Skip to content

Build: Switch from JSHint/JSCS to ESLint (+ other housekeeping) #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage
external
node_modules
*.min.js
src/intro.js
src/outro.js
test/data/jquery-*.js
test/data/jquery.mobile-*.js
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "jquery",
"root": true,
"env": {
"browser": false,
"node": true
}
}
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
dist
coverage
CDN
.project
Expand All @@ -8,4 +7,9 @@ CDN
*.patch
/*.html
.DS_Store
node_modules

# Ignore everything in dist folder except for eslint config
/dist/*
!/dist/.eslintrc.json

node_modules
5 changes: 0 additions & 5 deletions .jscsrc

This file was deleted.

17 changes: 0 additions & 17 deletions .jshintrc

This file was deleted.

74 changes: 28 additions & 46 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ module.exports = function( grunt ) {

"use strict";

// The concatenated file won't pass onevar but our modules can
var readOptionalJSON = function( filepath ) {
var data = {};
try {
data = grunt.file.readJSON( filepath );
} catch ( e ) {}
return data;
},
srcHintOptions = readOptionalJSON( "src/.jshintrc" );
delete srcHintOptions.onevar;

// Project configuration.
grunt.initConfig( {
pkg: grunt.file.readJSON( "package.json" ),
Expand Down Expand Up @@ -77,13 +66,24 @@ module.exports = function( grunt ) {
force: true
}
},
jscs: {
src: [
"test/*.js",
"<%= files %>",
"Gruntfile.js",
"build/**/*.js"
]
eslint: {
options: {

// See https://github.com/sindresorhus/grunt-eslint/issues/119
quiet: true
},

dist: {
src: "dist/jquery-migrate.js"
},
dev: {
src: [
"Gruntfile.js",
"build/**/*.js",
"src/**/*.js",
"test/**/*.js"
]
}
},
npmcopy: {
all: {
Expand All @@ -97,24 +97,6 @@ module.exports = function( grunt ) {
"qunit/LICENSE.txt": "qunitjs/LICENSE.txt" }
}
},
jshint: {
dist: {
src: [ "dist/jquery-migrate.js" ],
options: srcHintOptions
},
tests: {
src: [ "test/*.js" ],
options: {
jshintrc: "test/.jshintrc"
}
},
grunt: {
src: [ "Gruntfile.js" ],
options: {
jshintrc: ".jshintrc"
}
}
},
uglify: {
all: {
files: {
Expand All @@ -136,23 +118,23 @@ module.exports = function( grunt ) {
} );

// Load grunt tasks from NPM packages
grunt.loadNpmTasks( "grunt-git-authors" );
grunt.loadNpmTasks( "grunt-contrib-concat" );
grunt.loadNpmTasks( "grunt-contrib-watch" );
grunt.loadNpmTasks( "grunt-contrib-jshint" );
grunt.loadNpmTasks( "grunt-jscs" );
grunt.loadNpmTasks( "grunt-contrib-uglify" );
grunt.loadNpmTasks( "grunt-qunit-istanbul" );
grunt.loadNpmTasks( "grunt-coveralls" );
grunt.loadNpmTasks( "grunt-npmcopy" );
require( "load-grunt-tasks" )( grunt );

// Integrate jQuery migrate specific tasks
grunt.loadTasks( "build/tasks" );

// Just an alias
grunt.registerTask( "test", [ "qunit" ] );

grunt.registerTask( "lint", [ "jshint", "jscs" ] );
grunt.registerTask( "lint", [

// Running the full eslint task without breaking it down to targets
// would run the dist target first which would point to errors in the built
// file, making it harder to fix them. We want to check the built file only
// if we already know the source files pass the linter.
"eslint:dev",
"eslint:dist"
] );
grunt.registerTask( "build", [ "concat", "uglify", "lint" ] );

grunt.registerTask( "default", [ "build", "test" ] );
Expand Down
14 changes: 8 additions & 6 deletions build/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var releaseVersion,
// Windows needs the .cmd version but will find the non-.cmd
// On Windows, also ensure the HOME environment variable is set
gruntCmd = process.platform === "win32" ? "grunt.cmd" : "grunt",
npmCmd = process.platform == "win32" ? "npm.cmd" : "npm",
npmCmd = process.platform === "win32" ? "npm.cmd" : "npm",

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

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

function gruntBuild( next ) {
exec( gruntCmd, [], function( error, stdout ) {
exec( gruntCmd, [], function( error, stdout, stderr ) {
if ( error ) {
die( error + stderr );
}
Expand Down Expand Up @@ -234,7 +234,7 @@ function updateSourceVersion( ver ) {
}
}

function updateReadmeVersion( ver ) {
function updateReadmeVersion() {
var readme = fs.readFileSync( readmeFile, "utf8" );

// Change version references from the old version to the new one.
Expand All @@ -243,8 +243,10 @@ function updateReadmeVersion( ver ) {
status( "Skipping " + readmeFile + " update (beta release)" );
} else {
status( "Updating " + readmeFile );
readme = readme
.replace( /jquery-migrate-\d+\.\d+\.\d+(?:-\w+)?/g, "jquery-migrate-" + releaseVersion );
readme = readme.replace(
/jquery-migrate-\d+\.\d+\.\d+(?:-\w+)?/g,
"jquery-migrate-" + releaseVersion
);
if ( !dryrun ) {
fs.writeFileSync( readmeFile, readme );
}
Expand Down
8 changes: 8 additions & 0 deletions dist/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../src/.eslintrc.json",
"root": true,
"rules": {
// That is okay for the built version
"no-multiple-empty-lines": "off"
}
}
157 changes: 79 additions & 78 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,80 +1,81 @@
{
"name": "jquery-migrate",
"title": "jQuery Migrate",
"description": "Migrate older jQuery code to jQuery 3.0+",
"main": "dist/jquery-migrate.js",
"version": "3.0.1-pre",
"homepage": "https://github.com/jquery/jquery-migrate",
"author": {
"name": "jQuery Foundation and other contributors",
"url": "https://github.com/jquery/jquery-migrate/blob/master/AUTHORS.txt"
},
"repository": {
"type": "git",
"url": "git://github.com/jquery/jquery-migrate.git"
},
"bugs": {
"url": "http://bugs.jquery.com/"
},
"license": "MIT",
"scripts": {
"build": "grunt build",
"test": "grunt test",
"ci": "grunt ci"
},
"peerDependencies": {
"jquery": ">=3 <4"
},
"devDependencies": {
"chalk": "1.1.3",
"commitplease": "2.3.1",
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-concat": "1.0.1",
"grunt-contrib-jshint": "1.0.0",
"grunt-contrib-uglify": "1.0.1",
"grunt-contrib-watch": "1.0.0",
"grunt-coveralls": "1.0.1",
"grunt-git-authors": "3.2.0",
"grunt-jscs": "2.8.0",
"grunt-npmcopy": "0.1.0",
"grunt-qunit-istanbul": "0.6.0",
"jquery": "3.1.1",
"phantomjs-polyfill": "0.0.2",
"qunitjs": "1.23.1",
"testswarm": "1.1.0"
},
"keywords": [
"jquery",
"javascript",
"browser",
"plugin",
"migrate"
],
"commitplease": {
"components": [
"Docs",
"Tests",
"Build",
"Release",
"Core",
"Ajax",
"Attributes",
"Callbacks",
"CSS",
"Data",
"Deferred",
"Deprecated",
"Dimensions",
"Effects",
"Event",
"Manipulation",
"Offset",
"Queue",
"Selector",
"Serialize",
"Traversing",
"Wrap"
]
}
"name": "jquery-migrate",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably should change

[package.json]
then

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It already says "2 spaces" so this file was incorrectly formatted...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O, can't really see tabs vs spaces thingy in github UI

"title": "jQuery Migrate",
"description": "Migrate older jQuery code to jQuery 3.0+",
"main": "dist/jquery-migrate.js",
"version": "3.0.1-pre",
"homepage": "https://github.com/jquery/jquery-migrate",
"author": {
"name": "jQuery Foundation and other contributors",
"url": "https://github.com/jquery/jquery-migrate/blob/master/AUTHORS.txt"
},
"repository": {
"type": "git",
"url": "git://github.com/jquery/jquery-migrate.git"
},
"bugs": {
"url": "http://bugs.jquery.com/"
},
"license": "MIT",
"scripts": {
"build": "grunt build",
"test": "grunt test",
"ci": "grunt ci"
},
"peerDependencies": {
"jquery": ">=3 <4"
},
"devDependencies": {
"chalk": "1.1.3",
"commitplease": "2.7.5",
"eslint-config-jquery": "1.0.0",
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-concat": "1.0.1",
"grunt-contrib-uglify": "2.0.0",
"grunt-contrib-watch": "1.0.0",
"grunt-coveralls": "1.0.1",
"grunt-eslint": "19.0.0",
"grunt-git-authors": "3.2.0",
"grunt-npmcopy": "0.1.0",
"grunt-qunit-istanbul": "0.6.0",
"jquery": "3.1.1",
"load-grunt-tasks": "3.5.2",
"phantomjs-polyfill": "0.0.2",
"qunitjs": "1.23.1",
"testswarm": "1.1.0"
},
"keywords": [
"jquery",
"javascript",
"browser",
"plugin",
"migrate"
],
"commitplease": {
"components": [
"Docs",
"Tests",
"Build",
"Release",
"Core",
"Ajax",
"Attributes",
"Callbacks",
"CSS",
"Data",
"Deferred",
"Deprecated",
"Dimensions",
"Effects",
"Event",
"Manipulation",
"Offset",
"Queue",
"Selector",
"Serialize",
"Traversing",
"Wrap"
]
}
}
Loading