forked from mysticatea/eslint-plugin-node
-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathprocess-exit-as-throw.js
87 lines (73 loc) · 2.41 KB
/
process-exit-as-throw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* @author Toru Nagashima
* See LICENSE file in root directory for full license.
*/
"use strict"
/*eslint-env mocha */
const assert = require("assert")
const eslint = require("eslint")
const rule = require("../../../lib/rules/process-exit-as-throw")
const supported = rule.meta.supported
describe("process-exit-as-throw", () => {
let linter = eslint.linter
beforeEach(() => {
if (eslint.Linter != null) {
linter = new eslint.Linter()
} else {
linter.reset()
}
linter.defineRule("process-exit-as-throw", rule)
})
;(supported ? it : xit)(
"should get unreachable error after 'process.exit()'.",
() => {
const code = ["foo();", "process.exit(1);", "bar();"].join("\n")
const options = {
rules: {
"no-unreachable": "error",
"process-exit-as-throw": "error",
},
}
const messages = linter.verify(code, options)
assert.strictEqual(messages.length, 1)
assert.strictEqual(messages[0].message, "Unreachable code.")
assert.strictEqual(messages[0].line, 3)
}
)
;(supported ? it : xit)(
"should get no unreachable error after 'process.exit()' if this rule is turned off.",
() => {
const code = ["foo();", "process.exit(1);", "bar();"].join("\n")
const options = {
rules: {
"no-unreachable": "error",
"process-exit-as-throw": "off",
},
}
const messages = linter.verify(code, options)
assert.strictEqual(messages.length, 0)
}
)
;(supported ? it : xit)(
"should get no consistent-return error after 'process.exit()'.",
() => {
const code = [
"function foo() {",
" if (a) {",
" return 1;",
" } else {",
" process.exit(1);",
" }",
"}",
].join("\n")
const options = {
rules: {
"consistent-return": "error",
"process-exit-as-throw": "error",
},
}
const messages = linter.verify(code, options)
assert.strictEqual(messages.length, 0)
}
)
})