Eslint + prettier
关闭vscode插件
npm install -g eslint
npm init @eslint/config
npx eslint --init
检查:
Eslint 文件名
Eslint 文件名 --fix
"eslint": "^6.4.0",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-vue": "^5.2.3",
"prettier": "^1.18.2"
Vscode
printWidth: 140
tabWidth: 2
Singleqoute: true
Semicolon: check
corepack enable
corepack prepare pnpm@latest --activate
http://10.66.59.208:8080/dashboard/demo/
.editorconfig
root = true
[*]
charset = utf-8
indent_style = tab
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
.prettierrc.cjs
module.exports = {
printWidth: 140,
useTabs: true,
tabWidth: 2,
semi: true,
singleQuote: true,
jsxSingleQuote: true,
arrowParens: 'avoid',
bracketSpacing: true,
trailingComma: 'none',
endOfLine: 'lf'
};
eslint.config.mjs
import { FlatCompat } from "@eslint/eslintrc";
import path from "path";
import { fileURLToPath } from "url";
import unusedImports from "eslint-plugin-unused-imports";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname
});
const eslintConfig = [
{
ignores: ["public/**/*", "node_modules/**/*", ".next/**/*"]
},
...compat.extends("next/core-web-vitals"),
{
plugins: {
"unused-imports": unusedImports
},
rules: {
"react-refresh/only-export-components": "off",
"react/react-in-jsx-scope": "off",
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": "warn",
"no-debugger": "error",
"no-var": "warn",
"react-hooks/rules-of-hooks": "off",
"react-hooks/exhaustive-deps": "off",
"react/jsx-no-undef": "off",
"react/no-unescaped-entities": "warn",
"import/no-anonymous-default-export": [
"error",
{
allowArray: false,
allowArrowFunction: false,
allowAnonymousClass: false,
allowAnonymousFunction: false,
allowCallExpression: true,
allowNew: false,
allowLiteral: false,
allowObject: true
}
]
}
}
];
export default eslintConfig;
Plugin
Prettier - Code formatter

EditorConfig for VS Code

ESLint

npm run format && npm run lint:fix

浙公网安备 33010602011771号