|
| 1 | +// @ts-check |
| 2 | +import eslint from "@eslint/js"; |
| 3 | +import unicorn from "eslint-plugin-unicorn"; |
| 4 | +import tsEslint from "typescript-eslint"; |
| 5 | + |
| 6 | +/** Config that will apply to all files */ |
| 7 | +const allFilesConfig = tsEslint.config({ |
| 8 | + plugins: { |
| 9 | + unicorn, |
| 10 | + }, |
| 11 | + rules: { |
| 12 | + /** |
| 13 | + * Typescript plugin overrides |
| 14 | + */ |
| 15 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 16 | + "@typescript-eslint/no-explicit-any": "off", |
| 17 | + "@typescript-eslint/no-inferrable-types": "off", |
| 18 | + "@typescript-eslint/no-empty-function": "off", |
| 19 | + "@typescript-eslint/no-empty-interface": "off", |
| 20 | + "@typescript-eslint/no-empty-object-type": "off", |
| 21 | + "@typescript-eslint/no-unused-vars": [ |
| 22 | + "warn", |
| 23 | + { |
| 24 | + varsIgnorePattern: "^_", |
| 25 | + argsIgnorePattern: ".*", |
| 26 | + ignoreRestSiblings: true, |
| 27 | + caughtErrorsIgnorePattern: ".*", |
| 28 | + }, |
| 29 | + ], |
| 30 | + |
| 31 | + // This rule is bugged https://github.com/typescript-eslint/typescript-eslint/issues/6538 |
| 32 | + "@typescript-eslint/no-misused-promises": "off", |
| 33 | + "@typescript-eslint/no-unused-expressions": [ |
| 34 | + "warn", |
| 35 | + { allowShortCircuit: true, allowTernary: true }, |
| 36 | + ], |
| 37 | + |
| 38 | + /** |
| 39 | + * Unicorn |
| 40 | + */ |
| 41 | + "unicorn/filename-case": ["error", { case: "kebabCase" }], |
| 42 | + |
| 43 | + /** |
| 44 | + * Core |
| 45 | + */ |
| 46 | + "no-inner-declarations": "off", |
| 47 | + "no-empty": "off", |
| 48 | + "no-constant-condition": "off", |
| 49 | + "no-case-declarations": "off", |
| 50 | + "no-ex-assign": "off", |
| 51 | + "no-undef": "off", |
| 52 | + "prefer-const": [ |
| 53 | + "warn", |
| 54 | + { |
| 55 | + destructuring: "all", |
| 56 | + }, |
| 57 | + ], |
| 58 | + eqeqeq: ["warn", "always", { null: "ignore" }], |
| 59 | + |
| 60 | + // Do not want console.log left from debugging or using console.log for logging. Use the program logger. |
| 61 | + "no-console": "warn", |
| 62 | + |
| 63 | + // Symbols should have a description so it can be serialized. |
| 64 | + "symbol-description": "warn", |
| 65 | + }, |
| 66 | +}); |
| 67 | + |
| 68 | +/** Config that will apply to all typescript files only |
| 69 | + * @param {string} root |
| 70 | + */ |
| 71 | +export function getTypeScriptProjectRules(root) { |
| 72 | + return tsEslint.config({ |
| 73 | + files: [ |
| 74 | + "**/src/**/*.ts", |
| 75 | + ], |
| 76 | + plugins: {}, |
| 77 | + languageOptions: { |
| 78 | + parserOptions: { |
| 79 | + projectService: { |
| 80 | + allowDefaultProject: ["vitest.config.ts"], |
| 81 | + }, |
| 82 | + tsconfigRootDir: root, |
| 83 | + }, |
| 84 | + }, |
| 85 | + rules: { |
| 86 | + // Only put rules here that need typescript project information |
| 87 | + "@typescript-eslint/no-floating-promises": "error", |
| 88 | + "@typescript-eslint/no-deprecated": "warn", |
| 89 | + }, |
| 90 | + }); |
| 91 | +} |
| 92 | + |
| 93 | +export const TypeSpecCommonEslintConfigs = [ |
| 94 | + eslint.configs.recommended, |
| 95 | + ...tsEslint.configs.recommended, |
| 96 | + ...allFilesConfig, |
| 97 | +]; |
| 98 | + |
| 99 | +export default tsEslint.config( |
| 100 | + { |
| 101 | + ignores: [ |
| 102 | + "**/dist/**/*", |
| 103 | + "**/temp/**/*", |
| 104 | + "generator/**/*", |
| 105 | + ], |
| 106 | + }, |
| 107 | + ...TypeSpecCommonEslintConfigs, |
| 108 | + ...getTypeScriptProjectRules(import.meta.dirname), |
| 109 | +); |
0 commit comments