From 3032512477a20221ea6236e278c870ed7e55bd82 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 8 Nov 2013 00:40:38 +0000 Subject: [PATCH] Grunt: limit JSHint's run to a single specified file. Run with grunt jshint:core --file=filename.js. Props kadamwhite, see #25187. git-svn-id: https://develop.svn.wordpress.org/trunk@26043 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Gruntfile.js b/Gruntfile.js index 7a4ced7606..e20cf46738 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -123,6 +123,26 @@ module.exports = function(grunt) { options: { curly: false, eqeqeq: false + }, + // Limit JSHint's run to a single specified file + // grunt jshint:core --file=filename.js + filter: function( filepath ) { + var file = grunt.option( 'file' ); + + // Don't filter when no target file is specified + if ( ! file ) { + return true; + } + + // Normalize filepath for Windows + filepath = filepath.replace( /\\/g, '/' ); + + // Match only the filename passed from cli + if ( filepath.lastIndexOf( '/' + file ) === filepath.length - ( file.length + 1 ) ) { + return true; + } + + return false; } } },