From b7e822591938362e111a324240b29f4908f2cf26 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Thu, 17 Sep 2026 09:51:19 +0200 Subject: [PATCH 1/2] JSHint: Exclude minified plugin files more effectively. --- Gruntfile.js | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 08da38fb748e2..bd2e7552a609f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1086,25 +1086,53 @@ module.exports = function(grunt) { /* * Limit JSHint's run to a single specified plugin directory: * - * grunt jshint:plugins --dir=foldername + * Usage example: + * grunt jshint:plugins --dir=foldername + * + * Also, skips minified files that may not have a filename ending + * with `.min.js` automatically. Assuming they have lines longer + * than 500 characters. */ filter: function( dirpath ) { - var index, dir = grunt.option( 'dir' ); + // Bypasses folder targets so fs.readFileSync doesn't throw errors. + if ( ! fs.lstatSync( dirpath ).isFile() ) { + return false; + } - // Don't filter when no target folder is specified. - if ( ! dir ) { - return true; + // If `--dir` is provided. + var dir = grunt.option( 'dir' ); + if ( dir ) { + var normalizedPath = dirpath.replace( /\\/g, '/' ); + var index = normalizedPath.lastIndexOf( '/' + dir ); + + // If a directory was requested but this file isn't in it, exclude it. + if ( -1 === index ) { + return false; + } } - dirpath = dirpath.replace( /\\/g, '/' ); - index = dirpath.lastIndexOf( '/' + dir ); + // Read the file and inspect line lengths to catch minified/bundled code. + var content; + try { + content = fs.readFileSync( dirpath, 'utf-8' ); + } catch ( error ) { + grunt.log.writeln( 'Could not read file: ' + dirpath + ' (Error: ' + error.message + ')' ); + return false; + } - // Match only the folder name passed from cli. - if ( -1 !== index ) { - return true; + var lines = content.split( '\n' ); + + // Cap the maximum number of iterations at 5 lines. + for ( var i = 0; i < Math.min( lines.length, 5 ); i++ ) { + // Exclude files with lines longer than 500 characters. + if ( lines[i].length > 500 ) { + grunt.log.writeln( 'Skipping minified file: ' + dirpath ); + return false; + } } - return false; + // File passed both independent checks: proceed with JSHint. + return true; } } }, From 8d31cafab0a74e816fe424ff12aa4c817a76944b Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Mon, 21 Sep 2026 21:06:25 +0200 Subject: [PATCH 2/2] Address CR feedback. --- Gruntfile.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index bd2e7552a609f..f39a8afbd15b8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1083,15 +1083,18 @@ module.exports = function(grunt) { '**/test/**', '**/vendor/**' ], - /* - * Limit JSHint's run to a single specified plugin directory: + /** + * Limits JSHint's run to a single specified plugin directory: * * Usage example: * grunt jshint:plugins --dir=foldername * - * Also, skips minified files that may not have a filename ending - * with `.min.js` automatically. Assuming they have lines longer - * than 500 characters. + * This also automatically skips minified files that may not have + * a filename ending with `.min.js`, specifically when they have + * lines longer than 500 characters. + * + * @param {string} dirpath Directory path. + * @return {boolean} Whether the path is skipped. */ filter: function( dirpath ) { // Bypasses folder targets so fs.readFileSync doesn't throw errors. @@ -1123,9 +1126,9 @@ module.exports = function(grunt) { var lines = content.split( '\n' ); // Cap the maximum number of iterations at 5 lines. - for ( var i = 0; i < Math.min( lines.length, 5 ); i++ ) { + for ( const line of lines.slice( 0, 5 ) ) { // Exclude files with lines longer than 500 characters. - if ( lines[i].length > 500 ) { + if ( line.length > 500 ) { grunt.log.writeln( 'Skipping minified file: ' + dirpath ); return false; }