From 45472680bcab4b5f376eb6f1a0087c9fbbdb11a5 Mon Sep 17 00:00:00 2001 From: "P. Roebuck" Date: Tue, 1 May 2018 14:29:42 -0500 Subject: [PATCH] Annotate when exceptions are caught but ignored; closes #3354 (#3356) * style(*various*): Annotate when exceptions are caught but ignored There's an existing convertion to name intentionally ignored errors in catch block as `ignore`. Modified codebase to follow it. Fixes #3354 * style(bin/options.js): Turn off prettier for single line Prettier reformatting is just wrong here. fs.readFileSync() should **not** be split across multiple lines. * Revert "style(bin/options.js): Turn off prettier for single line" This reverts commit eb034dd81efbeb61c7378d085a4983a93ce45998. * style(bin/options.js): Revert un-Prettier comment per Boneskull's request --- .lintstagedrc.json | 12 ++++++++++++ bin/options.js | 4 ++-- lib/browser/progress.js | 2 +- lib/runner.js | 2 +- package.json | 9 ++------- 5 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 .lintstagedrc.json diff --git a/.lintstagedrc.json b/.lintstagedrc.json new file mode 100644 index 0000000000..19b7946fff --- /dev/null +++ b/.lintstagedrc.json @@ -0,0 +1,12 @@ +{ + "linters": { + "(bin/*|**/*.js)": [ + "prettier-eslint --write", + "git add" + ] + }, + "ignore": [ + "docs/**/*.js", + "test/**/*.fixture.js" + ] +} diff --git a/bin/options.js b/bin/options.js index 41f7222a62..60cbcd705e 100644 --- a/bin/options.js +++ b/bin/options.js @@ -40,8 +40,8 @@ function getOptions() { process.argv = process.argv .slice(0, 2) .concat(opts.concat(process.argv.slice(2))); - } catch (err) { - // ignore + } catch (ignore) { + // NOTE: should console.error() and throw the error } process.env.LOADED_MOCHA_OPTS = true; diff --git a/lib/browser/progress.js b/lib/browser/progress.js index 0dcb341898..7bf400b58e 100644 --- a/lib/browser/progress.js +++ b/lib/browser/progress.js @@ -112,7 +112,7 @@ Progress.prototype.draw = function(ctx) { var w = ctx.measureText(text).width; ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1); - } catch (err) { + } catch (ignore) { // don't fail if we can't render progress } return this; diff --git a/lib/runner.js b/lib/runner.js index 3f4ba55ef0..6aefb34cce 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -244,7 +244,7 @@ Runner.prototype.fail = function(test, err) { try { err.stack = this.fullStackTrace || !err.stack ? err.stack : stackFilter(err.stack); - } catch (ignored) { + } catch (ignore) { // some environments do not take kindly to monkeying with the stack } diff --git a/package.json b/package.json index bccad95b68..1c40ba5143 100644 --- a/package.json +++ b/package.json @@ -454,7 +454,8 @@ "scripts": { "prepublishOnly": "nps test clean build", "start": "nps", - "test": "nps test" + "test": "nps test", + "precommit": "lint-staged" }, "dependencies": { "browser-stdout": "1.3.1", @@ -527,12 +528,6 @@ }, "homepage": "https://mochajs.org", "logo": "https://cldup.com/S9uQ-cOLYz.svg", - "lint-staged": { - "*.js": [ - "prettier-eslint --write", - "git add" - ] - }, "prettier": { "singleQuote": true, "bracketSpacing": false