Skip to content

Commit 4547268

Browse files
plroebuckboneskull
authored andcommitted
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 eb034dd. * style(bin/options.js): Revert un-Prettier comment per Boneskull's request
1 parent 1606f35 commit 4547268

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

.lintstagedrc.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"linters": {
3+
"(bin/*|**/*.js)": [
4+
"prettier-eslint --write",
5+
"git add"
6+
]
7+
},
8+
"ignore": [
9+
"docs/**/*.js",
10+
"test/**/*.fixture.js"
11+
]
12+
}

bin/options.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function getOptions() {
4040
process.argv = process.argv
4141
.slice(0, 2)
4242
.concat(opts.concat(process.argv.slice(2)));
43-
} catch (err) {
44-
// ignore
43+
} catch (ignore) {
44+
// NOTE: should console.error() and throw the error
4545
}
4646

4747
process.env.LOADED_MOCHA_OPTS = true;

lib/browser/progress.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Progress.prototype.draw = function(ctx) {
112112
var w = ctx.measureText(text).width;
113113

114114
ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
115-
} catch (err) {
115+
} catch (ignore) {
116116
// don't fail if we can't render progress
117117
}
118118
return this;

lib/runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ Runner.prototype.fail = function(test, err) {
244244
try {
245245
err.stack =
246246
this.fullStackTrace || !err.stack ? err.stack : stackFilter(err.stack);
247-
} catch (ignored) {
247+
} catch (ignore) {
248248
// some environments do not take kindly to monkeying with the stack
249249
}
250250

package.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@
454454
"scripts": {
455455
"prepublishOnly": "nps test clean build",
456456
"start": "nps",
457-
"test": "nps test"
457+
"test": "nps test",
458+
"precommit": "lint-staged"
458459
},
459460
"dependencies": {
460461
"browser-stdout": "1.3.1",
@@ -527,12 +528,6 @@
527528
},
528529
"homepage": "https://mochajs.org",
529530
"logo": "https://cldup.com/S9uQ-cOLYz.svg",
530-
"lint-staged": {
531-
"*.js": [
532-
"prettier-eslint --write",
533-
"git add"
534-
]
535-
},
536531
"prettier": {
537532
"singleQuote": true,
538533
"bracketSpacing": false

0 commit comments

Comments
 (0)