Skip to content

Commit 1cb2093

Browse files
committed
Build: Switch from JSHint/JSCS to ESLint
Fixes #236 Closes #238
1 parent 9cb1ddc commit 1cb2093

22 files changed

+136
-138
lines changed

.eslintignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
coverage
2+
external
3+
node_modules
4+
*.min.js
5+
src/intro.js
6+
src/outro.js
7+
test/data/jquery-*.js
8+
test/data/jquery.mobile-*.js

.eslintrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "jquery",
3+
"root": true,
4+
"env": {
5+
"browser": false,
6+
"node": true
7+
}
8+
}

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
dist
21
coverage
32
CDN
43
.project
@@ -8,4 +7,9 @@ CDN
87
*.patch
98
/*.html
109
.DS_Store
11-
node_modules
10+
11+
# Ignore everything in dist folder except for eslint config
12+
/dist/*
13+
!/dist/.eslintrc.json
14+
15+
node_modules

.jscsrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.jshintrc

Lines changed: 0 additions & 17 deletions
This file was deleted.

Gruntfile.js

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@ module.exports = function( grunt ) {
33

44
"use strict";
55

6-
// The concatenated file won't pass onevar but our modules can
7-
var readOptionalJSON = function( filepath ) {
8-
var data = {};
9-
try {
10-
data = grunt.file.readJSON( filepath );
11-
} catch ( e ) {}
12-
return data;
13-
},
14-
srcHintOptions = readOptionalJSON( "src/.jshintrc" );
15-
delete srcHintOptions.onevar;
16-
176
// Project configuration.
187
grunt.initConfig( {
198
pkg: grunt.file.readJSON( "package.json" ),
@@ -77,13 +66,24 @@ module.exports = function( grunt ) {
7766
force: true
7867
}
7968
},
80-
jscs: {
81-
src: [
82-
"test/*.js",
83-
"<%= files %>",
84-
"Gruntfile.js",
85-
"build/**/*.js"
86-
]
69+
eslint: {
70+
options: {
71+
72+
// See https://github.com/sindresorhus/grunt-eslint/issues/119
73+
quiet: true
74+
},
75+
76+
dist: {
77+
src: "dist/jquery-migrate.js"
78+
},
79+
dev: {
80+
src: [
81+
"Gruntfile.js",
82+
"build/**/*.js",
83+
"src/**/*.js",
84+
"test/**/*.js"
85+
]
86+
}
8787
},
8888
npmcopy: {
8989
all: {
@@ -97,24 +97,6 @@ module.exports = function( grunt ) {
9797
"qunit/LICENSE.txt": "qunitjs/LICENSE.txt" }
9898
}
9999
},
100-
jshint: {
101-
dist: {
102-
src: [ "dist/jquery-migrate.js" ],
103-
options: srcHintOptions
104-
},
105-
tests: {
106-
src: [ "test/*.js" ],
107-
options: {
108-
jshintrc: "test/.jshintrc"
109-
}
110-
},
111-
grunt: {
112-
src: [ "Gruntfile.js" ],
113-
options: {
114-
jshintrc: ".jshintrc"
115-
}
116-
}
117-
},
118100
uglify: {
119101
all: {
120102
files: {
@@ -144,7 +126,15 @@ module.exports = function( grunt ) {
144126
// Just an alias
145127
grunt.registerTask( "test", [ "qunit" ] );
146128

147-
grunt.registerTask( "lint", [ "jshint", "jscs" ] );
129+
grunt.registerTask( "lint", [
130+
131+
// Running the full eslint task without breaking it down to targets
132+
// would run the dist target first which would point to errors in the built
133+
// file, making it harder to fix them. We want to check the built file only
134+
// if we already know the source files pass the linter.
135+
"eslint:dev",
136+
"eslint:dist"
137+
] );
148138
grunt.registerTask( "build", [ "concat", "uglify", "lint" ] );
149139

150140
grunt.registerTask( "default", [ "build", "test" ] );

build/release.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var releaseVersion,
2424
// Windows needs the .cmd version but will find the non-.cmd
2525
// On Windows, also ensure the HOME environment variable is set
2626
gruntCmd = process.platform === "win32" ? "grunt.cmd" : "grunt",
27-
npmCmd = process.platform == "win32" ? "npm.cmd" : "npm",
27+
npmCmd = process.platform === "win32" ? "npm.cmd" : "npm",
2828

2929
readmeFile = "README.md",
3030
packageFile = "package.json",
@@ -120,7 +120,7 @@ function initialize( next ) {
120120
// (look for " BRANCH pushes to BRANCH (up to date)")
121121

122122
function checkGitStatus( next ) {
123-
child.execFile( "git", [ "status" ], function( error, stdout, stderr ) {
123+
child.execFile( "git", [ "status" ], function( error, stdout ) {
124124
var onBranch = ( ( stdout || "" ).match( /On branch (\S+)/ ) || [] )[ 1 ];
125125
if ( onBranch !== branch ) {
126126
die( "Branches don't match: Wanted " + branch + ", got " + onBranch );
@@ -151,7 +151,7 @@ function updateVersions( next ) {
151151
}
152152

153153
function gruntBuild( next ) {
154-
exec( gruntCmd, [], function( error, stdout ) {
154+
exec( gruntCmd, [], function( error, stdout, stderr ) {
155155
if ( error ) {
156156
die( error + stderr );
157157
}
@@ -234,7 +234,7 @@ function updateSourceVersion( ver ) {
234234
}
235235
}
236236

237-
function updateReadmeVersion( ver ) {
237+
function updateReadmeVersion() {
238238
var readme = fs.readFileSync( readmeFile, "utf8" );
239239

240240
// Change version references from the old version to the new one.
@@ -243,8 +243,10 @@ function updateReadmeVersion( ver ) {
243243
status( "Skipping " + readmeFile + " update (beta release)" );
244244
} else {
245245
status( "Updating " + readmeFile );
246-
readme = readme
247-
.replace( /jquery-migrate-\d+\.\d+\.\d+(?:-\w+)?/g, "jquery-migrate-" + releaseVersion );
246+
readme = readme.replace(
247+
/jquery-migrate-\d+\.\d+\.\d+(?:-\w+)?/g,
248+
"jquery-migrate-" + releaseVersion
249+
);
248250
if ( !dryrun ) {
249251
fs.writeFileSync( readmeFile, readme );
250252
}

dist/.eslintrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../src/.eslintrc.json",
3+
"root": true,
4+
"rules": {
5+
// That is okay for the built version
6+
"no-multiple-empty-lines": "off"
7+
}
8+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
"devDependencies": {
2929
"chalk": "1.1.3",
3030
"commitplease": "2.7.5",
31+
"eslint-config-jquery": "1.0.0",
3132
"grunt": "0.4.5",
3233
"grunt-cli": "0.1.13",
3334
"grunt-contrib-concat": "1.0.1",
34-
"grunt-contrib-jshint": "1.0.0",
3535
"grunt-contrib-uglify": "2.0.0",
3636
"grunt-contrib-watch": "1.0.0",
3737
"grunt-coveralls": "1.0.1",
38+
"grunt-eslint": "19.0.0",
3839
"grunt-git-authors": "3.2.0",
39-
"grunt-jscs": "2.8.0",
4040
"grunt-npmcopy": "0.1.0",
4141
"grunt-qunit-istanbul": "0.6.0",
4242
"jquery": "3.1.1",

src/.eslintrc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"env": {
3+
"browser": false,
4+
"node": false
5+
},
6+
// Support: IE <=9 only, Android <=4.0 only
7+
// The above browsers are failing a lot of tests in the ES5
8+
// test suite at http://test262.ecmascript.org.
9+
"parserOptions": {
10+
"ecmaVersion": 3
11+
},
12+
"globals": {
13+
"window": true,
14+
15+
"define": true,
16+
"module": true,
17+
18+
"jQuery": true,
19+
"migrateWarn": true,
20+
"migrateWarnFunc": true,
21+
"migrateWarnProp": true,
22+
23+
"noGlobal": true
24+
}
25+
}

src/.jshintrc

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jQuery.find = function( selector ) {
2929
// The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
3030
// First see if qS thinks it's a valid selector, if so avoid a false positive
3131
try {
32-
document.querySelector( selector );
32+
window.document.querySelector( selector );
3333
} catch ( err1 ) {
3434

3535
// Didn't *look* valid to qSA, warn and try quoting what we think is the value
@@ -40,7 +40,7 @@ jQuery.find = function( selector ) {
4040
// If the regexp *may* have created an invalid selector, don't update it
4141
// Note that there may be false alarms if selector uses jQuery extensions
4242
try {
43-
document.querySelector( selector );
43+
window.document.querySelector( selector );
4444
migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
4545
args[ 0 ] = selector;
4646
} catch ( err2 ) {

src/event.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jQuery.event.fix = function( originalEvent ) {
2525
migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type );
2626
if ( ( props = fixHook.props ) && props.length ) {
2727
while ( props.length ) {
28-
jQuery.event.addProp( props.pop() );
28+
jQuery.event.addProp( props.pop() );
2929
}
3030
}
3131
}
@@ -67,12 +67,12 @@ jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
6767

6868
// Trigger "ready" event only once, on document ready
6969
jQuery( function() {
70-
jQuery( document ).triggerHandler( "ready" );
70+
jQuery( window.document ).triggerHandler( "ready" );
7171
} );
7272

7373
jQuery.event.special.ready = {
7474
setup: function() {
75-
if ( this === document ) {
75+
if ( this === window.document ) {
7676
migrateWarn( "'ready' event is deprecated" );
7777
}
7878
}

src/intro.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
;(function( factory ) {
2-
/* jshint browserify:true */
1+
;( function( factory ) {
32
if ( typeof define === "function" && define.amd ) {
3+
44
// AMD. Register as an anonymous module.
55
define( [ "jquery" ], window, factory );
66
} else if ( typeof module === "object" && module.exports ) {
7+
78
// Node/CommonJS
9+
// eslint-disable-next-line no-undef
810
module.exports = factory( require( "jquery" ), window );
911
} else {
12+
1013
// Browser globals
1114
factory( jQuery, window );
1215
}
13-
}(function( jQuery, window ) {
16+
} )( function( jQuery, window ) {
1417
"use strict";

src/migrate.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
/* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
12

23
( function() {
34

45
// Support: IE9 only
56
// IE9 only creates console object when dev tools are first opened
67
// Also, avoid Function#bind here to simplify PhantomJS usage
78
var log = window.console && window.console.log &&
8-
function() { window.console.log.apply( window.console, arguments ); },
9+
function() {
10+
window.console.log.apply( window.console, arguments );
11+
},
912
rbadVersions = /^[12]\./;
1013

1114
if ( !log ) {
@@ -79,7 +82,7 @@ function migrateWarnFunc( obj, prop, newFunc, msg ) {
7982
};
8083
}
8184

82-
if ( document.compatMode === "BackCompat" ) {
85+
if ( window.document.compatMode === "BackCompat" ) {
8386

8487
// JQuery has never supported or tested Quirks Mode
8588
migrateWarn( "jQuery is not compatible with Quirks Mode" );

src/offset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jQuery.fn.offset = function() {
1111
return origin;
1212
}
1313

14-
docElem = ( elem.ownerDocument || document ).documentElement;
14+
docElem = ( elem.ownerDocument || window.document ).documentElement;
1515
if ( !jQuery.contains( docElem, elem ) ) {
1616
migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
1717
return origin;

src/outro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
return jQuery;
2-
}));
2+
} );

0 commit comments

Comments
 (0)