|
1 | 1 | import eslintJs from "@eslint/js";
|
2 |
| -import eslintPrettier from "eslint-config-prettier/flat"; |
3 |
| -import path from "node:path"; |
4 |
| -import eslintTs from "typescript-eslint"; |
5 |
| -import unusedImportsPlugin from "eslint-plugin-unused-imports"; |
| 2 | +import prettierConfig from "eslint-config-prettier/flat"; |
6 | 3 | import importPlugin from "eslint-plugin-import";
|
7 | 4 | import mochaPlugin from "eslint-plugin-mocha";
|
8 | 5 | import unicornPlugin from "eslint-plugin-unicorn";
|
9 |
| -import type { Linter } from "eslint"; |
| 6 | +import unusedImportsPlugin from "eslint-plugin-unused-imports"; |
| 7 | +import eslintTs, { type ConfigWithExtends } from "typescript-eslint"; |
10 | 8 | import cursorlessOrgConfig from "./packages/cursorless-org/eslint.config.mts";
|
11 | 9 |
|
12 |
| -export default eslintTs.config( |
13 |
| - { |
14 |
| - ignores: [ |
15 |
| - "**/generated/**/*", |
16 |
| - "**/out/**/*", |
17 |
| - "**/dist/**/*", |
18 |
| - "**/build/**/*", |
19 |
| - "**/vendor/**/*", |
20 |
| - "**/.next/**/*", |
21 |
| - "**/.docusaurus/**/*", |
22 |
| - "data/playground/**/*", |
23 |
| - ], |
| 10 | +const ignoresConfig: ConfigWithExtends = { |
| 11 | + ignores: [ |
| 12 | + "**/generated/**/*", |
| 13 | + "**/out/**/*", |
| 14 | + "**/dist/**/*", |
| 15 | + "**/build/**/*", |
| 16 | + "**/vendor/**/*", |
| 17 | + "**/.next/**/*", |
| 18 | + "**/.docusaurus/**/*", |
| 19 | + "data/playground/**/*", |
| 20 | + ], |
| 21 | +}; |
| 22 | + |
| 23 | +const rootConfig: ConfigWithExtends = { |
| 24 | + plugins: { |
| 25 | + "unused-imports": unusedImportsPlugin, |
| 26 | + import: importPlugin, |
| 27 | + unicorn: unicornPlugin, |
| 28 | + mocha: mochaPlugin, |
24 | 29 | },
|
25 |
| - eslintJs.configs.recommended, |
26 |
| - // We want to enable this in the long run. For now there are a lot of errors that needs to be handled. |
27 |
| - // eslintTs.configs.recommendedTypeChecked, |
28 |
| - eslintTs.configs.recommended, |
29 |
| - eslintPrettier, |
30 |
| - { |
31 |
| - plugins: { |
32 |
| - "unused-imports": unusedImportsPlugin, |
33 |
| - import: importPlugin, |
34 |
| - unicorn: unicornPlugin, |
35 |
| - mocha: mochaPlugin, |
36 |
| - }, |
37 | 30 |
|
38 |
| - languageOptions: { |
39 |
| - parser: eslintTs.parser, |
40 |
| - ecmaVersion: 6, |
41 |
| - sourceType: "module", |
42 |
| - parserOptions: { |
43 |
| - project: true, |
44 |
| - }, |
| 31 | + languageOptions: { |
| 32 | + parser: eslintTs.parser, |
| 33 | + ecmaVersion: 6, |
| 34 | + sourceType: "module", |
| 35 | + parserOptions: { |
| 36 | + project: true, |
45 | 37 | },
|
| 38 | + }, |
46 | 39 |
|
47 |
| - settings: { |
48 |
| - "import/resolver": { |
49 |
| - typescript: { |
50 |
| - alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist` |
51 |
| - project: ["tsconfig.json", "packages/*/tsconfig.json"], |
52 |
| - }, |
| 40 | + settings: { |
| 41 | + "import/resolver": { |
| 42 | + typescript: { |
| 43 | + // Always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist` |
| 44 | + alwaysTryTypes: true, |
| 45 | + project: ["tsconfig.json", "packages/*/tsconfig.json"], |
53 | 46 | },
|
54 | 47 | },
|
55 |
| - |
56 |
| - rules: { |
57 |
| - "import/no-relative-packages": "error", |
58 |
| - "@typescript-eslint/consistent-type-imports": "error", |
59 |
| - "@typescript-eslint/consistent-type-assertions": [ |
60 |
| - "error", |
61 |
| - { |
62 |
| - assertionStyle: "as", |
63 |
| - }, |
64 |
| - ], |
65 |
| - "@typescript-eslint/naming-convention": [ |
66 |
| - "error", |
67 |
| - { |
68 |
| - selector: ["objectLiteralProperty"], |
69 |
| - format: ["camelCase"], |
70 |
| - filter: { |
71 |
| - regex: "[.]", |
72 |
| - match: false, |
73 |
| - }, |
74 |
| - }, |
75 |
| - ], |
76 |
| - "@typescript-eslint/no-floating-promises": "error", |
77 |
| - "@typescript-eslint/no-explicit-any": "off", |
78 |
| - "@typescript-eslint/no-inferrable-types": "off", |
79 |
| - "@typescript-eslint/no-non-null-assertion": "off", |
80 |
| - "unused-imports/no-unused-imports": "error", |
81 |
| - "@typescript-eslint/no-unused-vars": [ |
82 |
| - "error", |
83 |
| - { |
84 |
| - argsIgnorePattern: "^_", |
85 |
| - varsIgnorePattern: "^_", |
86 |
| - caughtErrorsIgnorePattern: "^_", |
87 |
| - ignoreRestSiblings: true, |
88 |
| - }, |
89 |
| - ], |
90 |
| - curly: "error", |
91 |
| - eqeqeq: [ |
92 |
| - "error", |
93 |
| - "always", |
94 |
| - { |
95 |
| - null: "never", |
96 |
| - }, |
97 |
| - ], |
98 |
| - "no-constant-condition": [ |
99 |
| - "error", |
100 |
| - { |
101 |
| - checkLoops: false, |
102 |
| - }, |
103 |
| - ], |
104 |
| - "no-restricted-syntax": [ |
105 |
| - "error", |
106 |
| - "MemberExpression[object.property.name='constructor'][property.name='name']", |
107 |
| - ], |
108 |
| - "no-throw-literal": "error", |
109 |
| - semi: "off", |
110 |
| - "unicorn/prefer-module": "error", |
111 |
| - "mocha/no-pending-tests": "error", |
112 |
| - "mocha/no-exclusive-tests": "error", |
113 |
| - }, |
114 | 48 | },
|
115 |
| - { |
116 |
| - files: ["**/*.tsx"], |
117 |
| - rules: { |
118 |
| - "@typescript-eslint/naming-convention": [ |
119 |
| - "error", |
120 |
| - { |
121 |
| - selector: ["function"], |
122 |
| - format: ["PascalCase", "camelCase"], |
| 49 | + |
| 50 | + rules: { |
| 51 | + "import/no-relative-packages": "error", |
| 52 | + "@typescript-eslint/consistent-type-imports": "error", |
| 53 | + "@typescript-eslint/consistent-type-assertions": [ |
| 54 | + "error", |
| 55 | + { |
| 56 | + assertionStyle: "as", |
| 57 | + }, |
| 58 | + ], |
| 59 | + "@typescript-eslint/naming-convention": [ |
| 60 | + "error", |
| 61 | + { |
| 62 | + selector: ["objectLiteralProperty"], |
| 63 | + format: ["camelCase"], |
| 64 | + filter: { |
| 65 | + regex: "[.]", |
| 66 | + match: false, |
123 | 67 | },
|
124 |
| - ], |
125 |
| - }, |
126 |
| - }, |
127 |
| - { |
128 |
| - files: [ |
129 |
| - "**/jest.config.ts", |
130 |
| - "**/docusaurus.config.mts", |
131 |
| - "**/mdx-components.tsx", |
132 |
| - "**/scripts/**", |
133 |
| - "**/resources/**", |
134 |
| - "typings/**", |
135 |
| - "**/*.js", |
136 |
| - "**/*.mjs", |
137 |
| - "eslint.config.mts", |
| 68 | + }, |
| 69 | + ], |
| 70 | + "@typescript-eslint/no-floating-promises": "error", |
| 71 | + "@typescript-eslint/no-explicit-any": "off", |
| 72 | + "@typescript-eslint/no-inferrable-types": "off", |
| 73 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 74 | + "unused-imports/no-unused-imports": "error", |
| 75 | + "@typescript-eslint/no-unused-vars": [ |
| 76 | + "error", |
| 77 | + { |
| 78 | + argsIgnorePattern: "^_", |
| 79 | + varsIgnorePattern: "^_", |
| 80 | + caughtErrorsIgnorePattern: "^_", |
| 81 | + ignoreRestSiblings: true, |
| 82 | + }, |
| 83 | + ], |
| 84 | + curly: "error", |
| 85 | + eqeqeq: [ |
| 86 | + "error", |
| 87 | + "always", |
| 88 | + { |
| 89 | + null: "never", |
| 90 | + }, |
| 91 | + ], |
| 92 | + "no-constant-condition": [ |
| 93 | + "error", |
| 94 | + { |
| 95 | + checkLoops: false, |
| 96 | + }, |
| 97 | + ], |
| 98 | + "no-restricted-syntax": [ |
| 99 | + "error", |
| 100 | + "MemberExpression[object.property.name='constructor'][property.name='name']", |
138 | 101 | ],
|
| 102 | + "no-throw-literal": "error", |
| 103 | + semi: "off", |
| 104 | + "unicorn/prefer-module": "error", |
| 105 | + "mocha/no-pending-tests": "error", |
| 106 | + "mocha/no-exclusive-tests": "error", |
| 107 | + }, |
| 108 | +}; |
139 | 109 |
|
140 |
| - extends: [eslintTs.configs.disableTypeChecked], |
| 110 | +const tsxConfig: ConfigWithExtends = { |
| 111 | + files: ["**/*.tsx"], |
| 112 | + rules: { |
| 113 | + "@typescript-eslint/naming-convention": [ |
| 114 | + "error", |
| 115 | + { |
| 116 | + selector: ["function"], |
| 117 | + format: ["PascalCase", "camelCase"], |
| 118 | + }, |
| 119 | + ], |
141 | 120 | },
|
| 121 | +}; |
| 122 | + |
| 123 | +const disabledTypeCheckConfig: ConfigWithExtends = { |
| 124 | + files: [ |
| 125 | + "**/jest.config.ts", |
| 126 | + "**/docusaurus.config.mts", |
| 127 | + "**/mdx-components.tsx", |
| 128 | + "**/scripts/**", |
| 129 | + "**/resources/**", |
| 130 | + "typings/**", |
| 131 | + "**/*.js", |
| 132 | + "**/*.mjs", |
| 133 | + "eslint.config.mts", |
| 134 | + ], |
| 135 | + |
| 136 | + extends: [eslintTs.configs.disableTypeChecked], |
| 137 | +}; |
| 138 | + |
| 139 | +export default eslintTs.config( |
| 140 | + ignoresConfig, |
| 141 | + eslintJs.configs.recommended, |
| 142 | + // We want to enable this in the long run. For now there are a lot of errors that needs to be handled. |
| 143 | + // eslintTs.configs.recommendedTypeChecked, |
| 144 | + eslintTs.configs.recommended, |
| 145 | + prettierConfig, |
| 146 | + rootConfig, |
| 147 | + tsxConfig, |
| 148 | + disabledTypeCheckConfig, |
142 | 149 | cursorlessOrgConfig,
|
143 | 150 | );
|
0 commit comments