Skip to content
This repository was archived by the owner on Oct 23, 2020. It is now read-only.

Commit c393ca6

Browse files
committed
Adopt Node.js linting rules
1 parent 9bf9686 commit c393ca6

File tree

10 files changed

+2113
-75
lines changed

10 files changed

+2113
-75
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.eslintrc.js

.eslintrc.js

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
'use strict';
2+
3+
// This is a modified version of the Node.js core ESLint configuration.
4+
5+
module.exports = {
6+
root: true,
7+
env: {
8+
node: true,
9+
es6: true
10+
},
11+
parser: 'babel-eslint',
12+
parserOptions: { sourceType: 'script' },
13+
rules: {
14+
// ESLint built-in rules
15+
// http://eslint.org/docs/rules
16+
'accessor-pairs': 'error',
17+
'array-callback-return': 'error',
18+
'arrow-parens': ['error', 'always'],
19+
'arrow-spacing': ['error', { before: true, after: true }],
20+
'block-scoped-var': 'error',
21+
'block-spacing': 'error',
22+
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
23+
'capitalized-comments': ['error', 'always', {
24+
line: {
25+
// Ignore all lines that have less characters than 20 and all lines that
26+
// start with something that looks like a variable name or code.
27+
// eslint-disable-next-line max-len
28+
ignorePattern: '.{0,20}$|[a-z]+ ?[0-9A-Z_.(/=:[#-]|std|http|ssh|ftp|(let|var|const) [a-z_A-Z0-9]+ =|[b-z] |[a-z]*[0-9].* ',
29+
ignoreInlineComments: true,
30+
ignoreConsecutiveComments: true
31+
},
32+
block: {
33+
ignorePattern: '.*'
34+
}
35+
}],
36+
'comma-dangle': ['error', 'never'],
37+
'comma-spacing': 'error',
38+
'comma-style': 'error',
39+
'computed-property-spacing': 'error',
40+
'constructor-super': 'error',
41+
'dot-location': ['error', 'property'],
42+
'dot-notation': 'error',
43+
'eol-last': 'error',
44+
'eqeqeq': ['error', 'smart'],
45+
'for-direction': 'error',
46+
'func-call-spacing': 'error',
47+
'func-name-matching': 'error',
48+
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
49+
'getter-return': 'error',
50+
'indent': ['error', 2, {
51+
ArrayExpression: 'first',
52+
CallExpression: { arguments: 'first' },
53+
FunctionDeclaration: { parameters: 'first' },
54+
FunctionExpression: { parameters: 'first' },
55+
MemberExpression: 'off',
56+
ObjectExpression: 'first',
57+
SwitchCase: 1
58+
}],
59+
'key-spacing': ['error', { mode: 'strict' }],
60+
'keyword-spacing': 'error',
61+
'linebreak-style': ['error', 'unix'],
62+
'max-len': ['error', {
63+
code: 80,
64+
ignorePattern: '^// Flags:',
65+
ignoreRegExpLiterals: true,
66+
ignoreUrls: true,
67+
tabWidth: 2
68+
}],
69+
'new-parens': 'error',
70+
'no-async-promise-executor': 'error',
71+
'no-class-assign': 'error',
72+
'no-confusing-arrow': 'error',
73+
'no-const-assign': 'error',
74+
'no-control-regex': 'error',
75+
'no-debugger': 'error',
76+
'no-delete-var': 'error',
77+
'no-dupe-args': 'error',
78+
'no-dupe-class-members': 'error',
79+
'no-dupe-keys': 'error',
80+
'no-duplicate-case': 'error',
81+
'no-duplicate-imports': 'error',
82+
'no-empty-character-class': 'error',
83+
'no-ex-assign': 'error',
84+
'no-extra-boolean-cast': 'error',
85+
'no-extra-parens': ['error', 'functions'],
86+
'no-extra-semi': 'error',
87+
'no-fallthrough': 'error',
88+
'no-func-assign': 'error',
89+
'no-global-assign': 'error',
90+
'no-invalid-regexp': 'error',
91+
'no-irregular-whitespace': 'error',
92+
'no-lonely-if': 'error',
93+
'no-misleading-character-class': 'error',
94+
'no-mixed-requires': 'error',
95+
'no-mixed-spaces-and-tabs': 'error',
96+
'no-multi-spaces': ['error', { ignoreEOLComments: true }],
97+
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }],
98+
'no-new-require': 'error',
99+
'no-new-symbol': 'error',
100+
'no-obj-calls': 'error',
101+
'no-octal': 'error',
102+
'no-path-concat': 'error',
103+
'no-proto': 'error',
104+
'no-redeclare': ['error', { 'builtinGlobals': false }],
105+
'no-restricted-modules': ['error', 'sys'],
106+
/* eslint-disable max-len */
107+
'no-restricted-properties': [
108+
'error',
109+
{
110+
object: 'assert',
111+
property: 'deepEqual',
112+
message: 'Use `assert.deepStrictEqual()`.'
113+
},
114+
{
115+
object: 'assert',
116+
property: 'notDeepEqual',
117+
message: 'Use `assert.notDeepStrictEqual()`.'
118+
},
119+
{
120+
object: 'assert',
121+
property: 'equal',
122+
message: 'Use `assert.strictEqual()` rather than `assert.equal()`.'
123+
},
124+
{
125+
object: 'assert',
126+
property: 'notEqual',
127+
message: 'Use `assert.notStrictEqual()` rather than `assert.notEqual()`.'
128+
},
129+
{
130+
property: '__defineGetter__',
131+
message: '__defineGetter__ is deprecated.'
132+
},
133+
{
134+
property: '__defineSetter__',
135+
message: '__defineSetter__ is deprecated.'
136+
}
137+
],
138+
'no-restricted-syntax': [
139+
'error',
140+
{
141+
selector: "CallExpression[callee.property.name='deepStrictEqual'][arguments.2.type='Literal']",
142+
message: 'Do not use a literal for the third argument of assert.deepStrictEqual().'
143+
},
144+
{
145+
selector: "CallExpression[callee.property.name='doesNotThrow']",
146+
message: 'Do not use `assert.doesNotThrow()`. Write the code without the wrapper and add a comment instead.'
147+
},
148+
{
149+
selector: "CallExpression[callee.property.name='doesNotReject']",
150+
message: 'Do not use `assert.doesNotReject()`. Write the code without the wrapper and add a comment instead.'
151+
},
152+
{
153+
selector: "CallExpression[callee.property.name='rejects'][arguments.length<2]",
154+
message: '`assert.rejects()` must be invoked with at least two arguments.'
155+
},
156+
{
157+
selector: "CallExpression[callee.property.name='strictEqual'][arguments.2.type='Literal']",
158+
message: 'Do not use a literal for the third argument of assert.strictEqual().'
159+
},
160+
{
161+
selector: "CallExpression[callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])",
162+
message: 'Use an object as second argument of `assert.throws()`.'
163+
},
164+
{
165+
selector: "CallExpression[callee.property.name='throws'][arguments.length<2]",
166+
message: '`assert.throws()` must be invoked with at least two arguments.'
167+
},
168+
{
169+
selector: "CallExpression[callee.name='setTimeout'][arguments.length<2]",
170+
message: '`setTimeout()` must be invoked with at least two arguments.'
171+
},
172+
{
173+
selector: "CallExpression[callee.name='setInterval'][arguments.length<2]",
174+
message: '`setInterval()` must be invoked with at least two arguments.'
175+
},
176+
{
177+
selector: 'ThrowStatement > CallExpression[callee.name=/Error$/]',
178+
message: 'Use `new` keyword when throwing an `Error`.'
179+
},
180+
{
181+
selector: "CallExpression[callee.property.name='notDeepStrictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression']):not([arguments.1.type='UnaryExpression'])",
182+
message: 'The first argument should be the `actual`, not the `expected` value.'
183+
},
184+
{
185+
selector: "CallExpression[callee.property.name='notStrictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression']):not([arguments.1.type='UnaryExpression'])",
186+
message: 'The first argument should be the `actual`, not the `expected` value.'
187+
},
188+
{
189+
selector: "CallExpression[callee.property.name='deepStrictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression']):not([arguments.1.type='UnaryExpression'])",
190+
message: 'The first argument should be the `actual`, not the `expected` value.'
191+
},
192+
{
193+
selector: "CallExpression[callee.property.name='strictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression']):not([arguments.1.type='UnaryExpression'])",
194+
message: 'The first argument should be the `actual`, not the `expected` value.'
195+
}
196+
],
197+
/* eslint-enable max-len */
198+
'no-return-await': 'error',
199+
'no-self-assign': 'error',
200+
'no-self-compare': 'error',
201+
'no-shadow-restricted-names': 'error',
202+
'no-tabs': 'error',
203+
'no-template-curly-in-string': 'error',
204+
'no-this-before-super': 'error',
205+
'no-throw-literal': 'error',
206+
'no-trailing-spaces': 'error',
207+
'no-undef': ['error', { typeof: true }],
208+
'no-undef-init': 'error',
209+
'no-unexpected-multiline': 'error',
210+
'no-unreachable': 'error',
211+
'no-unsafe-finally': 'error',
212+
'no-unsafe-negation': 'error',
213+
'no-unused-labels': 'error',
214+
'no-unused-vars': ['error', { args: 'none', caughtErrors: 'all' }],
215+
'no-use-before-define': ['error', {
216+
classes: true,
217+
functions: false,
218+
variables: false
219+
}],
220+
'no-useless-call': 'error',
221+
'no-useless-catch': 'error',
222+
'no-useless-concat': 'error',
223+
'no-useless-constructor': 'error',
224+
'no-useless-escape': 'error',
225+
'no-useless-return': 'error',
226+
'no-void': 'error',
227+
'no-whitespace-before-property': 'error',
228+
'no-with': 'error',
229+
'object-curly-spacing': ['error', 'always'],
230+
'one-var': ['error', { initialized: 'never' }],
231+
'one-var-declaration-per-line': 'error',
232+
'operator-linebreak': ['error', 'after'],
233+
'prefer-const': ['error', { ignoreReadBeforeAssign: true }],
234+
'quotes': ['error', 'single', { avoidEscape: true }],
235+
'quote-props': ['error', 'consistent'],
236+
'rest-spread-spacing': 'error',
237+
'semi': 'error',
238+
'semi-spacing': 'error',
239+
'space-before-blocks': ['error', 'always'],
240+
'space-before-function-paren': ['error', {
241+
anonymous: 'never',
242+
named: 'never',
243+
asyncArrow: 'always'
244+
}],
245+
'space-in-parens': ['error', 'never'],
246+
'space-infix-ops': 'error',
247+
'space-unary-ops': 'error',
248+
'spaced-comment': ['error', 'always', {
249+
'block': { 'balanced': true },
250+
'exceptions': ['-']
251+
}],
252+
'strict': ['error', 'global'],
253+
'symbol-description': 'error',
254+
'template-curly-spacing': 'error',
255+
'unicode-bom': 'error',
256+
'use-isnan': 'error',
257+
'valid-typeof': 'error'
258+
},
259+
globals: {
260+
Atomics: 'readable',
261+
BigInt: 'readable',
262+
BigInt64Array: 'readable',
263+
BigUint64Array: 'readable',
264+
TextEncoder: 'readable',
265+
TextDecoder: 'readable',
266+
queueMicrotask: 'readable'
267+
}
268+
};

.eslintrc.json

Lines changed: 0 additions & 36 deletions
This file was deleted.

lib/subtle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async function wrapKey(format, key, wrappingKey, wrapAlgorithm) {
9999
let wrapFn, alg;
100100
try {
101101
alg = getAlgorithm(wrapAlgorithm, wrapFn = 'wrapKey');
102-
} catch (err) {
102+
} catch {
103103
alg = getAlgorithm(wrapAlgorithm, wrapFn = 'encrypt');
104104
}
105105

@@ -126,7 +126,7 @@ async function unwrapKey(format, wrappedKey, unwrappingKey,
126126
let unwrapFn, alg;
127127
try {
128128
alg = getAlgorithm(unwrapAlgorithm, unwrapFn = 'unwrapKey');
129-
} catch (err) {
129+
} catch {
130130
alg = getAlgorithm(unwrapAlgorithm, unwrapFn = 'decrypt');
131131
}
132132

0 commit comments

Comments
 (0)