Coding Standards: Move the remaining PHPCS errors to report as warnings, and add Travis tests.

The remaining error-level coding standards issues (specifically, associated with the sniffs `WordPress.PHP.YodaConditions.NotYoda`, `WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase`, `WordPress.DB.PreparedSQL.InterpolatedNotPrepared`, `WordPress.DB.PreparedSQL.NotPrepared`, and `WordPress.Files.FileName.InvalidClassFileName`) are marked as warnings, until they're all addressed.

This change allows us to run linting on Travis across the entire codebase, ensuring no other error-level violations can be introduced.

Additionally, PHPCS will now cache results locally, drastically improving performance for subsequent checks: scanning the entire codebase takes 1-2 minutes the first time, and less than one second for subsequent checks.

See #47632.



git-svn-id: https://develop.svn.wordpress.org/trunk@45665 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-07-19 07:47:16 +00:00
parent ab26c9a2fb
commit 3d1714de71
3 changed files with 29 additions and 6 deletions

View File

@ -1442,10 +1442,15 @@ module.exports = function(grunt) {
var done = this.async();
var flags = this.flags;
var args = changedFiles.php;
if ( flags.travis ) {
args = [ 'tests' ];
if ( flags.travisErrors ) {
// We can check the entire codebase for coding standards errors.
args = [ 'lint:errors' ];
} else if ( flags.travisWarnings ) {
// We can check the tests directory for errors and warnings.
args = [ 'lint', 'tests' ];
} else {
args.unshift( 'lint' );
}
args.unshift( 'lint' );
grunt.util.spawn( {
cmd: 'composer',
args: args,
@ -1462,7 +1467,7 @@ module.exports = function(grunt) {
// Travis CI tasks.
grunt.registerTask('travis:js', 'Runs Javascript Travis CI tasks.', [ 'jshint:corejs', 'qunit:compiled' ]);
grunt.registerTask('travis:phpunit', 'Runs PHPUnit Travis CI tasks.', [ 'build', 'phpunit' ]);
grunt.registerTask('travis:phpcs', 'Runs PHP Coding Standards Travis CI tasks.', [ 'format:php:error', 'lint:php:travis:error' ]);
grunt.registerTask('travis:phpcs', 'Runs PHP Coding Standards Travis CI tasks.', [ 'format:php:error', 'lint:php:travisErrors:error', 'lint:php:travisWarnings:error' ]);
// Patch task.
grunt.renameTask('patch_wordpress', 'patch');

View File

@ -14,7 +14,8 @@
"wp-coding-standards/wpcs": "~2.1.0"
},
"scripts": {
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "phpcs --standard=phpcs.xml.dist --report-summary --report-source"
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source --cache -d memory_limit=256M",
"lint": "phpcs --standard=phpcs.xml.dist --report-summary --report-source --cache -d memory_limit=256M",
"lint:errors": "phpcs --standard=phpcs.xml.dist --report-summary --report-source --cache -d memory_limit=256M -n"
}
}

View File

@ -5,6 +5,23 @@
<rule ref="WordPress-Core"/>
<rule ref="WordPress.CodeAnalysis.EmptyStatement"/>
<!-- These rules are being set as warnings instead of errors, so we can error check the entire codebase. -->
<rule ref="WordPress.PHP.YodaConditions.NotYoda">
<type>warning</type>
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase">
<type>warning</type>
</rule>
<rule ref="WordPress.DB.PreparedSQL.InterpolatedNotPrepared">
<type>warning</type>
</rule>
<rule ref="WordPress.DB.PreparedSQL.NotPrepared">
<type>warning</type>
</rule>
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<type>warning</type>
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="customPropertiesWhitelist" type="array">