Last active
July 3, 2024 08:36
-
-
Save aolyang/8ad9c14209b069806eac45b5927d00de to your computer and use it in GitHub Desktop.
config vue3 eslint use "eslint9.x flat config" feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { builtinModules } from "module" | |
import { fixupConfigRules } from "@eslint/compat" | |
import jsLint from "@eslint/js" | |
import stylistic from "@stylistic/eslint-plugin" | |
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js" | |
import pluginSimpleImportSort from "eslint-plugin-simple-import-sort" | |
import vueLint from "eslint-plugin-vue" | |
import globals from "globals" | |
import tsLint from "typescript-eslint" | |
export default [ | |
// config parsers | |
{ | |
files: ["**/*.{js,mjs,cjs,ts,mts,jsx,tsx}"] | |
}, | |
{ | |
files: ["*.vue", "**/*.vue"], | |
languageOptions: { | |
parserOptions: { | |
parser: "@typescript-eslint/parser", | |
sourceType: "module" | |
} | |
} | |
}, | |
// config envs | |
{ | |
languageOptions: { | |
globals: { ...globals.browser, ...globals.node } | |
} | |
}, | |
// rules | |
jsLint.configs.recommended, | |
...tsLint.configs.recommended, | |
...vueLint.configs["flat/essential"], | |
...fixupConfigRules(pluginReactConfig), | |
{ | |
rules: { | |
"react/react-in-jsx-scope": "off", | |
"@typescript-eslint/consistent-type-imports": [ | |
"error", | |
{ | |
prefer: "type-imports", | |
fixStyle: "separate-type-imports" | |
} | |
] | |
} | |
}, | |
{ | |
plugins: { | |
"simple-import-sort": pluginSimpleImportSort | |
}, | |
rules: { | |
"simple-import-sort/imports": [ | |
"error", | |
{ | |
groups: [ | |
[ | |
`node:`, | |
`^(${builtinModules.join("|")})(/|$)` | |
], | |
// style less,scss,css | |
["^.+\\.less$", "^.+\\.s?css$"], | |
// Side effect imports. | |
["^\\u0000"], | |
["^@?\\w.*\\u0000$", "^[^.].*\\u0000$", "^\\..*\\u0000$"], | |
["^vue", "^@vue", "^@?\\w", "^\\u0000"], | |
["^@/utils"], | |
["^@/composables"], | |
// Parent imports. Put `..` last. | |
["^\\.\\.(?!/?$)", "^\\.\\./?$"], | |
// Other relative imports. Put same-folder imports and `.` last. | |
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"] | |
] | |
} | |
] | |
} | |
}, | |
// see: https://eslint.style/guide/getting-started | |
// see: https://github.com/eslint-stylistic/eslint-stylistic/blob/main/packages/eslint-plugin/configs/disable-legacy.ts | |
stylistic.configs["disable-legacy"], | |
stylistic.configs.customize({ | |
indent: 4, | |
quotes: "double", | |
semi: false, | |
commaDangle: "never", | |
jsx: true | |
}) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment