Add a .jshintrc file and associated jshint grunt task.
This .jshintrc is adopted from the jQuery project, with some basic modifications (such as single quotes instead of double quotes). This pretty closely follows our current JS standards and rather closely resembles our PHP standards, especially the love of whitespace. The major changes are enforcing === and always using braces for if statements. props kadamwhite, gnarf37, with mattwiebe and carldanley. see #25187. git-svn-id: https://develop.svn.wordpress.org/trunk@25960 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
add8bc4e57
commit
06635ed4cd
21
.jshintrc
Normal file
21
.jshintrc
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"boss": true,
|
||||
"curly": true,
|
||||
"eqeqeq": true,
|
||||
"eqnull": true,
|
||||
"expr": true,
|
||||
"immed": true,
|
||||
"noarg": true,
|
||||
"quotmark": "single",
|
||||
"smarttabs": true,
|
||||
"trailing": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
|
||||
"browser": true,
|
||||
|
||||
"globals": {
|
||||
"jQuery": false,
|
||||
"wp": false
|
||||
}
|
||||
}
|
75
Gruntfile.js
75
Gruntfile.js
@ -1,8 +1,8 @@
|
||||
/*global module:false*/
|
||||
/* jshint node:true */
|
||||
module.exports = function(grunt) {
|
||||
var path = require('path');
|
||||
var SOURCE_DIR = 'src/';
|
||||
var BUILD_DIR = 'build/';
|
||||
var path = require('path'),
|
||||
SOURCE_DIR = 'src/',
|
||||
BUILD_DIR = 'build/';
|
||||
|
||||
// Load tasks.
|
||||
require('matchdep').filterDev('grunt-*').forEach( grunt.loadNpmTasks );
|
||||
@ -47,8 +47,8 @@ module.exports = function(grunt) {
|
||||
},
|
||||
version: {
|
||||
options: {
|
||||
processContent: function( src, filepath ) {
|
||||
return src.replace( /^(\$wp_version.+?)-src';/m, "$1';" );
|
||||
processContent: function( src ) {
|
||||
return src.replace( /^(\$wp_version.+?)-src';/m, '$1\';' );
|
||||
}
|
||||
},
|
||||
files: [
|
||||
@ -80,6 +80,60 @@ module.exports = function(grunt) {
|
||||
]
|
||||
}
|
||||
},
|
||||
jshint: {
|
||||
options: grunt.file.readJSON('.jshintrc'),
|
||||
grunt: {
|
||||
files: {
|
||||
src: ['Gruntfile.js']
|
||||
},
|
||||
options: {
|
||||
onevar: true
|
||||
}
|
||||
},
|
||||
tests: {
|
||||
files: {
|
||||
src: [
|
||||
'tests/qunit/**/*.js',
|
||||
'!tests/qunit/vendor/qunit.js'
|
||||
]
|
||||
},
|
||||
options: grunt.file.readJSON('tests/qunit/.jshintrc')
|
||||
},
|
||||
'wp-admin': {
|
||||
files: {
|
||||
src: [
|
||||
'src/wp-admin/js/**/*.js',
|
||||
'!src/wp-admin/js/farbtastic.js',
|
||||
'!src/wp-admin/js/iris.min.js'
|
||||
]
|
||||
}
|
||||
},
|
||||
'wp-includes': {
|
||||
files: {
|
||||
src: [
|
||||
'src/wp-includes/js/**/*.js',
|
||||
// 3rd-Party Scripts
|
||||
'!src/wp-includes/js/backbone.min.js',
|
||||
'!src/wp-includes/js/colorpicker.js',
|
||||
'!src/wp-includes/js/crop/**/*.js',
|
||||
'!src/wp-includes/js/hoverIntent.js',
|
||||
'!src/wp-includes/js/imgareaselect/**/*.js',
|
||||
'!src/wp-includes/js/jcrop/**/*.js',
|
||||
'!src/wp-includes/js/jquery/**/*.js',
|
||||
'!src/wp-includes/js/json2.js',
|
||||
'!src/wp-includes/js/mediaelement/**/*.js',
|
||||
'!src/wp-includes/js/plupload/**/*.js',
|
||||
'!src/wp-includes/js/swfobject.js',
|
||||
'!src/wp-includes/js/swfupload/**/*.js',
|
||||
'!src/wp-includes/js/thickbox/**/*.js',
|
||||
'!src/wp-includes/js/tinymce/**/*.js',
|
||||
'!src/wp-includes/js/tw-sack.js',
|
||||
'!src/wp-includes/js/underscore.min.js',
|
||||
'!src/wp-includes/js/zxcvbn.min.js'
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
qunit: {
|
||||
files: ['tests/qunit/**/*.html']
|
||||
},
|
||||
@ -194,12 +248,13 @@ module.exports = function(grunt) {
|
||||
// On `watch:all`, automatically updates the `copy:dynamic` and `clean:dynamic`
|
||||
// configurations so that only the changed files are updated.
|
||||
grunt.event.on('watch', function( action, filepath, target ) {
|
||||
if ( target != 'all' )
|
||||
if ( target !== 'all' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var relativePath = path.relative( SOURCE_DIR, filepath );
|
||||
var cleanSrc = ( action == 'deleted' ) ? [relativePath] : [];
|
||||
var copySrc = ( action == 'deleted' ) ? [] : [relativePath];
|
||||
var relativePath = path.relative( SOURCE_DIR, filepath ),
|
||||
cleanSrc = ( action === 'deleted' ) ? [relativePath] : [],
|
||||
copySrc = ( action === 'deleted' ) ? [] : [relativePath];
|
||||
|
||||
grunt.config(['clean', 'dynamic', 'src'], cleanSrc);
|
||||
grunt.config(['copy', 'dynamic', 'src'], copySrc);
|
||||
|
@ -18,6 +18,7 @@
|
||||
"grunt-contrib-watch": "~0.5.1",
|
||||
"grunt-contrib-compress": "~0.5.2",
|
||||
"grunt-contrib-concat": "~0.3.0",
|
||||
"grunt-contrib-jshint": "~0.7.0",
|
||||
"matchdep": "~0.1.2"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user