Make WordPress Core

Ticket #43731: jshint.patch

File jshint.patch, 7.9 KB (added by youknowriad, 7 years ago)

JSHint to NPM script

  • new file .jshintignore

    diff --git a/.jshintignore b/.jshintignore
    new file mode 100644
    index 0000000000..de37fcc6ab
    - +  
     1tests/qunit/vendor/*
     2tests/qunit/editor/**
     3
     4src/wp-content/themes/twenty{eleven,twelve,thirteen}/**
     5src/wp-content/themes/twenty{fourteen,fifteen,sixteen}/js/html5.js
     6src/wp-content/themes/twentyseventeen/assets/js/html5.js
     7src/wp-content/themes/twentyseventeen/assets/js/jquery.scrollTo.js
     8
     9src/wp-includes/js/media-*
     10
     11src/wp-includes/js/codemirror/*.js
     12src/wp-admin/js/farbtastic.js
     13src/wp-includes/js/backbone*.js
     14src/wp-includes/js/swfobject.js
     15src/wp-includes/js/underscore*.js
     16src/wp-includes/js/colorpicker.js
     17src/wp-includes/js/hoverIntent.js
     18src/wp-includes/js/json2.js
     19src/wp-includes/js/tw-sack.js
     20src/wp-includes/js/twemoji.js
     21src/**/*.min.js
     22
     23src/wp-content/plugins/**/*.min.js
  • .jshintrc

    diff --git a/.jshintrc b/.jshintrc
    index 1b7387f4a2..decf2015c7 100644
    a b  
    11{
    22        "boss": true,
    3         "curly": true,
    4         "eqeqeq": true,
     3        "curly": false,
     4        "eqeqeq": false,
    55        "eqnull": true,
    66        "es3": true,
    77        "expr": true,
  • Gruntfile.js

    diff --git a/Gruntfile.js b/Gruntfile.js
    index a551b308be..c03480414e 100644
    a b module.exports = function(grunt) { 
    316316                                src: []
    317317                        }
    318318                },
    319                 jshint: {
    320                         options: grunt.file.readJSON('.jshintrc'),
    321                         grunt: {
    322                                 src: ['Gruntfile.js']
    323                         },
    324                         tests: {
    325                                 src: [
    326                                         'tests/qunit/**/*.js',
    327                                         '!tests/qunit/vendor/*',
    328                                         '!tests/qunit/editor/**'
    329                                 ],
    330                                 options: grunt.file.readJSON('tests/qunit/.jshintrc')
    331                         },
    332                         themes: {
    333                                 expand: true,
    334                                 cwd: SOURCE_DIR + 'wp-content/themes',
    335                                 src: [
    336                                         'twenty*/**/*.js',
    337                                         '!twenty{eleven,twelve,thirteen}/**',
    338                                         // Third party scripts
    339                                         '!twenty{fourteen,fifteen,sixteen}/js/html5.js',
    340                                         '!twentyseventeen/assets/js/html5.js',
    341                                         '!twentyseventeen/assets/js/jquery.scrollTo.js'
    342                                 ]
    343                         },
    344                         media: {
    345                                 src: [
    346                                         SOURCE_DIR + 'wp-includes/js/media/**/*.js'
    347                                 ]
    348                         },
    349                         core: {
    350                                 expand: true,
    351                                 cwd: SOURCE_DIR,
    352                                 src: [
    353                                         'wp-admin/js/**/*.js',
    354                                         'wp-includes/js/*.js',
    355                                         // Built scripts.
    356                                         '!wp-includes/js/media-*',
    357                                         // WordPress scripts inside directories
    358                                         'wp-includes/js/jquery/jquery.table-hotkeys.js',
    359                                         'wp-includes/js/mediaelement/mediaelement-migrate.js',
    360                                         'wp-includes/js/mediaelement/wp-mediaelement.js',
    361                                         'wp-includes/js/mediaelement/wp-playlist.js',
    362                                         'wp-includes/js/plupload/handlers.js',
    363                                         'wp-includes/js/plupload/wp-plupload.js',
    364                                         'wp-includes/js/tinymce/plugins/wordpress/plugin.js',
    365                                         'wp-includes/js/tinymce/plugins/wp*/plugin.js',
    366                                         // Third party scripts
    367                                         '!wp-includes/js/codemirror/*.js',
    368                                         '!wp-admin/js/farbtastic.js',
    369                                         '!wp-includes/js/backbone*.js',
    370                                         '!wp-includes/js/swfobject.js',
    371                                         '!wp-includes/js/underscore*.js',
    372                                         '!wp-includes/js/colorpicker.js',
    373                                         '!wp-includes/js/hoverIntent.js',
    374                                         '!wp-includes/js/json2.js',
    375                                         '!wp-includes/js/tw-sack.js',
    376                                         '!wp-includes/js/twemoji.js',
    377                                         '!**/*.min.js'
    378                                 ],
    379                                 // Remove once other JSHint errors are resolved
    380                                 options: {
    381                                         curly: false,
    382                                         eqeqeq: false
    383                                 },
    384                                 // Limit JSHint's run to a single specified file:
    385                                 //
    386                                 //    grunt jshint:core --file=filename.js
    387                                 //
    388                                 // Optionally, include the file path:
    389                                 //
    390                                 //    grunt jshint:core --file=path/to/filename.js
    391                                 //
    392                                 filter: function( filepath ) {
    393                                         var index, file = grunt.option( 'file' );
    394 
    395                                         // Don't filter when no target file is specified
    396                                         if ( ! file ) {
    397                                                 return true;
    398                                         }
    399 
    400                                         // Normalize filepath for Windows
    401                                         filepath = filepath.replace( /\\/g, '/' );
    402                                         index = filepath.lastIndexOf( '/' + file );
    403 
    404                                         // Match only the filename passed from cli
    405                                         if ( filepath === file || ( -1 !== index && index === filepath.length - ( file.length + 1 ) ) ) {
    406                                                 return true;
    407                                         }
    408 
    409                                         return false;
    410                                 }
    411                         },
    412                         plugins: {
    413                                 expand: true,
    414                                 cwd: SOURCE_DIR + 'wp-content/plugins',
    415                                 src: [
    416                                         '**/*.js',
    417                                         '!**/*.min.js'
    418                                 ],
    419                                 // Limit JSHint's run to a single specified plugin directory:
    420                                 //
    421                                 //    grunt jshint:plugins --dir=foldername
    422                                 //
    423                                 filter: function( dirpath ) {
    424                                         var index, dir = grunt.option( 'dir' );
    425 
    426                                         // Don't filter when no target folder is specified
    427                                         if ( ! dir ) {
    428                                                 return true;
    429                                         }
    430 
    431                                         dirpath = dirpath.replace( /\\/g, '/' );
    432                                         index = dirpath.lastIndexOf( '/' + dir );
    433 
    434                                         // Match only the folder name passed from cli
    435                                         if ( -1 !== index ) {
    436                                                 return true;
    437                                         }
    438 
    439                                         return false;
    440                                 }
    441                         }
    442                 },
    443319                jsdoc : {
    444320                        dist : {
    445321                                dest: 'jsdoc',
    module.exports = function(grunt) { 
    761637                                files: [ '**/*.php' ],
    762638                                tasks: [ 'phpunit:default' ]
    763639                        }
     640                },
     641                exec: {
     642                        jshint: 'npm run jshint'
    764643                }
    765644        });
    766645
    module.exports = function(grunt) { 
    775654
    776655        // Register tasks.
    777656
     657        // Exec task.
     658        grunt.loadNpmTasks('grunt-exec');
     659
    778660        // Webpack task.
    779661        grunt.loadNpmTasks( 'grunt-webpack' );
    780662
    module.exports = function(grunt) { 
    785667        grunt.registerTask('colors', ['sass:colors', 'postcss:colors']);
    786668
    787669        // JSHint task.
    788         grunt.registerTask( 'jshint:corejs', [
    789                 'jshint:grunt',
    790                 'jshint:tests',
    791                 'jshint:themes',
    792                 'jshint:core',
    793                 'jshint:media'
    794         ] );
     670        grunt.registerTask( 'jshint:corejs', ['exec:jshint'] );
    795671
    796672        grunt.registerTask( 'restapi-jsclient', [
    797673                'phpunit:restapi-jsclient',
  • package.json

    diff --git a/package.json b/package.json
    index 3a289ee1c7..a1afa3c8b2 100644
    a b  
    99        "engines": {
    1010                "node": "8.9.3"
    1111        },
     12        "scripts": {
     13                "jshint": "jshint Gruntfile.js tests/qunit src/wp-content/themes/twenty* src/wp-includes/js/media src/wp-includes/js/*.js src/wp-admin/js/**/*.js"
     14        },
    1215        "author": "The WordPress Contributors",
    1316        "license": "GPL-2.0-or-later",
    1417        "devDependencies": {
     
    2124                "grunt-contrib-copy": "~1.0.0",
    2225                "grunt-contrib-cssmin": "~1.0.2",
    2326                "grunt-contrib-imagemin": "~1.0.0",
    24                 "grunt-contrib-jshint": "~1.0.0",
    2527                "grunt-contrib-qunit": "^1.2.0",
    2628                "grunt-contrib-uglify": "~2.0.0",
    2729                "grunt-contrib-watch": "~1.0.0",
     30                "grunt-exec": "^3.0.0",
    2831                "grunt-includes": "~0.5.1",
    2932                "grunt-jsdoc": "^2.1.0",
    3033                "grunt-jsvalidate": "~0.2.2",
     
    3437                "grunt-replace": "~1.0.1",
    3538                "grunt-rtlcss": "~2.0.1",
    3639                "grunt-sass": "2.0.0",
    37                 "ink-docstrap": "^1.3.0",
    3840                "grunt-webpack": "^3.0.2",
     41                "ink-docstrap": "^1.3.0",
     42                "jshint": "^2.9.5",
    3943                "matchdep": "~1.0.0",
    4044                "webpack": "^3.6.0",
    4145                "webpack-dev-server": "^2.9.1"
  • tests/qunit/wp-admin/js/nav-menu.js

    diff --git a/tests/qunit/wp-admin/js/nav-menu.js b/tests/qunit/wp-admin/js/nav-menu.js
    index de99e3d6f7..a7e1f37b3e 100644
    a b  
    99        setTimeout( function() {
    1010                // QUnit may load this file without running it, in which case `assert`
    1111                // will never be set to `assertPassed` below.
    12                 assert && assert.equal(
    13                         eventsFired,
    14                         eventsExpected,
    15                         eventsExpected + ' wpNavMenu events should fire.'
    16                 );
     12                if ( assert ) {
     13                         assert.equal(
     14                                eventsFired,
     15                                eventsExpected,
     16                                eventsExpected + ' wpNavMenu events should fire.'
     17                        );
     18                }
    1719        }, 3000 );
    1820
    1921        QUnit.test( 'Testing wpNavMenu event triggers.', function( assertPassed ) {
  • tests/qunit/wp-includes/js/tinymce/tinymce-obsolete.js

    diff --git a/tests/qunit/wp-includes/js/tinymce/tinymce-obsolete.js b/tests/qunit/wp-includes/js/tinymce/tinymce-obsolete.js
    index 9db1f9ac9d..d26ff2dddb 100644
    a b  
    5858                }
    5959
    6060                for ( tagName in attr ) {
    61                         if ( tags = html.match( new RegExp( '<' + tagName + ' [^>]+>', 'g' ) ) ) {
     61                        tags = html.match( new RegExp( '<' + tagName + ' [^>]+>', 'g' ) );
     62                        if ( tags ) {
    6263                                for ( tag in tags ) {
    6364                                        array = attr[tagName].split(' ');
    6465