Skip to content

Commit 9d85092

Browse files
committed
[eslint] add linting
1 parent 7ecd773 commit 9d85092

File tree

5 files changed

+182
-20
lines changed

5 files changed

+182
-20
lines changed

.eslintrc

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{
2+
"root": true,
3+
4+
"extends": "@ljharb/eslint-config/node/8",
5+
6+
"rules": {
7+
"comma-dangle": "warn",
8+
"func-style": "off",
9+
"id-length": "off",
10+
"indent": ["error", 2],
11+
"multiline-comment-style": "off",
12+
"no-unused-vars": "warn",
13+
"sort-keys": "off",
14+
},
15+
16+
"ignorePatterns": [
17+
"build",
18+
],
19+
20+
"overrides": [
21+
{
22+
"files": "test.js",
23+
"rules": {
24+
"global-require": "off",
25+
"max-nested-callbacks": "off",
26+
},
27+
},
28+
{
29+
"files": "assert.js", // mostly from node core
30+
"rules": {
31+
"array-bracket-newline": "off",
32+
"array-element-newline": "off",
33+
"arrow-body-style": "off",
34+
"arrow-parens": "off",
35+
"curly": "off",
36+
"eqeqeq": "off",
37+
"func-name-matching": "off",
38+
"function-call-argument-newline": "off",
39+
"function-paren-newline": "off",
40+
"global-require": "off",
41+
"indent": "off",
42+
"max-lines": "off",
43+
"max-params": "off",
44+
"new-cap": "off",
45+
"no-mixed-operators": "off",
46+
"no-multi-assign": "off",
47+
"no-negated-condition": "off",
48+
"no-param-reassign": "off",
49+
"operator-linebreak": ["error", "after"],
50+
"no-prototype-builtins": "off",
51+
"no-restricted-syntax": "off",
52+
"no-use-before-define": "off",
53+
"no-var": "off",
54+
"nonblock-statement-body-position": "off",
55+
"object-curly-newline": "off",
56+
"prefer-destructuring": "off",
57+
"prefer-template": "off",
58+
"sort-keys": "off",
59+
},
60+
},
61+
{
62+
"files": "internal/**",
63+
"rules": {
64+
"arrow-parens": "off",
65+
"camelcase": "off",
66+
"complexity": "off",
67+
"curly": "off",
68+
"default-case": "off",
69+
"eqeqeq": "off",
70+
"function-call-argument-newline": "off",
71+
"function-paren-newline": "off",
72+
"global-require": "off",
73+
"indent": "off",
74+
"max-depth": "off",
75+
"max-lines-per-function": "off",
76+
"max-lines": "off",
77+
"max-params": "off",
78+
"max-statements": "off",
79+
"no-else-return": "off",
80+
"no-extra-parens": "off",
81+
"no-implicit-coercion": "off",
82+
"no-mixed-operators": "off",
83+
"no-negated-condition": "off",
84+
"no-param-reassign": "off",
85+
"no-plusplus": "off",
86+
"no-restricted-syntax": "off",
87+
"no-shadow": "off",
88+
"no-unused-expressions": "off",
89+
"no-use-before-define": "off",
90+
"no-var": "off",
91+
"nonblock-statement-body-position": "off",
92+
"object-curly-newline": "off",
93+
"operator-linebreak": "off",
94+
"prefer-template": "off",
95+
"semi": "off",
96+
"space-before-function-paren": "off",
97+
"wrap-regex": "off",
98+
},
99+
},
100+
{
101+
"files": "test/**", // test files from node core
102+
"rules": {
103+
"array-bracket-spacing": "off",
104+
"arrow-parens": "off",
105+
"comma-dangle": "off",
106+
"consistent-return": "off",
107+
"curly": "off",
108+
"default-param-last": "off",
109+
"eqeqeq": "off",
110+
"function-call-argument-newline": "off",
111+
"function-paren-newline": "off",
112+
"global-require": "off",
113+
"indent": "off",
114+
"keyword-spacing": "off",
115+
"lines-around-directive": "off",
116+
"max-lines-per-function": "off",
117+
"new-cap": "off",
118+
"no-else-return": "off",
119+
"no-eval": "off",
120+
"operator-linebreak": ["error", "after"],
121+
"no-extra-parens": "off",
122+
"no-inner-declarations": "off",
123+
"no-invalid-this": "off",
124+
"no-lone-blocks": "off",
125+
"no-multi-spaces": "off",
126+
"no-multiple-empty-lines": "off",
127+
"no-new-func": "off",
128+
"no-new-wrappers": "off",
129+
"no-param-reassign": "off",
130+
"no-plusplus": "off",
131+
"no-prototype-builtins": "off",
132+
"no-shadow": "off",
133+
"no-sparse-arrays": "off",
134+
"no-undef": "off",
135+
"no-underscore-dangle": "off",
136+
"no-use-before-define": "off",
137+
"no-var": "off",
138+
"nonblock-statement-body-position": "off",
139+
"object-curly-spacing": "off",
140+
"object-shorthand": "off",
141+
"prefer-arrow-callback": "off",
142+
"prefer-destructuring": "off",
143+
"prefer-promise-reject-errors": "off",
144+
"prefer-rest-params": "off",
145+
"prefer-template": "off",
146+
"quote-props": "off",
147+
"space-before-function-paren": "off",
148+
"strict": "off",
149+
"wrap-iife": "off",
150+
"wrap-regex": "off",
151+
},
152+
},
153+
],
154+
}

