|
1 | | -import { defineConfig, globalIgnores } from "eslint/config"; |
2 | | -import globals from "globals"; |
| 1 | +import { defineConfig, globalIgnores } from 'eslint/config'; |
| 2 | +import globals from 'globals'; |
3 | 3 | import eslint from '@eslint/js'; |
4 | 4 | import tseslint from 'typescript-eslint'; |
| 5 | +import stylistic from '@stylistic/eslint-plugin'; |
5 | 6 |
|
6 | 7 | export default defineConfig([ |
7 | | - globalIgnores(["**/CMakeFiles/**"]), |
| 8 | + globalIgnores(['**/CMakeFiles/**', 'build/**']), |
8 | 9 | eslint.configs.recommended, |
9 | 10 | tseslint.configs.recommended, |
| 11 | + // Formatting rules mirrored from nodejs/node's eslint.config.mjs. |
| 12 | + // nodejs/node uses the JS-only @stylistic/eslint-plugin-js; this repo has |
| 13 | + // TypeScript, so we use the unified @stylistic/eslint-plugin (same rules, |
| 14 | + // JS + TS aware). Keep this block in sync with upstream when it changes. |
| 15 | + { |
| 16 | + files: ['**/*.{js,mjs,ts}'], |
| 17 | + plugins: { '@stylistic': stylistic }, |
| 18 | + rules: { |
| 19 | + '@stylistic/arrow-parens': 'error', |
| 20 | + '@stylistic/arrow-spacing': 'error', |
| 21 | + '@stylistic/block-spacing': 'error', |
| 22 | + '@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }], |
| 23 | + '@stylistic/comma-dangle': ['error', 'always-multiline'], |
| 24 | + '@stylistic/comma-spacing': 'error', |
| 25 | + '@stylistic/comma-style': 'error', |
| 26 | + '@stylistic/computed-property-spacing': 'error', |
| 27 | + '@stylistic/dot-location': ['error', 'property'], |
| 28 | + '@stylistic/eol-last': 'error', |
| 29 | + '@stylistic/function-call-spacing': 'error', |
| 30 | + '@stylistic/indent': ['error', 2, { |
| 31 | + ArrayExpression: 'first', |
| 32 | + CallExpression: { arguments: 'first' }, |
| 33 | + FunctionDeclaration: { parameters: 'first' }, |
| 34 | + FunctionExpression: { parameters: 'first' }, |
| 35 | + MemberExpression: 'off', |
| 36 | + ObjectExpression: 'first', |
| 37 | + SwitchCase: 1, |
| 38 | + assignmentOperator: 'off', |
| 39 | + }], |
| 40 | + '@stylistic/key-spacing': 'error', |
| 41 | + '@stylistic/keyword-spacing': 'error', |
| 42 | + '@stylistic/linebreak-style': 'error', |
| 43 | + '@stylistic/max-len': ['error', { |
| 44 | + code: 120, |
| 45 | + ignorePattern: '^// Flags:', |
| 46 | + ignoreRegExpLiterals: true, |
| 47 | + ignoreTemplateLiterals: true, |
| 48 | + ignoreUrls: true, |
| 49 | + tabWidth: 2, |
| 50 | + }], |
| 51 | + '@stylistic/new-parens': 'error', |
| 52 | + '@stylistic/no-confusing-arrow': 'error', |
| 53 | + '@stylistic/no-extra-parens': ['error', 'functions'], |
| 54 | + '@stylistic/no-multi-spaces': ['error', { ignoreEOLComments: true }], |
| 55 | + '@stylistic/no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }], |
| 56 | + '@stylistic/no-tabs': 'error', |
| 57 | + '@stylistic/no-trailing-spaces': 'error', |
| 58 | + '@stylistic/no-whitespace-before-property': 'error', |
| 59 | + '@stylistic/object-curly-newline': 'error', |
| 60 | + '@stylistic/object-curly-spacing': ['error', 'always'], |
| 61 | + '@stylistic/one-var-declaration-per-line': 'error', |
| 62 | + '@stylistic/operator-linebreak': ['error', 'after'], |
| 63 | + '@stylistic/padding-line-between-statements': [ |
| 64 | + 'error', |
| 65 | + { blankLine: 'always', prev: 'function', next: 'function' }, |
| 66 | + ], |
| 67 | + '@stylistic/quotes': ['error', 'single', { avoidEscape: true, allowTemplateLiterals: 'always' }], |
| 68 | + '@stylistic/quote-props': ['error', 'consistent'], |
| 69 | + '@stylistic/rest-spread-spacing': 'error', |
| 70 | + '@stylistic/semi': 'error', |
| 71 | + '@stylistic/semi-spacing': 'error', |
| 72 | + '@stylistic/space-before-blocks': ['error', 'always'], |
| 73 | + '@stylistic/space-before-function-paren': ['error', { |
| 74 | + anonymous: 'never', |
| 75 | + named: 'never', |
| 76 | + asyncArrow: 'always', |
| 77 | + }], |
| 78 | + '@stylistic/space-in-parens': 'error', |
| 79 | + '@stylistic/space-infix-ops': 'error', |
| 80 | + '@stylistic/space-unary-ops': 'error', |
| 81 | + '@stylistic/spaced-comment': ['error', 'always', { |
| 82 | + block: { balanced: true }, |
| 83 | + exceptions: ['-'], |
| 84 | + }], |
| 85 | + '@stylistic/template-curly-spacing': 'error', |
| 86 | + }, |
| 87 | + }, |
10 | 88 | { |
11 | 89 | files: [ |
12 | | - "tests/**/*.js", |
| 90 | + 'tests/**/*.js', |
13 | 91 | ], |
14 | 92 | languageOptions: { |
15 | 93 | // Only allow ECMAScript built-ins and CTS harness globals. |
16 | 94 | // This causes no-undef to flag any runtime-specific API (setTimeout, process, Buffer, etc.). |
17 | 95 | globals: { |
18 | 96 | ...globals.es2025, |
19 | 97 | // CTS harness globals |
20 | | - assert: "readonly", |
21 | | - loadAddon: "readonly", |
22 | | - mustCall: "readonly", |
23 | | - mustNotCall: "readonly", |
24 | | - gc: "readonly", |
25 | | - gcUntil: "readonly", |
26 | | - experimentalFeatures: "readonly", |
27 | | - napiVersion: "readonly", |
28 | | - skipTest: "readonly", |
| 98 | + assert: 'readonly', |
| 99 | + loadAddon: 'readonly', |
| 100 | + mustCall: 'readonly', |
| 101 | + mustNotCall: 'readonly', |
| 102 | + gc: 'readonly', |
| 103 | + gcUntil: 'readonly', |
| 104 | + experimentalFeatures: 'readonly', |
| 105 | + onUncaughtException: 'readonly', |
| 106 | + napiVersion: 'readonly', |
| 107 | + skipTest: 'readonly', |
29 | 108 | }, |
30 | 109 | }, |
31 | 110 | rules: { |
32 | | - "no-undef": "error", |
33 | | - "no-restricted-imports": ["error", { |
34 | | - patterns: ["*"], |
| 111 | + 'no-undef': 'error', |
| 112 | + 'no-restricted-imports': ['error', { |
| 113 | + patterns: ['*'], |
35 | 114 | }], |
36 | | - "no-restricted-syntax": ["error", |
37 | | - { selector: "MemberExpression[object.name='globalThis']", message: "Avoid globalThis access in test files — use CTS harness globals instead" }, |
38 | | - { selector: "MemberExpression[object.name='global']", message: "Avoid global access in test files — use CTS harness globals instead" } |
| 115 | + 'no-restricted-syntax': [ |
| 116 | + 'error', |
| 117 | + { |
| 118 | + selector: "MemberExpression[object.name='globalThis']", |
| 119 | + message: 'Avoid globalThis access in test files — use CTS harness globals instead', |
| 120 | + }, |
| 121 | + { |
| 122 | + selector: "MemberExpression[object.name='global']", |
| 123 | + message: 'Avoid global access in test files — use CTS harness globals instead', |
| 124 | + }, |
39 | 125 | ], |
40 | 126 | }, |
41 | 127 | }, |
42 | 128 | { |
43 | 129 | files: [ |
44 | | - "implementors/**/*.{js,ts}", |
45 | | - "scripts/**/*.{js,mjs}", |
| 130 | + 'implementors/**/*.{js,ts}', |
| 131 | + 'scripts/**/*.{js,mjs}', |
46 | 132 | ], |
47 | 133 | languageOptions: { |
48 | 134 | globals: { |
|
0 commit comments