Make WordPress Core

Changeset 25960


Ignore:
Timestamp:
10/27/2013 09:53:11 PM (13 years ago)
Author:
nacin
Message:

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.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r25693 r25960  
    1 /*global module:false*/
     1/* jshint node:true */
    22module.exports = function(grunt) {
    3         var path = require('path');
    4         var SOURCE_DIR = 'src/';
    5         var BUILD_DIR = 'build/';
     3        var path = require('path'),
     4                SOURCE_DIR = 'src/',
     5                BUILD_DIR = 'build/';
    66
    77        // Load tasks.
     
    4848                        version: {
    4949                                options: {
    50                                         processContent: function( src, filepath ) {
    51                                                 return src.replace( /^(\$wp_version.+?)-src';/m, "$1';" );
     50                                        processContent: function( src ) {
     51                                                return src.replace( /^(\$wp_version.+?)-src';/m, '$1\';' );
    5252                                        }
    5353                                },
     
    7979                                        '!wp-admin/css/farbtastic.css'
    8080                                ]
     81                        }
     82                },
     83                jshint: {
     84                        options: grunt.file.readJSON('.jshintrc'),
     85                        grunt: {
     86                                files: {
     87                                        src: ['Gruntfile.js']
     88                                },
     89                                options: {
     90                                        onevar: true
     91                                }
     92                        },
     93                        tests: {
     94                                files: {
     95                                        src: [
     96                                                'tests/qunit/**/*.js',
     97                                                '!tests/qunit/vendor/qunit.js'
     98                                        ]
     99                                },
     100                                options: grunt.file.readJSON('tests/qunit/.jshintrc')
     101                        },
     102                        'wp-admin': {
     103                                files: {
     104                                        src: [
     105                                                'src/wp-admin/js/**/*.js',
     106                                                '!src/wp-admin/js/farbtastic.js',
     107                                                '!src/wp-admin/js/iris.min.js'
     108                                        ]
     109                                }
     110                        },
     111                        'wp-includes': {
     112                                files: {
     113                                        src: [
     114                                                'src/wp-includes/js/**/*.js',
     115                                                // 3rd-Party Scripts
     116                                                '!src/wp-includes/js/backbone.min.js',
     117                                                '!src/wp-includes/js/colorpicker.js',
     118                                                '!src/wp-includes/js/crop/**/*.js',
     119                                                '!src/wp-includes/js/hoverIntent.js',
     120                                                '!src/wp-includes/js/imgareaselect/**/*.js',
     121                                                '!src/wp-includes/js/jcrop/**/*.js',
     122                                                '!src/wp-includes/js/jquery/**/*.js',
     123                                                '!src/wp-includes/js/json2.js',
     124                                                '!src/wp-includes/js/mediaelement/**/*.js',
     125                                                '!src/wp-includes/js/plupload/**/*.js',
     126                                                '!src/wp-includes/js/swfobject.js',
     127                                                '!src/wp-includes/js/swfupload/**/*.js',
     128                                                '!src/wp-includes/js/thickbox/**/*.js',
     129                                                '!src/wp-includes/js/tinymce/**/*.js',
     130                                                '!src/wp-includes/js/tw-sack.js',
     131                                                '!src/wp-includes/js/underscore.min.js',
     132                                                '!src/wp-includes/js/zxcvbn.min.js'
     133                                        ]
     134                                }
    81135                        }
    82136                },
     
    195249        // configurations so that only the changed files are updated.
    196250        grunt.event.on('watch', function( action, filepath, target ) {
    197                 if ( target != 'all' )
     251                if ( target !== 'all' ) {
    198252                        return;
    199 
    200                 var relativePath = path.relative( SOURCE_DIR, filepath );
    201                 var cleanSrc = ( action == 'deleted' ) ? [relativePath] : [];
    202                 var copySrc = ( action == 'deleted' ) ? [] : [relativePath];
     253                }
     254
     255                var relativePath = path.relative( SOURCE_DIR, filepath ),
     256                        cleanSrc = ( action === 'deleted' ) ? [relativePath] : [],
     257                        copySrc = ( action === 'deleted' ) ? [] : [relativePath];
    203258
    204259                grunt.config(['clean', 'dynamic', 'src'], cleanSrc);
  • trunk/package.json

    r25243 r25960  
    1919    "grunt-contrib-compress": "~0.5.2",
    2020    "grunt-contrib-concat": "~0.3.0",
     21    "grunt-contrib-jshint": "~0.7.0",
    2122    "matchdep": "~0.1.2"
    2223  }
Note: See TracChangeset for help on using the changeset viewer.