From 3d1714de710be2d277b6280ca34a01c43866d3e6 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 19 Jul 2019 07:47:16 +0000 Subject: [PATCH] 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 --- Gruntfile.js | 13 +++++++++---- composer.json | 5 +++-- phpcs.xml.dist | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 815999009f..4d4a88e6e7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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'); diff --git a/composer.json b/composer.json index 03f050fd4c..c795607093 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c4cdc5d97b..82f21d12c2 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -5,6 +5,23 @@ + + + warning + + + warning + + + warning + + + warning + + + warning + +