Skip to content

Commit 97c17c7

Browse files
committed
tools: enable no-undef, define globals for eslint
- Enable the no-undef rule for everything except tests. - Instead of relying on the predefined node environment, specify all our globals manually and as read-only. - Enable globalReturn which was previously implied by the node environment.
1 parent 4e90c82 commit 97c17c7

File tree

6 files changed

+67
-55
lines changed

6 files changed

+67
-55
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ test/addons/doc-*/
33
test/fixtures
44
test/**/node_modules
55
test/parallel/test-fs-non-number-arguments-throw.js
6+
test/disabled

.eslintrc

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
env:
2-
node: true
3-
41
# enable ECMAScript features
52
ecmaFeatures:
63
blockBindings: true
@@ -10,6 +7,7 @@ ecmaFeatures:
107
generators: true
118
forOf: true
129
objectLiteralShorthandProperties: true
10+
globalReturn: true
1311

1412
rules:
1513
# Possible Errors
@@ -39,14 +37,9 @@ rules:
3937
# Stylistic Issues
4038
# list: https://github.com/eslint/eslint/tree/master/docs/rules#stylistic-issues
4139
## use single quote, we can use double quote when escape chars
42-
quotes:
43-
- 2
44-
- "single"
45-
- "avoid-escape"
40+
quotes: [2, "single", "avoid-escape"]
4641
## 2 space indentation
47-
indent:
48-
- 2
49-
- 2
42+
indent: [2, 2]
5043
## add space after comma
5144
## set to 'warn' because of https://github.com/eslint/eslint/issues/2408
5245
comma-spacing: 1
@@ -63,35 +56,56 @@ rules:
6356
## require parens for Constructor
6457
new-parens: 2
6558
## max 80 length
66-
max-len:
67-
- 2
68-
- 80
69-
- 2
59+
max-len: [2, 80, 2]
7060

7161
# Strict Mode
7262
# list: https://github.com/eslint/eslint/tree/master/docs/rules#strict-mode
7363
## 'use strict' on top
74-
strict:
75-
- 2
76-
- "global"
64+
strict: [2, "global"]
65+
66+
# Variables
67+
# list: https://github.com/eslint/eslint/tree/master/docs/rules#variables
68+
## disallow use of undefined variables (globals)
69+
no-undef: 2
7770

7871
# Global scoped method and vars
7972
globals:
80-
DTRACE_HTTP_CLIENT_REQUEST: true
81-
LTTNG_HTTP_CLIENT_REQUEST: true
82-
COUNTER_HTTP_CLIENT_REQUEST: true
83-
DTRACE_HTTP_CLIENT_RESPONSE: true
84-
LTTNG_HTTP_CLIENT_RESPONSE: true
85-
COUNTER_HTTP_CLIENT_RESPONSE: true
86-
DTRACE_HTTP_SERVER_REQUEST: true
87-
LTTNG_HTTP_SERVER_REQUEST: true
88-
COUNTER_HTTP_SERVER_REQUEST: true
89-
DTRACE_HTTP_SERVER_RESPONSE: true
90-
LTTNG_HTTP_SERVER_RESPONSE: true
91-
COUNTER_HTTP_SERVER_RESPONSE: true
92-
DTRACE_NET_STREAM_END: true
93-
LTTNG_NET_STREAM_END: true
94-
COUNTER_NET_SERVER_CONNECTION_CLOSE: true
95-
DTRACE_NET_SERVER_CONNECTION: true
96-
LTTNG_NET_SERVER_CONNECTION: true
97-
COUNTER_NET_SERVER_CONNECTION: true
73+
DTRACE_HTTP_CLIENT_REQUEST: false
74+
LTTNG_HTTP_CLIENT_REQUEST: false
75+
COUNTER_HTTP_CLIENT_REQUEST: false
76+
DTRACE_HTTP_CLIENT_RESPONSE: false
77+
LTTNG_HTTP_CLIENT_RESPONSE: false
78+
COUNTER_HTTP_CLIENT_RESPONSE: false
79+
DTRACE_HTTP_SERVER_REQUEST: false
80+
LTTNG_HTTP_SERVER_REQUEST: false
81+
COUNTER_HTTP_SERVER_REQUEST: false
82+
DTRACE_HTTP_SERVER_RESPONSE: false
83+
LTTNG_HTTP_SERVER_RESPONSE: false
84+
COUNTER_HTTP_SERVER_RESPONSE: false
85+
DTRACE_NET_STREAM_END: false
86+
LTTNG_NET_STREAM_END: false
87+
COUNTER_NET_SERVER_CONNECTION_CLOSE: false
88+
DTRACE_NET_SERVER_CONNECTION: false
89+
LTTNG_NET_SERVER_CONNECTION: false
90+
COUNTER_NET_SERVER_CONNECTION: false
91+
__dirname: false
92+
__filename: false
93+
ArrayBuffer: false
94+
Buffer: false
95+
clearImmediate: false
96+
clearInterval: false
97+
clearTimeout: false
98+
console: false
99+
DataView: false
100+
escape: false
101+
exports: false
102+
global: false
103+
GLOBAL: false
104+
Intl: false
105+
module: false
106+
process: false
107+
require: false
108+
root: false
109+
setImmediate: false
110+
setInterval: false
111+
setTimeout: false

test/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
rules:
44
## allow unreachable code
55
no-unreachable: 0
6+
## allow undeclared variables
7+
no-undef: 0
8+
9+
globals:
10+
gc: false

test/parallel/test-cluster-worker-exit.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,13 @@ function checkResults(expected_results, results) {
106106
var actual = results[k],
107107
expected = expected_results[k];
108108

109-
if (typeof expected === 'function') {
110-
expected(r[k]);
111-
} else {
112-
var msg = (expected[1] || '') +
113-
(' [expected: ' + expected[0] + ' / actual: ' + actual + ']');
109+
var msg = (expected[1] || '') +
110+
(' [expected: ' + expected[0] + ' / actual: ' + actual + ']');
114111

115-
if (expected && expected.length) {
116-
assert.equal(actual, expected[0], msg);
117-
} else {
118-
assert.equal(actual, expected, msg);
119-
}
112+
if (expected && expected.length) {
113+
assert.equal(actual, expected[0], msg);
114+
} else {
115+
assert.equal(actual, expected, msg);
120116
}
121117
}
122118
}

test/parallel/test-cluster-worker-kill.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,12 @@ function checkResults(expected_results, results) {
106106
var actual = results[k],
107107
expected = expected_results[k];
108108

109-
if (typeof expected === 'function') {
110-
expected(r[k]);
109+
var msg = (expected[1] || '') +
110+
(' [expected: ' + expected[0] + ' / actual: ' + actual + ']');
111+
if (expected && expected.length) {
112+
assert.equal(actual, expected[0], msg);
111113
} else {
112-
var msg = (expected[1] || '') +
113-
(' [expected: ' + expected[0] + ' / actual: ' + actual + ']');
114-
if (expected && expected.length) {
115-
assert.equal(actual, expected[0], msg);
116-
} else {
117-
assert.equal(actual, expected, msg);
118-
}
114+
assert.equal(actual, expected, msg);
119115
}
120116
}
121117
}

test/pummel/test-net-timeout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ process.on('exit', function() {
7979
assert.ok(starttime != null);
8080
assert.ok(timeouttime != null);
8181

82-
diff = timeouttime - starttime;
82+
var diff = timeouttime - starttime;
8383
console.log('diff = ' + diff);
8484

8585
assert.ok(timeout < diff);

0 commit comments

Comments
 (0)