|
| 1 | +import { includeIgnoreFile } from "@eslint/compat"; |
| 2 | +import eslint from "@eslint/js"; |
| 3 | +import type { Linter } from "eslint"; |
| 4 | +import eslintPluginVue from "eslint-plugin-vue"; |
| 5 | +import { resolve } from "node:path"; |
| 6 | +import tseslint from "typescript-eslint"; |
| 7 | +import eslintParserVue from "vue-eslint-parser"; |
| 8 | + |
| 9 | +const gitignorePath = resolve(import.meta.dirname, ".gitignore"); |
| 10 | + |
| 11 | +const eslintRules: Linter.RulesRecord = { |
| 12 | + "arrow-body-style": ["error", "as-needed"], |
| 13 | + curly: "error", |
| 14 | + eqeqeq: ["error", "always", { null: "ignore" }], |
| 15 | + "no-else-return": "error", |
| 16 | +}; |
| 17 | + |
| 18 | +const tsRules: Linter.RulesRecord = { |
| 19 | + // https://typescript-eslint.io/rules/no-unused-vars/#how-to-use |
| 20 | + "no-unused-vars": "off", |
| 21 | + "@typescript-eslint/no-unused-vars": [ |
| 22 | + "error", |
| 23 | + { |
| 24 | + args: "all", |
| 25 | + argsIgnorePattern: "^_", |
| 26 | + caughtErrors: "all", |
| 27 | + caughtErrorsIgnorePattern: "^_", |
| 28 | + destructuredArrayIgnorePattern: "^_", |
| 29 | + varsIgnorePattern: "^_", |
| 30 | + ignoreRestSiblings: true, |
| 31 | + }, |
| 32 | + ], |
| 33 | + |
| 34 | + // Opinionated configuration |
| 35 | + "@typescript-eslint/array-type": [ |
| 36 | + "error", |
| 37 | + { default: "array-simple", readonly: "generic" }, |
| 38 | + ], |
| 39 | + "@typescript-eslint/consistent-type-exports": "error", |
| 40 | + "@typescript-eslint/consistent-type-imports": [ |
| 41 | + "error", |
| 42 | + { |
| 43 | + disallowTypeAnnotations: false, |
| 44 | + fixStyle: "separate-type-imports", |
| 45 | + prefer: "type-imports", |
| 46 | + }, |
| 47 | + ], |
| 48 | + "@typescript-eslint/no-inferrable-types": [ |
| 49 | + "error", |
| 50 | + { ignoreParameters: true }, |
| 51 | + ], |
| 52 | +}; |
| 53 | + |
| 54 | +const config = tseslint.config( |
| 55 | + //#region global |
| 56 | + includeIgnoreFile(gitignorePath), |
| 57 | + { |
| 58 | + name: "manual ignores", |
| 59 | + ignores: ["eslint.config.ts"], |
| 60 | + }, |
| 61 | + { |
| 62 | + name: "linter options", |
| 63 | + linterOptions: { |
| 64 | + reportUnusedDisableDirectives: "error", |
| 65 | + }, |
| 66 | + }, |
| 67 | + //#endregion |
| 68 | + |
| 69 | + //#region eslint (js) |
| 70 | + eslint.configs.recommended, |
| 71 | + { |
| 72 | + name: "eslint overrides", |
| 73 | + rules: eslintRules, |
| 74 | + }, |
| 75 | + //#endregion |
| 76 | + |
| 77 | + //#region typescript-eslint |
| 78 | + ...tseslint.configs.recommendedTypeChecked, |
| 79 | + ...tseslint.configs.stylisticTypeChecked, |
| 80 | + { |
| 81 | + name: "typescript-eslint overrides", |
| 82 | + plugins: { |
| 83 | + "@typescript-eslint": tseslint.plugin, |
| 84 | + }, |
| 85 | + languageOptions: { |
| 86 | + ecmaVersion: "latest", |
| 87 | + sourceType: "module", |
| 88 | + parserOptions: { |
| 89 | + parser: tseslint.parser, |
| 90 | + project: "./tsconfig.json", |
| 91 | + warnOnUnsupportedTypeScriptVersion: false, |
| 92 | + }, |
| 93 | + }, |
| 94 | + rules: { |
| 95 | + ...eslintRules, |
| 96 | + |
| 97 | + // TODO cquadflieg 2024-10-11: These are even double enabled by typescript-eslint |
| 98 | + "no-cond-assign": "off", |
| 99 | + "no-constant-binary-expression": "off", |
| 100 | + "no-control-regex": "off", |
| 101 | + "no-empty": "off", |
| 102 | + "no-fallthrough": "off", |
| 103 | + "no-prototype-builtins": "off", |
| 104 | + "no-unused-private-class-members": "off", |
| 105 | + "no-useless-escape": "off", |
| 106 | + |
| 107 | + // TODO cquadflieg 2024-10-30: Investigate later if these should be re-enabled (included in recommendedTypeChecked) |
| 108 | + "@typescript-eslint/await-thenable": "off", |
| 109 | + "@typescript-eslint/no-duplicate-type-constituents": "off", |
| 110 | + "@typescript-eslint/no-empty-object-type": "off", |
| 111 | + "@typescript-eslint/no-explicit-any": "off", |
| 112 | + "@typescript-eslint/no-floating-promises": "off", |
| 113 | + "@typescript-eslint/no-implied-eval": "off", |
| 114 | + "@typescript-eslint/no-misused-promises": "off", |
| 115 | + "@typescript-eslint/no-redundant-type-constituents": "off", |
| 116 | + "@typescript-eslint/no-this-alias": "off", |
| 117 | + "@typescript-eslint/no-unnecessary-type-assertion": "off", |
| 118 | + "@typescript-eslint/no-unsafe-argument": "off", |
| 119 | + "@typescript-eslint/no-unsafe-assignment": "off", |
| 120 | + "@typescript-eslint/no-unsafe-call": "off", |
| 121 | + "@typescript-eslint/no-unsafe-function-type": "off", |
| 122 | + "@typescript-eslint/no-unsafe-member-access": "off", |
| 123 | + "@typescript-eslint/no-unsafe-return": "off", |
| 124 | + "@typescript-eslint/no-unused-expressions": "off", |
| 125 | + "@typescript-eslint/no-wrapper-object-types": "off", |
| 126 | + "@typescript-eslint/only-throw-error": "off", |
| 127 | + "@typescript-eslint/prefer-promise-reject-errors": "off", |
| 128 | + "@typescript-eslint/require-await": "off", |
| 129 | + "@typescript-eslint/restrict-plus-operands": "off", |
| 130 | + "@typescript-eslint/restrict-template-expressions": "off", |
| 131 | + "@typescript-eslint/unbound-method": "off", |
| 132 | + |
| 133 | + // TODO cquadflieg 2024-10-11: Investigate later if these should be re-enabled (included in stylisticTypeChecked) |
| 134 | + "@typescript-eslint/class-literal-property-style": "off", |
| 135 | + "@typescript-eslint/dot-notation": "off", |
| 136 | + "@typescript-eslint/no-empty-function": "off", |
| 137 | + "@typescript-eslint/prefer-regexp-exec": "off", |
| 138 | + "@typescript-eslint/prefer-string-starts-ends-with": "off", |
| 139 | + |
| 140 | + ...tsRules, |
| 141 | + }, |
| 142 | + }, |
| 143 | + //#endregion |
| 144 | + |
| 145 | + //#region eslint-plugin-vue |
| 146 | + ...eslintPluginVue.configs["flat/recommended"], |
| 147 | + { |
| 148 | + name: "vue overrides", |
| 149 | + files: ["*.vue", "**/*.vue"], |
| 150 | + languageOptions: { |
| 151 | + ecmaVersion: "latest", |
| 152 | + sourceType: "module", |
| 153 | + parser: eslintParserVue, |
| 154 | + parserOptions: { |
| 155 | + parser: tseslint.parser, |
| 156 | + project: "./tsconfig.json", |
| 157 | + extraFileExtensions: [".vue"], |
| 158 | + }, |
| 159 | + }, |
| 160 | + rules: { |
| 161 | + ...eslintRules, |
| 162 | + |
| 163 | + // TODO cquadflieg 2024-10-11: Investigate later if these should be re-enabled (included in stylisticTypeChecked) |
| 164 | + "@typescript-eslint/consistent-type-definitions": "off", |
| 165 | + "@typescript-eslint/non-nullable-type-assertion-style": "off", |
| 166 | + |
| 167 | + ...tsRules, |
| 168 | + |
| 169 | + // Not needed, because it's handled by prettier |
| 170 | + "vue/html-indent": "off", |
| 171 | + "vue/max-attributes-per-line": "off", |
| 172 | + "vue/singleline-html-element-content-newline": "off", |
| 173 | + |
| 174 | + // If we use `v-html`, we know what we are doing |
| 175 | + "vue/no-v-html": "off", |
| 176 | + |
| 177 | + // TODO cquadflieg 2024-10-25: Enable in separate MR |
| 178 | + "vue/no-template-shadow": "off", |
| 179 | + "vue/require-default-prop": "off", |
| 180 | + "vue/require-prop-types": "off", |
| 181 | + |
| 182 | + // Opinionated configuration |
| 183 | + "vue/attribute-hyphenation": [ |
| 184 | + "error", |
| 185 | + "always", |
| 186 | + { |
| 187 | + ignore: ["ariaDescribedby", "innerHTML"], |
| 188 | + }, |
| 189 | + ], |
| 190 | + "vue/block-lang": [ |
| 191 | + "error", |
| 192 | + { |
| 193 | + script: { |
| 194 | + lang: "ts", |
| 195 | + }, |
| 196 | + }, |
| 197 | + ], |
| 198 | + "vue/block-order": [ |
| 199 | + "error", |
| 200 | + { |
| 201 | + order: ["script:not([setup])", "script[setup]", "template", "style"], |
| 202 | + }, |
| 203 | + ], |
| 204 | + "vue/define-macros-order": [ |
| 205 | + "error", |
| 206 | + { |
| 207 | + order: [ |
| 208 | + "defineOptions", |
| 209 | + "defineProps", |
| 210 | + "defineEmits", |
| 211 | + "defineModel", |
| 212 | + "defineSlots", |
| 213 | + ], |
| 214 | + defineExposeLast: true, |
| 215 | + }, |
| 216 | + ], |
| 217 | + "vue/html-self-closing": [ |
| 218 | + "error", |
| 219 | + { |
| 220 | + html: { |
| 221 | + component: "always", |
| 222 | + normal: "never", |
| 223 | + void: "always", |
| 224 | + }, |
| 225 | + svg: "always", |
| 226 | + math: "always", |
| 227 | + }, |
| 228 | + ], |
| 229 | + }, |
| 230 | + } |
| 231 | + //#endregion |
| 232 | +); |
| 233 | + |
| 234 | +export default config; |
0 commit comments