Browse Source

Implemented grunt jshint:git, making it inside default.

fredck 11 years ago
parent
commit
de300ee96e

+ 20 - 4
packages/ckeditor5-ui/dev/tasks/jshint.js

@@ -1,13 +1,29 @@
 /* global module */
+/* global require */
 
 'use strict';
 
+var tools = require( './res/tools' );
+
 module.exports = function( grunt ) {
+	// Base task configuration, targetting "all" by default.
+	var config = {
+		all: [ '**/*.js' ],
+		options: defaultConfig
+	};
+
+	var isGitTask = ( grunt.cli.tasks.indexOf( 'jshint:git' ) > -1 ),
+		isDefaultTask = ( grunt.cli.tasks.indexOf( 'default' ) > -1 ) || !grunt.cli.tasks.length;
+
+	// Create the :git configuration on the fly, if necessary.
+	if ( isGitTask || isDefaultTask ) {
+		delete config.all;
+		config.git = tools.getGitDirtyFiles();
+	}
+
+	// Merge with configurations set in gruntfile.js.
 	grunt.config.merge( {
-		jshint: {
-			files: [ '**/*.js' ],
-			options: defaultConfig
-		}
+		jshint: config
 	} );
 
 	grunt.loadNpmTasks( 'grunt-contrib-jshint' );

+ 7 - 1
packages/ckeditor5-ui/dev/tasks/res/tools.js

@@ -3,9 +3,15 @@
 
 'use strict';
 
+var dirtyFiles;
+
 module.exports = {
 	getGitDirtyFiles: function() {
-		return this.shExec( 'git diff-index --name-only HEAD' ).split( '\n' );
+		// Cache it, so it is executed only once when running multiple tasks.
+		if ( !dirtyFiles ) {
+			dirtyFiles = this.shExec( 'git diff-index --name-only HEAD' ).replace( /\s*$/, '' ).split( '\n' );
+		}
+		return dirtyFiles;
 	},
 
 	shExec: function( command ) {

+ 2 - 4
packages/ckeditor5-ui/gruntfile.js

@@ -8,9 +8,7 @@ module.exports = function( grunt ) {
 
 		jshint: {
 			options: {
-				'ignores': lintIgnores,
-				'predef': [
-				]
+				'ignores': lintIgnores
 			}
 		},
 
@@ -23,7 +21,7 @@ module.exports = function( grunt ) {
 
 	grunt.loadTasks( 'dev/tasks' );
 
-	grunt.registerTask( 'default', [ 'jshint', 'jscs' ] );
+	grunt.registerTask( 'default', [ 'jshint:git', 'jscs' ] );
 };
 
 var lintIgnores = [