Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
225 lines (218 loc) · 7.18 KB
/
Copy patheslint.config.js
File metadata and controls
225 lines (218 loc) · 7.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import globals from 'globals';
import xo from 'eslint-config-xo';
import jsdocPlugin from 'eslint-plugin-jsdoc';
import eslintPlugin from 'eslint-plugin-eslint-plugin';
import eslintPackageJson from 'eslint-package-json';
import nodeStyleTextConfig from 'node-style-text/eslint-config';
import internalRules from './scripts/internal-rules/index.js';
import eslintPluginUnicorn from './index.js';
const disabledJsdocRules = Object.fromEntries(
Object.keys(jsdocPlugin.rules).map(name => [`jsdoc/${name}`, 'off']),
);
// `eslint-config-xo` defines the `json` plugin for both package.json and generic
// JSON files; drop it from the package.json block so the package-json config owns
// the plugin in that overlapping scope.
const xoConfig = xo().map(configBlock => {
if (!(configBlock.files?.includes('**/package.json') && configBlock.plugins?.json)) {
return configBlock;
}
const {json, ...plugins} = configBlock.plugins;
return {
...configBlock,
plugins,
};
});
for (const configBlock of xoConfig) {
if (configBlock.plugins?.unicorn?.rules) {
// XO can lag local renamed rules, but inline disable comments must still validate in this repo.
configBlock.plugins.unicorn.rules['name-replacements'] = eslintPluginUnicorn.rules['name-replacements'];
// TODO: Remove when XO uses a version that ignores `node:coverage` directives.
configBlock.plugins.unicorn.rules['single-line-block-comment-style'] = eslintPluginUnicorn.rules['single-line-block-comment-style'];
}
const capitalizedComments = configBlock.rules?.['capitalized-comments'];
if (capitalizedComments) {
// TODO: Remove when `eslint-config-xo` ignores `node:coverage` directives.
const [severity, when, options] = capitalizedComments;
configBlock.rules['capitalized-comments'] = [severity, when, {...options, ignorePattern: `${options.ignorePattern}|node:coverage`}];
}
}
const config = [
...xoConfig,
eslintPackageJson.configs.recommended,
nodeStyleTextConfig,
internalRules,
{
languageOptions: {
globals: {
...globals.node,
},
},
},
{
ignores: [
'coverage',
'.ai-temporary',
'.cache-eslint-remote-tester',
'eslint-remote-tester-results',
'test/integration/{fixtures,fixtures-local}/**',
'test/fixtures/no-unnecessary-polyfills/issue-2270-node-18-range/package.json',
'test/fixtures/no-unnecessary-polyfills/issue-2270-node-22/package.json',
'test/fixtures/no-unnecessary-polyfills/package-json-sectioned-browserslist/package.json',
'**/*.ts',
],
},
{
rules: disabledJsdocRules,
},
{
files: ['**/*.js'],
rules: {
'no-sequences': ['error', {allowInParentheses: false}],
'require-unicode-regexp': 'off',
'no-shadow': 'off',
'no-unused-vars': 'off',
'no-undef': 'off',
'import-x/no-anonymous-default-export': 'off',
'node-test/no-conditional-assertion': 'off',
'n/prefer-global/process': 'off',
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2341
'unicorn/escape-case': 'off',
'unicorn/prefer-unicode-code-point-escapes': 'off',
'unicorn/expiring-todo-comments': 'off',
'unicorn/no-hex-escape': 'off',
'unicorn/no-null': 'off',
'unicorn/consistent-boolean-name': 'off',
// Recursive AST/tree walkers are intentional in rule implementation code.
'unicorn/no-useless-recursion': 'off',
// Disabled violations remain intentional in this codebase.
'unicorn/prefer-minimal-ternary': 'off',
'unicorn/prefer-simple-condition-first': 'off',
'unicorn/prefer-simplified-conditions': 'off',
// `eslint-config-xo` 4 brings in `eslint-plugin-unicorn` 76, which reports much more code with these rules. The codebase does not follow them yet.
'unicorn/prefer-ternary': 'off',
'unicorn/prefer-combined-guards': 'off',
'unicorn/prefer-early-return': 'off',
'unicorn/prefer-logical-operator-over-ternary': 'off',
'unicorn/prefer-continue': 'off',
// Many existing internal utilities intentionally export declarations separately.
'unicorn/default-export-style': 'off',
'unicorn/prefer-array-flat': ['error', {
functions: [
'flat',
'flatten',
],
}],
'unicorn/consistent-function-scoping': 'off',
'import/order': 'off',
'func-names': 'off',
'@stylistic/function-paren-newline': 'off',
'@stylistic/curly-newline': 'off',
// Some non-test rule files have names that match Node.js test file conventions.
'node-test/no-import-test-files': 'off',
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2833
'unicorn/template-indent': ['error', {indent: '\t'}],
// These `regexp/*` rules flag our own rule-implementation regexes, which run on source
// code at lint time rather than untrusted input, and rewriting them would hurt readability.
'regexp/optimal-quantifier-concatenation': 'off',
'regexp/no-super-linear-move': 'off',
'regexp/no-super-linear-backtracking': 'off',
'regexp/strict': 'off',
'regexp/no-control-character': 'off',
'regexp/prefer-named-capture-group': 'off',
// Our long-standing `eslint-disable` directives predate this rule and are self-explanatory.
'@eslint-community/eslint-comments/require-description': 'off',
},
},
{
// Shared test helpers configure `node:test` when loaded and register tests for the test files that import them.
files: ['test/utils/*.js'],
rules: {
'node-test/no-export': 'off',
'unicorn/no-top-level-side-effects': 'off',
},
},
{
files: [
'rules/no-unused-properties.js',
],
rules: {
'unicorn/name-replacements': 'error',
},
},
{
files: [
'rules/comment-content.js',
'rules/consistent-assert.js',
'rules/no-for-each.js',
'rules/no-array-reduce.js',
'rules/no-declarations-before-early-exit.js',
'rules/no-error-property-assignment.js',
'rules/no-redundant-comparison.js',
'rules/no-unnecessary-polyfills.js',
'rules/prefer-math-min-max.js',
'rules/prefer-private-class-fields.js',
'scripts/internal-rules/fix-snapshot-test.js',
'test/utils/snapshot-rule-tester.js',
],
rules: {
// Existing implementations intentionally use nested control flow in a few places.
'unicorn/no-break-in-nested-loop': 'off',
},
},
{
files: [
'test/**/*.js',
],
rules: {
// Test files contain source-code fixtures in template literals.
'unicorn/no-incorrect-template-string-interpolation': 'off',
},
},
{
// Intentional HTTP identifiers and examples.
files: [
'rules/prefer-https.js',
'test/prefer-https.js',
'test/no-url-in-search-params.js',
'test/string-content.js',
],
rules: {
'unicorn/prefer-https': 'off',
},
},
{
files: ['rules/prefer-https.js'],
rules: {
'regexp/no-super-linear-backtracking': 'error',
'regexp/no-super-linear-move': 'error',
},
},
{
files: [
'rules/*.js',
],
plugins: {
'eslint-plugin': eslintPlugin,
},
rules: {
...eslintPlugin.configs.all.rules,
'eslint-plugin/require-meta-docs-description': [
'error',
{
pattern: '.+',
},
],
'eslint-plugin/require-meta-docs-recommended': [
'error',
{
allowNonBoolean: true,
},
],
'eslint-plugin/require-meta-docs-url': 'off',
'eslint-plugin/require-meta-has-suggestions': 'off',
'eslint-plugin/require-meta-schema': 'off',
'eslint-plugin/require-meta-schema-description': 'error',
},
},
];
export default config;