Skip to content

Commit 5533225

Browse files
authored
1 parent ec4e63a commit 5533225

File tree

6 files changed

+61
-42
lines changed

6 files changed

+61
-42
lines changed

scripts/__snapshots__/rules-generator.test.ts.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ exports[`RulesGenerator > RulesGenerator generates rules correctly > byCategory
55
66
const styleRules = {
77
'rulename-with-mod': "off"
8-
}
8+
} as const
99
1010
const correctnessRules = {
1111
'@typescript-eslint/rulename-without-mod': "off"
12-
}
12+
} as const
1313
1414
export {
1515
styleRules,
@@ -22,11 +22,11 @@ exports[`RulesGenerator > RulesGenerator generates rules correctly > byScope 1`]
2222
2323
const eslintRules = {
2424
'rulename-with-mod': "off"
25-
}
25+
} as const
2626
2727
const typescriptRules = {
2828
'@typescript-eslint/rulename-without-mod': "off"
29-
}
29+
} as const
3030
3131
export {
3232
eslintRules,

scripts/rules-generator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class RulesGenerator {
7171
return ` '${rule.replace(/_/g, '-')}': "off"`;
7272
})
7373
.join(',\n');
74-
code += '\n}\n\n';
74+
code += '\n} as const\n\n';
7575
}
7676

7777
code += 'export {\n';

src/__snapshots__/rules-by-scope.spec.ts.snap

+6
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ exports[`contains all the oxlint rules 1`] = `
863863
"no-duplicate-case": [
864864
0,
865865
],
866+
"no-else-return": [
867+
0,
868+
],
866869
"no-empty": [
867870
0,
868871
],
@@ -1040,6 +1043,9 @@ exports[`contains all the oxlint rules 1`] = `
10401043
"no-this-before-super": [
10411044
0,
10421045
],
1046+
"no-throw-literal": [
1047+
0,
1048+
],
10431049
"no-trailing-spaces": [
10441050
0,
10451051
],

src/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import * as ruleMapsByScope from './rules-by-scope.js';
22
import * as ruleMapsByCategory from './rules-by-category.js';
33
import { createFlatRulesConfig } from './utils.js';
44

5-
const allRules: Record<string, string> = Object.assign(
5+
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
6+
x: infer I
7+
) => void
8+
? I
9+
: never;
10+
11+
type RulesGroups = keyof typeof ruleMapsByScope;
12+
type AllRules = (typeof ruleMapsByScope)[RulesGroups];
13+
14+
const allRules: UnionToIntersection<AllRules> = Object.assign(
615
{},
716
...Object.values(ruleMapsByScope)
817
);

src/rules-by-category.ts

+23-21
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const pedanticRules = {
3333
'unicorn/no-unreadable-iife': 'off',
3434
'unicorn/prefer-dom-node-remove': 'off',
3535
'unicorn/prefer-event-target': 'off',
36-
};
36+
} as const;
3737

3838
const nurseryRules = {
3939
'constructor-super': 'off',
@@ -47,7 +47,7 @@ const nurseryRules = {
4747
'react/require-render-return': 'off',
4848
'react/rules-of-hooks': 'off',
4949
'tree-shaking/no-side-effects-in-initialization': 'off',
50-
};
50+
} as const;
5151

5252
const restrictionRules = {
5353
'default-case': 'off',
@@ -82,7 +82,7 @@ const restrictionRules = {
8282
'unicorn/no-anonymous-default-export': 'off',
8383
'unicorn/no-array-reduce': 'off',
8484
'unicorn/no-magic-array-flat-depth': 'off',
85-
};
85+
} as const;
8686

8787
const styleRules = {
8888
'default-case-last': 'off',
@@ -132,10 +132,11 @@ const styleRules = {
132132
'unicorn/no-unreadable-array-destructuring': 'off',
133133
'unicorn/prefer-reflect-apply': 'off',
134134
'vitest/prefer-each': 'off',
135-
};
135+
} as const;
136136

137137
const conditionalFixRules = {
138138
eqeqeq: 'off',
139+
'no-else-return': 'off',
139140
'prefer-numeric-literals': 'off',
140141
'sort-imports': 'off',
141142
'use-isnan': 'off',
@@ -163,15 +164,15 @@ const conditionalFixRules = {
163164
'unicorn/prefer-query-selector': 'off',
164165
'unicorn/prefer-spread': 'off',
165166
'unicorn/require-array-join-separator': 'off',
166-
};
167+
} as const;
167168

168169
const dangerousFixRules = {
169170
'for-direction': 'off',
170-
};
171+
} as const;
171172

172173
const conditionalFixSuggestionRules = {
173174
'func-names': 'off',
174-
};
175+
} as const;
175176

176177
const pendingRules = {
177178
'no-array-constructor': 'off',
@@ -225,7 +226,7 @@ const pendingRules = {
225226
'unicorn/prefer-number-properties': 'off',
226227
'unicorn/prefer-structured-clone': 'off',
227228
'vitest/require-local-test-context-for-concurrent-snapshots': 'off',
228-
};
229+
} as const;
229230

230231
const correctnessRules = {
231232
'no-async-promise-executor': 'off',
@@ -351,19 +352,19 @@ const correctnessRules = {
351352
'unicorn/no-invalid-remove-event-listener': 'off',
352353
'unicorn/no-thenable': 'off',
353354
'vitest/no-conditional-tests': 'off',
354-
};
355+
} as const;
355356

356357
const perfRules = {
357358
'no-await-in-loop': 'off',
358359
'react-perf/jsx-no-jsx-as-prop': 'off',
359360
'react-perf/jsx-no-new-array-as-prop': 'off',
360361
'react-perf/jsx-no-new-function-as-prop': 'off',
361362
'react-perf/jsx-no-new-object-as-prop': 'off',
362-
};
363+
} as const;
363364

364365
const conditionalSuggestionFixRules = {
365366
'no-compare-neg-zero': 'off',
366-
};
367+
} as const;
367368

368369
const fixRules = {
369370
'no-debugger': 'off',
@@ -439,16 +440,16 @@ const fixRules = {
439440
'vitest/prefer-to-be-falsy': 'off',
440441
'vitest/prefer-to-be-object': 'off',
441442
'vitest/prefer-to-be-truthy': 'off',
442-
};
443+
} as const;
443444

444445
const suggestionRules = {
445446
'no-empty': 'off',
446-
};
447+
} as const;
447448

448449
const fixDangerousRules = {
449450
'no-eq-null': 'off',
450451
'no-unexpected-multiline': 'off',
451-
};
452+
} as const;
452453

453454
const suspiciousRules = {
454455
'no-extend-native': 'off',
@@ -463,16 +464,17 @@ const suspiciousRules = {
463464
'react/react-in-jsx-scope': 'off',
464465
'@typescript-eslint/no-extraneous-class': 'off',
465466
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
466-
};
467+
} as const;
468+
469+
const conditionalSuggestionRules = {
470+
'no-throw-literal': 'off',
471+
'jsx-a11y/anchor-has-content': 'off',
472+
} as const;
467473

468474
const dangerousSuggestionRules = {
469475
'no-unused-vars': 'off',
470476
'@typescript-eslint/no-unused-vars': 'off',
471-
};
472-
473-
const conditionalSuggestionRules = {
474-
'jsx-a11y/anchor-has-content': 'off',
475-
};
477+
} as const;
476478

477479
export {
478480
pedanticRules,
@@ -490,6 +492,6 @@ export {
490492
suggestionRules,
491493
fixDangerousRules,
492494
suspiciousRules,
493-
dangerousSuggestionRules,
494495
conditionalSuggestionRules,
496+
dangerousSuggestionRules,
495497
};

src/rules-by-scope.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const eslintRules = {
3838
'no-dupe-else-if': 'off',
3939
'no-dupe-keys': 'off',
4040
'no-duplicate-case': 'off',
41+
'no-else-return': 'off',
4142
'no-empty': 'off',
4243
'no-empty-character-class': 'off',
4344
'no-empty-function': 'off',
@@ -82,6 +83,7 @@ const eslintRules = {
8283
'no-template-curly-in-string': 'off',
8384
'no-ternary': 'off',
8485
'no-this-before-super': 'off',
86+
'no-throw-literal': 'off',
8587
'no-undef': 'off',
8688
'no-undefined': 'off',
8789
'no-unexpected-multiline': 'off',
@@ -112,7 +114,7 @@ const eslintRules = {
112114
'unicode-bom': 'off',
113115
'use-isnan': 'off',
114116
'valid-typeof': 'off',
115-
};
117+
} as const;
116118

117119
const typescriptRules = {
118120
'@typescript-eslint/default-param-last': 'off',
@@ -161,7 +163,7 @@ const typescriptRules = {
161163
'@typescript-eslint/prefer-namespace-keyword': 'off',
162164
'@typescript-eslint/prefer-ts-expect-error': 'off',
163165
'@typescript-eslint/triple-slash-reference': 'off',
164-
};
166+
} as const;
165167

166168
const importRules = {
167169
'import/default': 'off',
@@ -180,7 +182,7 @@ const importRules = {
180182
'import/no-self-import': 'off',
181183
'import/no-unused-modules': 'off',
182184
'import/no-webpack-loader-syntax': 'off',
183-
};
185+
} as const;
184186

185187
const jestRules = {
186188
'jest/consistent-test-it': 'off',
@@ -231,7 +233,7 @@ const jestRules = {
231233
'jest/valid-describe-callback': 'off',
232234
'jest/valid-expect': 'off',
233235
'jest/valid-title': 'off',
234-
};
236+
} as const;
235237

236238
const jsdocRules = {
237239
'jsdoc/check-access': 'off',
@@ -252,7 +254,7 @@ const jsdocRules = {
252254
'jsdoc/require-returns-description': 'off',
253255
'jsdoc/require-returns-type': 'off',
254256
'jsdoc/require-yields': 'off',
255-
};
257+
} as const;
256258

257259
const jsxA11yRules = {
258260
'jsx-a11y/alt-text': 'off',
@@ -282,7 +284,7 @@ const jsxA11yRules = {
282284
'jsx-a11y/role-supports-aria-props': 'off',
283285
'jsx-a11y/scope': 'off',
284286
'jsx-a11y/tabindex-no-positive': 'off',
285-
};
287+
} as const;
286288

287289
const nextjsRules = {
288290
'nextjs/google-font-display': 'off',
@@ -305,11 +307,11 @@ const nextjsRules = {
305307
'nextjs/no-title-in-document-head': 'off',
306308
'nextjs/no-typos': 'off',
307309
'nextjs/no-unwanted-polyfillio': 'off',
308-
};
310+
} as const;
309311

310312
const nodeRules = {
311313
'node/no-exports-assign': 'off',
312-
};
314+
} as const;
313315

314316
const promiseRules = {
315317
'promise/avoid-new': 'off',
@@ -321,7 +323,7 @@ const promiseRules = {
321323
'promise/prefer-await-to-then': 'off',
322324
'promise/spec-only': 'off',
323325
'promise/valid-params': 'off',
324-
};
326+
} as const;
325327

326328
const reactRules = {
327329
'react/button-has-type': 'off',
@@ -352,22 +354,22 @@ const reactRules = {
352354
'react/rules-of-hooks': 'off',
353355
'react/self-closing-comp': 'off',
354356
'react/void-dom-elements-no-children': 'off',
355-
};
357+
} as const;
356358

357359
const reactPerfRules = {
358360
'react-perf/jsx-no-jsx-as-prop': 'off',
359361
'react-perf/jsx-no-new-array-as-prop': 'off',
360362
'react-perf/jsx-no-new-function-as-prop': 'off',
361363
'react-perf/jsx-no-new-object-as-prop': 'off',
362-
};
364+
} as const;
363365

364366
const securityRules = {
365367
'security/api-keys': 'off',
366-
};
368+
} as const;
367369

368370
const treeShakingRules = {
369371
'tree-shaking/no-side-effects-in-initialization': 'off',
370-
};
372+
} as const;
371373

372374
const unicornRules = {
373375
'unicorn/catch-error-name': 'off',
@@ -456,7 +458,7 @@ const unicornRules = {
456458
'unicorn/switch-case-braces': 'off',
457459
'unicorn/text-encoding-identifier-case': 'off',
458460
'unicorn/throw-new-error': 'off',
459-
};
461+
} as const;
460462

461463
const vitestRules = {
462464
'vitest/no-conditional-tests': 'off',
@@ -466,7 +468,7 @@ const vitestRules = {
466468
'vitest/prefer-to-be-object': 'off',
467469
'vitest/prefer-to-be-truthy': 'off',
468470
'vitest/require-local-test-context-for-concurrent-snapshots': 'off',
469-
};
471+
} as const;
470472

471473
export {
472474
eslintRules,

0 commit comments

Comments
 (0)