forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.js
132 lines (122 loc) · 3.69 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
// @ts-check
import eslint from "@eslint/js";
import deprecation from "eslint-plugin-deprecation";
import unicorn from "eslint-plugin-unicorn";
import vitest from "eslint-plugin-vitest";
import { dirname } from "path";
import tsEslint from "typescript-eslint";
import { fileURLToPath } from "url";
/** 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-unused-vars": [
"warn",
{ varsIgnorePattern: "^_", argsIgnorePattern: ".*", ignoreRestSiblings: true },
],
// This rule is bugged https://github.com/typescript-eslint/typescript-eslint/issues/6538
"@typescript-eslint/no-misused-promises": "off",
/**
* 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: ["**/*.ts", "**/*.tsx"],
plugins: {
deprecation,
},
languageOptions: {
parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: root,
},
},
rules: {
// Only put rules here that need typescript project information
"@typescript-eslint/no-floating-promises": "error",
"deprecation/deprecation": ["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",
},
});
export const TypeSpecCommonEslintConfigs = [
eslint.configs.recommended,
...tsEslint.configs.recommended,
...allFilesConfig,
...testFilesConfig,
];
export default tsEslint.config(
{
ignores: [
"**/dist/**/*",
"**/.temp/**/*",
"**/generated-defs/*",
"**/website/build/**/*",
"**/.docusaurus/**/*",
"packages/compiler/templates/**/*", // Ignore the templates which might have invalid code and not follow exactly our rules.
// TODO: enable
"**/.scripts/**/*",
"eng/tsp-core/scripts/**/*",
"eng/common/scripts/**/*",
"packages/*/scripts/**/*",
],
},
...TypeSpecCommonEslintConfigs,
...getTypeScriptProjectRules(dirname(fileURLToPath(import.meta.url)))
);