Add composer.json and package.json for linting with Travis

This commit is contained in:
Ismail El Korchi 2020-03-30 18:40:16 +01:00
parent 1df1677846
commit cfdbdfc534
9 changed files with 152 additions and 124 deletions

8
.eslintrc Normal file
View File

@ -0,0 +1,8 @@
{
"extends": [
"plugin:@wordpress/eslint-plugin/es5"
],
"env": {
"browser": true
}
}

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/node_modules
/vendor
package-lock.json
composer.lock

View File

@ -1,7 +0,0 @@
{
"preset": "wordpress",
"fileExtensions": [ ".js" ],
"excludeFiles": [
"js/**.min.js"
]
}

View File

@ -1 +0,0 @@
js/**.min.js

12
.stylelintrc.json Normal file
View File

@ -0,0 +1,12 @@
{
"extends": [
"stylelint-config-wordpress/scss"
],
"ignoreFiles": [
"sass/_normalize.scss"
],
"rules": {
"font-family-no-missing-generic-family-keyword": null,
"no-descending-specificity": null
}
}

View File

@ -4,92 +4,67 @@
# For use with the Underscores WordPress theme. # For use with the Underscores WordPress theme.
# @link https://github.com/Automattic/_s # @link https://github.com/Automattic/_s
# Ditch sudo and use containers. # Tell Travis CI which distro to use.
# @link https://docs.travis-ci.com/user/migrating-from-legacy/#Why-migrate-to-container-based-infrastructure%3F
# @link https://docs.travis-ci.com/user/workers/container-based-infrastructure/#Routing-your-build-to-container-based-infrastructure
sudo: false
dist: trusty dist: trusty
# Cache directories between builds.
# @link https://docs.travis-ci.com/user/caching/#arbitrary-directories
cache:
directories:
# Cache directory for npm.
- $HOME/.npm
# Cache directory for older Composer versions.
- $HOME/.composer/cache/files
# Cache directory for more recent Composer versions.
- $HOME/.cache/composer/files
# Declare project language. # Declare project language.
# @link https://about.travis-ci.org/docs/user/languages/php/ # @link https://docs.travis-ci.com/user/languages/php/
language: php language:
- php
php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
# Declare versions of PHP to use. Use one decimal max.
# @link https://docs.travis-ci.com/user/build-configuration/
matrix: matrix:
fast_finish: true fast_finish: true
include:
- php: 7.4
env: SNIFF=1
include: before_install:
# Current $required_php_version for WordPress: 5.2.4 # Speed up build time by disabling Xdebug.
# aliased to 5.2.17 - phpenv config-rm xdebug.ini || echo 'No xdebug config.'
- php: '5.2' # Download and install the latest long-term support release of node.
dist: precise - nvm install --lts
# aliased to a recent 5.6.x version # Install Composer dependencies.
- php: '5.6' - composer install
env: SNIFF=1 # Install NPM dependencies.
# aliased to a recent 7.0.x version - npm install
- php: '7.0'
# aliased to a recent 7.2.x version
- php: '7.2'
# bleeding edge PHP
- php: 'nightly'
allow_failures:
- php: 'nightly'
# Use this to prepare the system to install prerequisites or dependencies.
# e.g. sudo apt-get update.
# Failures in this section will result in build status 'errored'.
# before_install:
# Use this to prepare your build for testing.
# e.g. copy database configurations, environment variables, etc.
# Failures in this section will result in build status 'errored'.
before_script:
# Speed up build time by disabling Xdebug.
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'
# Set up temporary paths.
- export PHPCS_DIR=/tmp/phpcs
- export WPCS_DIR=/tmp/wpcs
- export PHPCOMPAT_DIR=/tmp/phpcompatibility
# Install CodeSniffer for WordPress Coding Standards checks.
- if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi
# Install WordPress Coding Standards.
- if [[ "$SNIFF" == "1" ]]; then git clone -b 0.14.1 --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $WPCS_DIR; fi
# Install PHP Compatibility sniffs.
- if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/wimg/PHPCompatibility.git $PHPCOMPAT_DIR; fi
# Set install path for PHPCS sniffs.
# @link https://github.com/squizlabs/PHP_CodeSniffer/blob/4237c2fc98cc838730b76ee9cee316f99286a2a7/CodeSniffer.php#L1941
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs --config-set installed_paths $WPCS_DIR,$PHPCOMPAT_DIR; fi
# After CodeSniffer install you should refresh your path.
- if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi
# Install JSCS: JavaScript Code Style checker.
# @link http://jscs.info/
- if [[ "$SNIFF" == "1" ]]; then npm install -g jscs; fi
# Install JSHint, a JavaScript Code Quality Tool.
# @link http://jshint.com/docs/
- if [[ "$SNIFF" == "1" ]]; then npm install -g jshint; fi
# Pull in the WP Core jshint rules.
- if [[ "$SNIFF" == "1" ]]; then wget https://develop.svn.wordpress.org/trunk/.jshintrc; fi
# Run test script commands.
# Default is specific to project language.
# All commands must exit with code 0 on success. Anything else is considered failure.
script: script:
# Search for PHP syntax errors. # Validate the composer.json file.
- find -L . -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l # @link https://getcomposer.org/doc/03-cli.md#validate
# Run the theme through JSHint. - composer validate --no-check-all --strict
- if [[ "$SNIFF" == "1" ]]; then jshint .; fi
# Run the theme through JavaScript Code Style checker. # Search for PHP syntax errors using PHP Parallel Lint.
- if [[ "$SNIFF" == "1" ]]; then jscs .; fi # https://github.com/php-parallel-lint/PHP-Parallel-Lint
# WordPress Coding Standards. - composer lint:php
# @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
# @link https://pear.php.net/package/PHP_CodeSniffer/ # Check the PHP files with the coding standards documented in the phpcs.xml.dist file.
# Uses a custom ruleset based on WordPress. This ruleset is automatically - if [[ "$SNIFF" == 1 ]]; then composer lint:wpcs; fi
# picked up by PHPCS as it's named `phpcs.xml(.dist)`.
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi # Check the JS files with the lint-js script defined in the @wordpress/scripts package.
- if [[ "$SNIFF" == 1 ]]; then npm run lint:js; fi
# Check the SCSS files with the lint-style script defined in the @wordpress/scripts package.
- if [[ "$SNIFF" == 1 ]]; then npm run lint:scss; fi
# Receive notifications for build results. # Receive notifications for build results.
# @link https://docs.travis-ci.com/user/notifications/#Email-notifications # @link https://docs.travis-ci.com/user/notifications/#configuring-email-notifications
notifications: notifications:
email: false email: false

33
composer.json Normal file
View File

@ -0,0 +1,33 @@
{
"name": "automattic/underscores",
"type": "wordpress-theme",
"description": "Hi. I'm a starter theme called _s, or underscores, if you like. I'm a theme meant for hacking so don't use me as a Parent Theme. Instead try turning me into the next, most awesome, WordPress theme out there. That's what I'm here for.",
"keywords": [
"WordPress",
"Themes"
],
"homepage": "https://github.com/Automattic/_s",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Contributors",
"homepage": "https://github.com/Automattic/_s/graphs/contributors"
}
],
"require": {
"php": ">=5.6"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2",
"wptrt/wpthemereview": "^0.2.1",
"php-parallel-lint/php-parallel-lint": "^1.1.0"
},
"scripts": {
"lint:wpcs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --runtime-set testVersion 5.6-",
"lint:php": "@php ./vendor/bin/parallel-lint --exclude .git --exclude vendor ."
},
"support": {
"issues": "https://github.com/Automattic/_s/issues",
"source": "https://github.com/Automattic/_s"
}
}

26
package.json Normal file
View File

@ -0,0 +1,26 @@
{
"name": "underscores",
"version": "1.0.0",
"description": "Hi. I'm a starter theme called _s, or underscores, if you like. I'm a theme meant for hacking so don't use me as a Parent Theme. Instead try turning me into the next, most awesome, WordPress theme out there. That's what I'm here for.",
"author": "Automattic Theme Team",
"license": "GPL-2.0-or-later",
"keywords": [
"WordPress",
"Theme"
],
"homepage": "https://github.com/Automattic/_s#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/Automattic/_s.git"
},
"bugs": {
"url": "https://github.com/Automattic/_s/issues"
},
"devDependencies": {
"@wordpress/scripts": "^7.1.3"
},
"scripts": {
"lint:scss": "wp-scripts lint-style 'sass/**/*.scss'",
"lint:js": "wp-scripts lint-js 'js/*.js'"
}
}

