Changeset 63783
- Timestamp:
- 09/21/2026 07:55:13 PM (4 weeks ago)
- File:
-
- 1 edited
-
trunk/Gruntfile.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Gruntfile.js
r63556 r63783 1084 1084 '**/vendor/**' 1085 1085 ], 1086 /* 1087 * Limit JSHint's run to a single specified plugin directory:1086 /** 1087 * Limits JSHint's run to a single specified plugin directory: 1088 1088 * 1089 * grunt jshint:plugins --dir=foldername 1089 * Usage example: 1090 * grunt jshint:plugins --dir=foldername 1091 * 1092 * This also automatically skips minified files that may not have 1093 * a filename ending with `.min.js`, specifically when they have 1094 * lines longer than 500 characters. 1095 * 1096 * @param {string} dirpath Directory path. 1097 * @return {boolean} Whether the path is skipped. 1090 1098 */ 1091 1099 filter: function( dirpath ) { 1092 var index, dir = grunt.option( 'dir' ); 1093 1094 // Don't filter when no target folder is specified. 1095 if ( ! dir ) { 1096 return true; 1097 } 1098 1099 dirpath = dirpath.replace( /\\/g, '/' ); 1100 index = dirpath.lastIndexOf( '/' + dir ); 1101 1102 // Match only the folder name passed from cli. 1103 if ( -1 !== index ) { 1104 return true; 1105 } 1106 1107 return false; 1100 // Bypasses folder targets so fs.readFileSync doesn't throw errors. 1101 if ( ! fs.lstatSync( dirpath ).isFile() ) { 1102 return false; 1103 } 1104 1105 // If `--dir` is provided. 1106 var dir = grunt.option( 'dir' ); 1107 if ( dir ) { 1108 var normalizedPath = dirpath.replace( /\\/g, '/' ); 1109 var index = normalizedPath.lastIndexOf( '/' + dir ); 1110 1111 // If a directory was requested but this file isn't in it, exclude it. 1112 if ( -1 === index ) { 1113 return false; 1114 } 1115 } 1116 1117 // Read the file and inspect line lengths to catch minified/bundled code. 1118 var content; 1119 try { 1120 content = fs.readFileSync( dirpath, 'utf-8' ); 1121 } catch ( error ) { 1122 grunt.log.writeln( 'Could not read file: ' + dirpath + ' (Error: ' + error.message + ')' ); 1123 return false; 1124 } 1125 1126 var lines = content.split( '\n' ); 1127 1128 // Cap the maximum number of iterations at 5 lines. 1129 for ( const line of lines.slice( 0, 5 ) ) { 1130 // Exclude files with lines longer than 500 characters. 1131 if ( line.length > 500 ) { 1132 grunt.log.writeln( 'Skipping minified file: ' + dirpath ); 1133 return false; 1134 } 1135 } 1136 1137 // File passed both independent checks: proceed with JSHint. 1138 return true; 1108 1139 } 1109 1140 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)