From 518cac37def6ef0996bca6d01a10c265ea272d55 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 14 Nov 2013 18:16:59 +0000 Subject: [PATCH] Grunt jshint: ensure the file passed with --file=filename.js matches all or part of the filepath before checking string lengths. Makes it possible to pass a file with full or partial path. All of these would work properly: admin-bar.js, wp-includes/js/admin-bar.js, src/wp-includes/js/admin-bar.js. Props atimmer, fixes #25992. git-svn-id: https://develop.svn.wordpress.org/trunk@26168 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 39c47f89dc..7c73bf5408 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,7 +4,7 @@ module.exports = function(grunt) { SOURCE_DIR = 'src/', BUILD_DIR = 'build/'; - // Load tasks. + // Load tasks. require('matchdep').filterDev('grunt-*').forEach( grunt.loadNpmTasks ); // Project configuration. @@ -204,7 +204,7 @@ module.exports = function(grunt) { // Limit JSHint's run to a single specified file // grunt jshint:core --file=filename.js filter: function( filepath ) { - var file = grunt.option( 'file' ); + var index, file = grunt.option( 'file' ); // Don't filter when no target file is specified if ( ! file ) { @@ -213,9 +213,10 @@ module.exports = function(grunt) { // Normalize filepath for Windows filepath = filepath.replace( /\\/g, '/' ); + index = filepath.lastIndexOf( '/' + file ); // Match only the filename passed from cli - if ( filepath.lastIndexOf( '/' + file ) === filepath.length - ( file.length + 1 ) ) { + if ( filepath === file || ( -1 !== index && index === filepath.length - ( file.length + 1 ) ) ) { return true; }