root = true
[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{json,yml,md}]
indent_style = space
indent_size = 2
JavaScript
JSX
Vue
TypeScript
CSS、Less、SCSS
HTML
JSON
Markdown
{
"printWidth": 80,
"trailingComma": "es5",
"tabWidth": 2,
"singleQuote": true,
"useTabs": false,
"bracketSpacing": true,
"endOfLine": "auto"
}
foo(function1(), function2(), function3());
foo(
function1(),
function2(),
function3()
);
foo('val', 'val2', 'val3');
npm install --save-dev eslint eslint-config-prettier eslint-config-standard eslint-plugin-prettier eslint-plugin-react
{
"extends": [
"standard",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": ["react", "react-hooks", "@typescript-eslint"],
"rules": {
"no-unused-vars": "warn",
"@typescript-eslint/no-use-before-define": ["error"],
"react-hooks/rules-of-hooks": "error",
}
}
npm install --save-dev stylelint stylelint-config-recommended
{
"extends": "stylelint-config-recommended",
"rules": {
"at-rule-no-unknown": [
true,
{
"ignoreAtRules": ["extends"]
}
],
}
}
npm install --save-dev husky lint-staged
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.(js|jsx|ts|tsx)": [
"eslint --fix",
"prettier --write",
"git add"
],
"src/**/*.(less|scss|css)":[
"stylelint --fix",
"prettier --write",
"git add"
]
}
EditorConfig可以针对不同平台和IDE配置代码风格。
Prettier可以对HTML、JS、TS、CSS/LESS/SCSS等进行代码格式化的自动订正。
ESLint可以对Source Code,JS、TS进行合法性的校验和自动订正,当然也可以进行格式化的操作,但会和Prettier规则发生冲突,我们可以借助插件解决两种格式化规则冲突问题。
最后欢迎大家投递雷火UX设计部面向2022届毕业生的校招岗位