forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.js
160 lines (149 loc) · 4.53 KB
/
eslint.config.js
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
// @ts-check
import eslint from "@eslint/js";
import reactHooks from "eslint-plugin-react-hooks";
import unicorn from "eslint-plugin-unicorn";
import vitest from "eslint-plugin-vitest";
import tsEslint from "typescript-eslint";
/** Config that will apply to all files */
const allFilesConfig = tsEslint.config({
plugins: {
unicorn,
},
rules: {
/**
* Typescript plugin overrides
*/
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
varsIgnorePattern: "^_",
argsIgnorePattern: ".*",
ignoreRestSiblings: true,
caughtErrorsIgnorePattern: ".*",
},
],
// This rule is bugged https://github.com/typescript-eslint/typescript-eslint/issues/6538
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-unused-expressions": [
"warn",
{ allowShortCircuit: true, allowTernary: true },
],
/**
* Unicorn
*/
"unicorn/filename-case": ["error", { case: "kebabCase" }],
/**
* Core
*/
"no-inner-declarations": "off",
"no-empty": "off",
"no-constant-condition": "off",
"no-case-declarations": "off",
"no-ex-assign": "off",
"no-undef": "off",
"prefer-const": [
"warn",
{
destructuring: "all",
},
],
eqeqeq: ["warn", "always", { null: "ignore" }],
// Do not want console.log left from debugging or using console.log for logging. Use the program logger.
"no-console": "warn",
// Symbols should have a description so it can be serialized.
"symbol-description": "warn",
},
});
/** Config that will apply to all typescript files only
* @param {string} root
*/
export function getTypeScriptProjectRules(root) {
return tsEslint.config({
files: ["**/packages/*/src/**/*.ts", "**/packages/*/src/**/*.tsx"],
ignores: [
"**/packages/http-client-csharp/**/*",
"**/packages/http-client-java/**/*",
"**/packages/http-client-python/**/*",
], // Ignore isolated modules
plugins: {},
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ["packages/*/vitest.config.ts"],
},
tsconfigRootDir: root,
},
},
rules: {
// Only put rules here that need typescript project information
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-deprecated": "warn",
},
});
}
/** Config that will apply to all test files only */
const testFilesConfig = tsEslint.config({
/**
* Test files specific rules
*/
files: ["**/*.test.ts"],
plugins: { vitest },
rules: {
"vitest/no-focused-tests": "warn",
"vitest/no-identical-title": "error",
"vitest/no-commented-out-tests": "warn",
"vitest/no-import-node-test": "warn",
"vitest/require-local-test-context-for-concurrent-snapshots": "warn",
"vitest/valid-describe-callback": "warn",
"vitest/valid-expect": "warn",
"vitest/consistent-test-it": ["warn", { fn: "it" }],
"vitest/no-done-callback": ["warn"],
"vitest/no-duplicate-hooks": ["warn"],
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
},
});
const jsxFilesConfig = tsEslint.config({
files: ["**/*.tsx"],
plugins: { "react-hooks": reactHooks },
rules: {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
},
});
export const TypeSpecCommonEslintConfigs = [
eslint.configs.recommended,
...tsEslint.configs.recommended,
...allFilesConfig,
...jsxFilesConfig,
...testFilesConfig,
];
export default tsEslint.config(
{
ignores: [
"**/dist/**/*",
"**/.temp/**/*",
"**/temp/**/*",
"**/generated-defs/*",
"**/website/build/**/*",
"**/.astro/**/*",
"**/.docusaurus/**/*",
"website/src/assets/**/*",
"packages/compiler/templates/**/*", // Ignore the templates which might have invalid code and not follow exactly our rules.
"**/venv/**/*", // Ignore python virtual env
"**/.vscode-test-web/**/*", // Ignore VSCode test web project
// TODO: enable
"**/.scripts/**/*",
"eng/tsp-core/scripts/**/*",
"eng/common/scripts/**/*",
"packages/*/scripts/**/*",
],
},
...TypeSpecCommonEslintConfigs,
...getTypeScriptProjectRules(import.meta.dirname),
);