babel.config.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
'use strict';
2+
13
const presets = [
24
[
3-
"@babel/env",
5+
'@babel/env',
46
{
57
targets: {
6-
edge: "18",
7-
firefox: "66",
8-
chrome: "73",
9-
safari: "12",
10-
ie: "11"
11-
}
8+
edge: '18',
9+
firefox: '66',
10+
chrome: '73',
11+
safari: '12',
12+
ie: '11',
13+
},
1214
},
1315
],
1416
];
1517

16-
module.exports = {presets};
18+
module.exports = { presets };

internal/errors.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// Currently in sync with Node.js lib/internal/errors.js
22
// https://github.com/nodejs/node/commit/3b044962c48fe313905877a96b5d0894a5404f6f
33

4-
/* eslint node-core/documented-errors: "error" */
5-
/* eslint node-core/alphabetize-errors: "error" */
6-
/* eslint node-core/prefer-util-format-errors: "error" */
7-
84
'use strict';
95

106
// The whole point behind this internal module is to allow Node.js to no

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
"build": "babel assert.js test.js --out-dir build && babel internal --out-dir build/internal && babel test --out-dir build/test",
1515
"prepare": "npm run build",
1616
"dev": "babel assert.js test.js --watch --out-dir build & babel internal --watch --out-dir build/internal & babel test --watch --out-dir build/test",
17-
"test": "npm run build && npm run test:nobuild",
18-
"test:nobuild": "node build/test.js",
19-
"test:source": "node test.js",
17+
"lint": "eslint --ext=js,mjs .",
18+
"pretest": "npm run lint",
19+
"test": "npm run tests-only",
20+
"posttest": "aud --production",
21+
"pretests-only": "npm run build",
22+
"tests-only": "npm run test:nobuild",
23+
"test:nobuild": "tape build/test.js",
24+
"test:source": "tape test.js",
2025
"test:browsers": "airtap build/test.js",
2126
"test:browsers:local": "npm run test:browsers -- --local"
2227
},
@@ -28,10 +33,13 @@
2833
"@babel/cli": "^7.22.15",
2934
"@babel/core": "^7.22.15",
3035
"@babel/preset-env": "^7.22.15",
36+
"@ljharb/eslint-config": "^21.1.0",
3137
"airtap": "^2.0.4",
3238
"array-fill": "^1.2.0",
39+
"aud": "^2.0.3",
3340
"core-js": "^3.32.2",
3441
"cross-env": "^5.2.1",
42+
"eslint": "=8.8.0",
3543
"object.entries": "^1.1.7",
3644
"object.getownpropertydescriptors": "^2.1.7",
3745
"tape": "^5.6.6"

test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const test = require('tape');
24

35
// Conditionally load polyfills required for testing
@@ -18,19 +20,19 @@ const testPaths = [
1820
['test-assert.js', () => require('./test/parallel/test-assert.js')],
1921
['test-assert-colors.js', () => require('./test/pseudo-tty/test-assert-colors.js')],
2022
['test-assert-no-color.js', () => require('./test/pseudo-tty/test-assert-no-color.js')],
21-
['test-assert-position-indicator.js', () => require('./test/pseudo-tty/test-assert-position-indicator.js')]
23+
['test-assert-position-indicator.js', () => require('./test/pseudo-tty/test-assert-position-indicator.js')],
2224
];
2325

2426
testPaths.forEach(([testName, requireTest]) => {
25-
test(testName, t => {
26-
t.plan(2)
27+
test(testName, (t) => {
28+
t.plan(2);
2729
let result;
2830
t.doesNotThrow(() => {
2931
result = requireTest();
3032
});
3133
Promise.resolve(result)
3234
.then(() => false)
33-
.catch(error => error)
34-
.then(resolved => t.error(resolved, 'should not resolve to rejected Promise'));
35+
.catch((error) => error)
36+
.then((resolved) => t.error(resolved, 'should not resolve to rejected Promise'));
3537
});
3638
});

0 commit comments

Comments
 (0)