Skip to content

Commit 1527754

Browse files
chore: add additional EsLint rule (#147)
1 parent 4c909bb commit 1527754

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2686
-282
lines changed

eslint.config.mjs

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,59 @@
55
*/
66

77
import js from '@eslint/js';
8+
import stylisticPlugin from '@stylistic/eslint-plugin';
9+
import {defineConfig, globalIgnores} from 'eslint/config';
10+
import importPlugin from 'eslint-plugin-import';
811
import globals from 'globals';
912
import tseslint from 'typescript-eslint';
10-
import {defineConfig, globalIgnores} from 'eslint/config';
11-
import checkLicensePlugin from './scripts/eslint_rules/check-license-plugin.js';
13+
14+
import localPlugin from './scripts/eslint_rules/local-plugin.js';
1215

1316
export default defineConfig([
1417
globalIgnores(['**/node_modules', '**/build/']),
18+
importPlugin.flatConfigs.typescript,
1519
{
16-
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
17-
plugins: {js},
20+
languageOptions: {
21+
ecmaVersion: 'latest',
22+
sourceType: 'module',
23+
24+
globals: {
25+
...globals.node,
26+
},
27+
28+
parserOptions: {
29+
projectService: {
30+
allowDefaultProject: ['.prettierrc.cjs', 'eslint.config.mjs'],
31+
},
32+
},
33+
34+
parser: tseslint.parser,
35+
},
36+
37+
plugins: {
38+
js,
39+
'@local': localPlugin,
40+
'@typescript-eslint': tseslint.plugin,
41+
'@stylistic': stylisticPlugin,
42+
},
43+
44+
settings: {
45+
'import/resolver': {
46+
typescript: true,
47+
},
48+
},
49+
1850
extends: ['js/recommended'],
1951
},
52+
tseslint.configs.recommended,
53+
tseslint.configs.stylistic,
2054
{
21-
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
22-
languageOptions: {globals: globals.node},
23-
},
24-
{plugins: {checkLicensePlugin}},
25-
{
55+
name: 'TypeScript rules',
2656
rules: {
27-
'checkLicensePlugin/check-license': 'error',
57+
'@local/check-license': 'error',
58+
59+
'no-undef': 'off',
60+
'no-unused-vars': 'off',
2861
'@typescript-eslint/no-unused-vars': [
2962
'error',
3063
{
@@ -38,7 +71,52 @@ export default defineConfig([
3871
ignoreRestArgs: true,
3972
},
4073
],
74+
// This optimizes the dependency tracking for type-only files.
75+
'@typescript-eslint/consistent-type-imports': 'error',
76+
// So type-only exports get elided.
77+
'@typescript-eslint/consistent-type-exports': 'error',
78+
// Prefer interfaces over types for shape like.
79+
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
80+
'@typescript-eslint/array-type': [
81+
'error',
82+
{
83+
default: 'array-simple',
84+
},
85+
],
86+
'@typescript-eslint/no-floating-promises': 'error',
87+
88+
'import/order': [
89+
'error',
90+
{
91+
'newlines-between': 'always',
92+
93+
alphabetize: {
94+
order: 'asc',
95+
caseInsensitive: true,
96+
},
97+
},
98+
],
99+
100+
'import/no-cycle': [
101+
'error',
102+
{
103+
maxDepth: Infinity,
104+
},
105+
],
106+
107+
'import/enforce-node-protocol-usage': ['error', 'always'],
108+
109+
'@stylistic/function-call-spacing': 'error',
110+
'@stylistic/semi': 'error',
111+
},
112+
},
113+
{
114+
name: 'Tests',
115+
files: ['**/*.test.ts'],
116+
rules: {
117+
// With the Node.js test runner, `describe` and `it` are technically
118+
// promises, but we don't need to await them.
119+
'@typescript-eslint/no-floating-promises': 'off',
41120
},
42121
},
43-
tseslint.configs.recommended,
44122
]);

0 commit comments

Comments
 (0)