Skip to content

Commit 6e4d302

Browse files
committed
tools: enable/add additional eslint rules
Enables the following rules: - no-undef: Valuable rule to error on usage of undefined variables - require-buffer: Custom rule that forbids usage of the global Buffer inside lib/ because of REPL issues. PR-URL: #1794 Reviewed-By: Trevor Norris <[email protected]>
1 parent b5b8ff1 commit 6e4d302

File tree

7 files changed

+59
-34
lines changed

7 files changed

+59
-34
lines changed

.eslintignore

+1
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

+32-32
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,9 @@ rules:
3939
# Stylistic Issues
4040
# list: https://github.com/eslint/eslint/tree/master/docs/rules#stylistic-issues
4141
## use single quote, we can use double quote when escape chars
42-
quotes:
43-
- 2
44-
- "single"
45-
- "avoid-escape"
42+
quotes: [2, "single", "avoid-escape"]
4643
## 2 space indentation
47-
indent:
48-
- 2
49-
- 2
44+
indent: [2, 2]
5045
## add space after comma
5146
## set to 'warn' because of https://github.com/eslint/eslint/issues/2408
5247
comma-spacing: 1
@@ -63,35 +58,40 @@ rules:
6358
## require parens for Constructor
6459
new-parens: 2
6560
## max 80 length
66-
max-len:
67-
- 2
68-
- 80
69-
- 2
61+
max-len: [2, 80, 2]
7062

7163
# Strict Mode
7264
# list: https://github.com/eslint/eslint/tree/master/docs/rules#strict-mode
7365
## 'use strict' on top
74-
strict:
75-
- 2
76-
- "global"
66+
strict: [2, "global"]
67+
68+
# Variables
69+
# list: https://github.com/eslint/eslint/tree/master/docs/rules#variables
70+
## disallow use of undefined variables (globals)
71+
no-undef: 2
72+
73+
# Custom rules in tools/eslint-rules
74+
require-buffer: 2
7775

7876
# Global scoped method and vars
7977
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
78+
DTRACE_HTTP_CLIENT_REQUEST : false
79+
LTTNG_HTTP_CLIENT_REQUEST : false
80+
COUNTER_HTTP_CLIENT_REQUEST : false
81+
DTRACE_HTTP_CLIENT_RESPONSE : false
82+
LTTNG_HTTP_CLIENT_RESPONSE : false
83+
COUNTER_HTTP_CLIENT_RESPONSE : false
84+
DTRACE_HTTP_SERVER_REQUEST : false
85+
LTTNG_HTTP_SERVER_REQUEST : false
86+
COUNTER_HTTP_SERVER_REQUEST : false
87+
DTRACE_HTTP_SERVER_RESPONSE : false
88+
LTTNG_HTTP_SERVER_RESPONSE : false
89+
COUNTER_HTTP_SERVER_RESPONSE : false
90+
DTRACE_NET_STREAM_END : false
91+
LTTNG_NET_STREAM_END : false
92+
COUNTER_NET_SERVER_CONNECTION_CLOSE : false
93+
DTRACE_NET_SERVER_CONNECTION : false
94+
LTTNG_NET_SERVER_CONNECTION : false
95+
COUNTER_NET_SERVER_CONNECTION : false
96+
escape : false
97+
unescape : false

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ bench-idle:
375375
./$(NODE_EXE) benchmark/idle_clients.js &
376376

377377
jslint:
378-
./$(NODE_EXE) tools/eslint/bin/eslint.js src lib test --reset --quiet
378+
./$(NODE_EXE) tools/eslint/bin/eslint.js src lib test --rulesdir tools/eslint-rules --reset --quiet
379379

380380
CPPLINT_EXCLUDE ?=
381381
CPPLINT_EXCLUDE += src/node_lttng.cc

lib/buffer.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable require-buffer */
12
'use strict';
23

34
const binding = process.binding('buffer');

test/.eslintrc

+7
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33
rules:
44
## allow unreachable code
55
no-unreachable: 0
6+
## allow undeclared variables
7+
no-undef: 0
8+
## allow global Buffer usage
9+
require-buffer: 0
10+
11+
globals:
12+
gc: false

tools/eslint-rules/require-buffer.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const msg = 'Use const Buffer = require(\'buffer\').Buffer; ' +
4+
'at the beginning of this file';
5+
6+
module.exports = function(context) {
7+
return {
8+
'Program:exit': function() {
9+
context.getScope().through.forEach(function(ref) {
10+
if (ref.identifier.name === 'Buffer') {
11+
context.report(ref.identifier, msg);
12+
}
13+
});
14+
}
15+
}
16+
}

vcbuild.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ goto jslint
181181
:jslint
182182
if not defined jslint goto exit
183183
echo running jslint
184-
%config%\iojs tools\eslint\bin\eslint.js src lib test --reset --quiet
184+
%config%\iojs tools\eslint\bin\eslint.js src lib test --rulesdir tools\eslint-rules --reset --quiet
185185
goto exit
186186

187187
:create-msvs-files-failed

0 commit comments

Comments
 (0)