|
| 1 | +import { globalIgnores } from "eslint/config"; |
| 2 | +import { |
| 3 | + defineConfigWithVueTs, |
| 4 | + vueTsConfigs, |
| 5 | +} from "@vue/eslint-config-typescript"; |
| 6 | +import pluginVue from "eslint-plugin-vue"; |
| 7 | +import pluginVitest from "@vitest/eslint-plugin"; |
| 8 | +import skipFormatting from "@vue/eslint-config-prettier/skip-formatting"; |
| 9 | +import importPlugin from "eslint-plugin-import"; |
| 10 | +import tselint from "typescript-eslint"; |
| 11 | +import vueParser from "vue-eslint-parser"; |
| 12 | +import { fileURLToPath } from "url"; |
| 13 | +import path from "path"; |
| 14 | + |
| 15 | +const __filename = fileURLToPath(import.meta.url); |
| 16 | +const __dirname = path.dirname(__filename); |
| 17 | + |
| 18 | +// To allow more languages other than `ts` in `.vue` files, uncomment the following lines: |
| 19 | +// import { configureVueProject } from '@vue/eslint-config-typescript' |
| 20 | +// configureVueProject({ scriptLangs: ['ts', 'tsx'] }) |
| 21 | +// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup |
| 22 | + |
| 23 | +export default defineConfigWithVueTs( |
| 24 | + { |
| 25 | + name: "app/files-to-lint", |
| 26 | + files: ["**/*.{vue,ts,mts,tsx}"], |
| 27 | + }, |
| 28 | + |
| 29 | + globalIgnores([ |
| 30 | + "**/dist/**", |
| 31 | + "**/dist-ssr/**", |
| 32 | + "**/coverage/**", |
| 33 | + "eslint.config.ts", |
| 34 | + ]), |
| 35 | + |
| 36 | + ...pluginVue.configs["flat/essential"], |
| 37 | + vueTsConfigs.recommended, |
| 38 | + importPlugin.flatConfigs["recommended"], |
| 39 | + tselint.configs["recommendedTypeChecked"], |
| 40 | + { |
| 41 | + languageOptions: { |
| 42 | + parser: vueParser, |
| 43 | + parserOptions: { |
| 44 | + parser: "@typescript-eslint/parser", |
| 45 | + // project: [`${__dirname}/tsconfig.json`], |
| 46 | + tsconfigRootDir: __dirname, |
| 47 | + // project: [`./tsconfig.json`, `./tsconfig.node.json`], |
| 48 | + // parserOptions: { |
| 49 | + // ecmaVersion: "latest", |
| 50 | + // sourceType: "module", |
| 51 | + // // project: ["./tsconfig.json", "./tsconfig.node.json"], |
| 52 | + // // TODO: figure our correct settings here |
| 53 | + // // project: [`${__dirname}/tsconfig.json`], |
| 54 | + // }, |
| 55 | + }, |
| 56 | + }, |
| 57 | + }, |
| 58 | + |
| 59 | + { |
| 60 | + ...pluginVitest.configs.recommended, |
| 61 | + files: ["src/**/__tests__/*"], |
| 62 | + }, |
| 63 | + |
| 64 | + skipFormatting, |
| 65 | + |
| 66 | + { |
| 67 | + settings: { |
| 68 | + "import/resolver": { |
| 69 | + node: { |
| 70 | + extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"], |
| 71 | + }, |
| 72 | + typescript: { |
| 73 | + // Optional: Specify the path to your tsconfig.json if it's not in the root |
| 74 | + project: "./tsconfig.json", |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + |
| 80 | + { |
| 81 | + rules: { |
| 82 | + // dont want this |
| 83 | + "@typescript-eslint/consistent-type-imports": 0, |
| 84 | + "import/named": 0, |
| 85 | + |
| 86 | + // warning on this because we have some shenanigans where it is a promise but a literal `await` is not present |
| 87 | + "@typescript-eslint/require-await": "warn", |
| 88 | + |
| 89 | + // "prettier/prettier": "warn", |
| 90 | + "@typescript-eslint/quotes": 0, |
| 91 | + |
| 92 | + // this is currently breaking, so turning it off |
| 93 | + "@typescript-eslint/unbound-method": 0, |
| 94 | + |
| 95 | + // some strict rules from TS / airbnb presets to relax ----------- |
| 96 | + camelcase: "off", |
| 97 | + // "@typescript-eslint/ban-ts-comment": "off", |
| 98 | + // "import/prefer-default-export": 0, |
| 99 | + "no-plusplus": 0, |
| 100 | + radix: 0, |
| 101 | + "prefer-destructuring": 0, |
| 102 | + "no-else-return": 0, // sometimes clearer even though unnecessary |
| 103 | + "prefer-arrow-callback": 0, |
| 104 | + "arrow-body-style": 0, |
| 105 | + "@typescript-eslint/lines-between-class-members": 0, // often nice to group related one-liners |
| 106 | + "max-classes-per-file": 0, // can make sense to colocate small classes |
| 107 | + "consistent-return": 0, // often can make sense to return (undefined) early |
| 108 | + "no-useless-return": 0, // sometimes helps clarify you are bailing early |
| 109 | + "no-continue": 0, |
| 110 | + "no-underscore-dangle": 0, |
| 111 | + "no-await-in-loop": 0, |
| 112 | + "no-lonely-if": 0, |
| 113 | + "@typescript-eslint/no-unused-vars": [ |
| 114 | + "warn", |
| 115 | + { |
| 116 | + argsIgnorePattern: "^_|^(response)$", |
| 117 | + varsIgnorePattern: "^_|^(props|emit)$", |
| 118 | + }, |
| 119 | + ], |
| 120 | + "@typescript-eslint/return-await": 0, |
| 121 | + |
| 122 | + // other ----------------------------------------------------- |
| 123 | + "no-undef": 0, // handled by typescript, which is better aware of global types |
| 124 | + // curly: ["error", "multi-line"], |
| 125 | + // "brace-style": "error", |
| 126 | + "max-len": [ |
| 127 | + "warn", // just a warning since prettier will enforce |
| 128 | + 120, |
| 129 | + 2, |
| 130 | + { |
| 131 | + // bumped to 120, otherwise same as airbnb's rule but ignoring comments |
| 132 | + ignoreUrls: true, |
| 133 | + ignoreComments: true, |
| 134 | + ignoreRegExpLiterals: true, |
| 135 | + ignoreStrings: true, |
| 136 | + ignoreTemplateLiterals: true, |
| 137 | + }, |
| 138 | + ], |
| 139 | + "max-statements-per-line": ["error", { max: 1 }], |
| 140 | + // "@typescript-eslint/no-floating-promises": "error", |
| 141 | + |
| 142 | + // custom plugin configs ------------------------------------------ |
| 143 | + // make import/order understand our alias paths |
| 144 | + // "import/order": [ |
| 145 | + // "warn", |
| 146 | + // { |
| 147 | + // pathGroups: [ |
| 148 | + // { |
| 149 | + // pattern: "@/**", |
| 150 | + // group: "internal", |
| 151 | + // position: "after", |
| 152 | + // }, |
| 153 | + // ], |
| 154 | + // pathGroupsExcludedImportTypes: ["internal", "external", "builtins"], |
| 155 | + // groups: [ |
| 156 | + // "builtin", |
| 157 | + // "external", |
| 158 | + // "unknown", |
| 159 | + // "internal", |
| 160 | + // ["sibling", "parent"], |
| 161 | + // "index", |
| 162 | + // "object", |
| 163 | + // "type", |
| 164 | + // ], |
| 165 | + // }, |
| 166 | + // ], |
| 167 | + |
| 168 | + // rules to disable for now, but will likely be turned back on -------- |
| 169 | + // TODO: review these rules, infractions case by case, probably turn back on? |
| 170 | + "@typescript-eslint/no-use-before-define": 0, |
| 171 | + // "import/no-cycle": 0, |
| 172 | + "no-param-reassign": 0, |
| 173 | + "no-restricted-syntax": 0, |
| 174 | + "@typescript-eslint/naming-convention": 0, |
| 175 | + "@typescript-eslint/no-shadow": 0, |
| 176 | + "guard-for-in": 0, |
| 177 | + |
| 178 | + // some rules to downgrade to warning while developing -------------------- |
| 179 | + // useful so things dont crash when code is temporarily commented out |
| 180 | + "no-console": "warn", |
| 181 | + "@typescript-eslint/no-empty-function": "warn", |
| 182 | + "no-debugger": "warn", |
| 183 | + "no-alert": "warn", |
| 184 | + "no-empty": "warn", |
| 185 | + |
| 186 | + // good to warn people |
| 187 | + "@typescript-eslint/no-base-to-string": "warn", |
| 188 | + "@typescript-eslint/restrict-template-expressions": "warn", |
| 189 | + // dont want to error here because we often have async funcs used with other lib calls that dont await, but they do not have to await! |
| 190 | + "@typescript-eslint/no-misused-promises": "warn", |
| 191 | + |
| 192 | + // turning this off, b/c our instances are actually for meaning & clarity |
| 193 | + "@typescript-eslint/no-redundant-type-constituents": 0, |
| 194 | + |
| 195 | + // rules that we want to warn, but disable agressive auto-fixing ----------- |
| 196 | + "prefer-const": 0, |
| 197 | + "no-unreachable": 0, // handy when you return early or throw an error while debugging |
| 198 | + // unreachable code will be removed by default, so we disable autofix, but leave a warning |
| 199 | + // "no-autofix/no-unreachable": 1, |
| 200 | + // useful while debugging and commenting things out, otherwise gets automatically changed from let to const |
| 201 | + // "no-autofix/prefer-const": "warn", |
| 202 | + |
| 203 | + "vue/block-order": [ |
| 204 | + "error", |
| 205 | + { |
| 206 | + order: [ |
| 207 | + "template", |
| 208 | + "script[setup]", |
| 209 | + "script:not([setup])", // necessary for default exports to not get hoisted below imports in setup block |
| 210 | + "style:not([scoped])", |
| 211 | + "style[scoped]", |
| 212 | + ], |
| 213 | + }, |
| 214 | + ], |
| 215 | + "vue/no-undef-components": [ |
| 216 | + "error", |
| 217 | + { |
| 218 | + ignorePatterns: [ |
| 219 | + "v-.*", // vue-konva requires global registration :( will hopefully fix soon! |
| 220 | + "router-(view|link)", // vue router is fairly standard to use via global registration |
| 221 | + ], |
| 222 | + }, |
| 223 | + ], |
| 224 | + "vue/multi-word-component-names": "off", |
| 225 | + "vue/require-default-prop": "off", |
| 226 | + "vue/padding-line-between-blocks": "error", |
| 227 | + "vue/prefer-true-attribute-shorthand": "error", |
| 228 | + "vue/eqeqeq": "error", |
| 229 | + "vue/no-multiple-template-root": "error", |
| 230 | + |
| 231 | + "vue/attribute-hyphenation": ["error", "never", { ignore: [] }], |
| 232 | + "vue/v-on-event-hyphenation": "off", |
| 233 | + |
| 234 | + "@typescript-eslint/ban-ts-comment": 0, |
| 235 | + // skipping for now, but should re-enable |
| 236 | + "@typescript-eslint/no-floating-promises": 0, |
| 237 | + }, |
| 238 | + }, |
| 239 | +); |
0 commit comments