Skip to content

Commit

Permalink
lint the hell out of the javascript; closes #2525
Browse files Browse the repository at this point in the history
- mostly whitespace changes
- add `'use strict';` everywhere
- fix problems with unused variables, bad variable names, multiple declarations, unreachable code, yoda expressions, error handling, instantiation, etc.
- add a few eslint directives to avoid rules when needed
- switch to YAML eslint configs
- remove `test/` from `.eslintignore`
- add `mocha.js` to `.eslintignore`
- add userland `assert` as dev dependency (as is recommended)
- rename `test/fixture-expect.js` to `test/setup.js`; add global `assert` here
- add `assert` and `run` globals to `test/`'s eslint config
- update `test/mocha.opts` as appropriate
- update `lint` target in `Makefile`
- update eslint environments as appropriate
  • Loading branch information
boneskull committed Oct 10, 2016
1 parent 1c72d5c commit 2bb2b9f
Show file tree
Hide file tree
Showing 182 changed files with 2,397 additions and 2,025 deletions.
5 changes: 2 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
lib/to-iso-string/
test/**/*
!test/runner.js
lib/to-iso-string/**/*.js
mocha.js
3 changes: 0 additions & 3 deletions .eslintrc.js

This file was deleted.

11 changes: 11 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
env:
node: true
browser: true
parserOptions:
ecmaVersion: 5
sourceType: script
extends: semistandard
rules:
strict:
- error
- safe
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ clean:

lint:
@printf "==> [Test :: Lint]\n"
$(ESLINT) browser-entry.js index.js karma.conf.js bin/mocha bin/_mocha "lib/**/*.js" "scripts/**/*.js" test
$(ESLINT) .

test-node: test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-glob test-requires test-reporters test-only test-global-only

Expand Down
1 change: 1 addition & 0 deletions bin/_mocha
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
'use strict';

/* eslint no-unused-vars: off */

Expand Down
2 changes: 2 additions & 0 deletions bin/mocha
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

'use strict';

/**
* This tiny wrapper file checks for known node flags and appends them
* when found, before invoking the "real" _mocha(1) executable.
Expand Down
12 changes: 7 additions & 5 deletions bin/options.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Dependencies.
*/
Expand All @@ -14,17 +16,17 @@ module.exports = getOptions;
* Get options.
*/

function getOptions() {
var optsPath = process.argv.indexOf('--opts') !== -1
? process.argv[process.argv.indexOf('--opts') + 1]
: 'test/mocha.opts';
function getOptions () {
var optsPath = process.argv.indexOf('--opts') === -1
? 'test/mocha.opts'
: process.argv[process.argv.indexOf('--opts') + 1];

try {
var opts = fs.readFileSync(optsPath, 'utf8')
.replace(/\\\s/g, '%20')
.split(/\s/)
.filter(Boolean)
.map(function(value) {
.map(function (value) {
return value.replace(/%20/g, ' ');
});

Expand Down
3 changes: 3 additions & 0 deletions browser-entry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';

/* eslint no-unused-vars: off */
/* eslint-env commonjs */

/**
* Shim process.stdout.
Expand Down
4 changes: 4 additions & 0 deletions lib/browser/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env:
node: false
browser: false
commonjs: true
9 changes: 6 additions & 3 deletions lib/browser/debug.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable no-unused-vars */
module.exports = function (type) {
return function () {};
'use strict';

function noop () {}

module.exports = function () {
return noop;
};
2 changes: 2 additions & 0 deletions lib/browser/events.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module exports.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/browser/progress.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Expose `Progress`.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/browser/tty.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

exports.isatty = function isatty () {
return true;
};
Expand Down
2 changes: 2 additions & 0 deletions lib/context.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/hook.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/interfaces/bdd.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/interfaces/exports.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/interfaces/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

exports.bdd = require('./bdd');
exports.tdd = require('./tdd');
exports.qunit = require('./qunit');
Expand Down
2 changes: 2 additions & 0 deletions lib/interfaces/qunit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/interfaces/tdd.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/*!
* mocha
* Copyright(c) 2011 TJ Holowaychuk <[email protected]>
Expand Down
2 changes: 2 additions & 0 deletions lib/ms.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Helpers.
*/
Expand Down
1 change: 1 addition & 0 deletions lib/pending.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';

/**
* Expose `Pending`.
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/doc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/dot.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/* eslint-env browser */

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

// Alias exports to a their normalized format Mocha#reporter to prevent a need
// for dynamic (try/catch) requires, which Browserify doesn't handle.
exports.Base = exports.base = require('./base');
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/json-stream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/json.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/landing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/list.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/markdown.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/min.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/nyan.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/progress.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/tap.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/xunit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/runnable.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/suite.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/* eslint-env browser */

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
"supports-color": "3.1.2"
},
"devDependencies": {
"assert": "^1.4.1",
"browserify": "^13.0.0",
"coffee-script": "^1.10.0",
"eslint": "^2.13.1",
Expand Down
8 changes: 0 additions & 8 deletions test/.eslintrc.js

This file was deleted.

7 changes: 7 additions & 0 deletions test/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
env:
mocha: true
globals:
expect: false
assert: false
# https://github.com/sindresorhus/globals/pull/102
run: false
Loading

0 comments on commit 2bb2b9f

Please sign in to comment.