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
@@ -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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,4 @@
env:
node: false
browser: false
commonjs: true
9 changes: 6 additions & 3 deletions lib/browser/debug.js
@@ -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
@@ -1,3 +1,5 @@
'use strict';

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

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

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

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

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

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

/**
* Module dependencies.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/interfaces/index.js
@@ -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
@@ -1,3 +1,5 @@
'use strict';

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

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

/*!
* mocha
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
Expand Down
2 changes: 2 additions & 0 deletions lib/ms.js
@@ -1,3 +1,5 @@
'use strict';

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

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

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

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

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

/* eslint-env browser */

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/reporters/index.js
@@ -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
@@ -1,3 +1,5 @@
'use strict';

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* eslint-env browser */

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
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
@@ -0,0 +1,7 @@
env:
mocha: true
globals:
expect: false
assert: false
# https://github.com/sindresorhus/globals/pull/102
run: false

0 comments on commit 2bb2b9f

Please sign in to comment.