View File

@ -1,9 +1,9 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<ruleset name="WordPress Theme Coding Standards"> <ruleset name="WordPress Theme Coding Standards">
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml --> <!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards --> <!-- See https://github.com/WordPress/WordPress-Coding-Standards -->
<!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki --> <!-- See https://github.com/WPTRT/WPThemeReview -->
<!-- See https://github.com/wimg/PHPCompatibility --> <!-- See https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<!-- Set a description for this ruleset. --> <!-- Set a description for this ruleset. -->
<description>A custom set of code standard rules to check for WordPress themes.</description> <description>A custom set of code standard rules to check for WordPress themes.</description>
@ -28,21 +28,28 @@
<!-- Check up to 8 files simultanously. --> <!-- Check up to 8 files simultanously. -->
<arg name="parallel" value="8"/> <arg name="parallel" value="8"/>
<!-- Only check the PHP, CSS and SCSS files. JS files are checked separately with JSCS and JSHint. --> <!-- Only check the PHP files. JS, and CSS files are checked separately with @wordpress/scripts package. -->
<arg name="extensions" value="php,css,scss/css"/> <arg name="extensions" value="php"/>
<!-- Check all files in this directory and the directories below it. --> <!-- Check all files in this directory and the directories below it. -->
<file>.</file> <file>.</file>
<!-- Exclude patterns. -->
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/node_modules/*</exclude-pattern>
<!-- <!--
############################################################################# #############################################################################
USE THE WordPress RULESET USE THE WordPress AND THE Theme Review RULESET
############################################################################# #############################################################################
--> -->
<rule ref="WordPress"/> <rule ref="WordPress">
<!-- This rule does not apply here since the _s prefix should be changed by the theme author. -->
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.ShortPrefixPassed"/>
</rule>
<rule ref="WPThemeReview"/>
<!-- <!--
############################################################################# #############################################################################
@ -97,36 +104,7 @@
############################################################################# #############################################################################
--> -->
<config name="testVersion" value="5.6-"/>
<config name="testVersion" value="5.2-99.0"/> <rule ref="PHPCompatibilityWP"/>
<rule ref="PHPCompatibility">
<!-- Whitelist PHP native classes, interfaces, functions and constants which
are back-filled by WP.
Based on:
* /wp-includes/compat.php
* /wp-includes/random_compat/random.php
-->
<exclude name="PHPCompatibility.PHP.NewClasses.errorFound"/>
<exclude name="PHPCompatibility.PHP.NewClasses.typeerrorFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.json_pretty_printFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.php_version_idFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.hash_equalsFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.json_last_error_msgFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.random_intFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.random_bytesFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound"/>
<exclude name="PHPCompatibility.PHP.NewInterfaces.jsonserializableFound"/>
</rule>
<!-- Whitelist the WP Core mysql_to_rfc3339() function. -->
<rule ref="PHPCompatibility.PHP.RemovedExtensions">
<properties>
<property name="functionWhitelist" type="array" value="mysql_to_rfc3339"/>
</properties>
</rule>
</ruleset> </ruleset>