WordPress.org

Make WordPress Core

Changeset 45665


Ignore:
Timestamp:
07/19/2019 07:47:16 AM (4 months ago)
Author:
pento
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r45607 r45665  
    14431443        var flags = this.flags;
    14441444        var args = changedFiles.php;
    1445         if ( flags.travis ) {
    1446             args = [ 'tests' ];
     1445        if ( flags.travisErrors ) {
     1446            // We can check the entire codebase for coding standards errors.
     1447            args = [ 'lint:errors' ];
     1448        } else if ( flags.travisWarnings ) {
     1449            // We can check the tests directory for errors and warnings.
     1450            args = [ 'lint', 'tests' ];
     1451        } else {
     1452            args.unshift( 'lint' );
    14471453        }
    1448         args.unshift( 'lint' );
    14491454        grunt.util.spawn( {
    14501455            cmd: 'composer',
     
    14631468    grunt.registerTask('travis:js', 'Runs Javascript Travis CI tasks.', [ 'jshint:corejs', 'qunit:compiled' ]);
    14641469    grunt.registerTask('travis:phpunit', 'Runs PHPUnit Travis CI tasks.', [ 'build', 'phpunit' ]);
    1465     grunt.registerTask('travis:phpcs', 'Runs PHP Coding Standards Travis CI tasks.', [ 'format:php:error', 'lint:php:travis:error' ]);
     1470    grunt.registerTask('travis:phpcs', 'Runs PHP Coding Standards Travis CI tasks.', [ 'format:php:error', 'lint:php:travisErrors:error', 'lint:php:travisWarnings:error' ]);
    14661471
    14671472    // Patch task.
  • trunk/composer.json

    r45600 r45665  
    1515    },
    1616    "scripts": {
    17         "format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
    18         "lint": "phpcs --standard=phpcs.xml.dist --report-summary --report-source"
     17        "format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source --cache -d memory_limit=256M",
     18        "lint": "phpcs --standard=phpcs.xml.dist --report-summary --report-source --cache -d memory_limit=256M",
     19        "lint:errors": "phpcs --standard=phpcs.xml.dist --report-summary --report-source --cache -d memory_limit=256M -n"
    1920    }
    2021}
  • trunk/phpcs.xml.dist

    r45664 r45665  
    55    <rule ref="WordPress-Core"/>
    66    <rule ref="WordPress.CodeAnalysis.EmptyStatement"/>
     7
     8    <!-- These rules are being set as warnings instead of errors, so we can error check the entire codebase. -->
     9    <rule ref="WordPress.PHP.YodaConditions.NotYoda">
     10        <type>warning</type>
     11    </rule>
     12    <rule ref="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase">
     13        <type>warning</type>
     14    </rule>
     15    <rule ref="WordPress.DB.PreparedSQL.InterpolatedNotPrepared">
     16        <type>warning</type>
     17    </rule>
     18    <rule ref="WordPress.DB.PreparedSQL.NotPrepared">
     19        <type>warning</type>
     20    </rule>
     21    <rule ref="WordPress.Files.FileName.InvalidClassFileName">
     22        <type>warning</type>
     23    </rule>
    724
    825    <rule ref="WordPress.NamingConventions.ValidVariableName">
Note: See TracChangeset for help on using the changeset viewer.