Giu*_*oni 7 javascript eslint eslint-config-airbnb prettier
如何删除分号规则?
我尝试删除半规则,但没有成功。当我保存文件时,它删除了分号,并且 lint 抱怨它丢失了,当我插入它时,它再次抱怨说要删除。
我想保留分号
那是我的 .prettierrc 文件:
{
"printWidth": 100,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "es5",
"endOfLine":"auto",
"semi": true
}
Run Code Online (Sandbox Code Playgroud)
这就是我的 .eslintrc 文件
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"extends": [
"airbnb",
"plugin:prettier/recommended",
"plugin:react/recommended",
"plugin:jsx-a11y/recommended"
],
"plugins": ["prettier", "react", "react-hooks"],
"rules": {
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
],
"react-hooks/exhaustive-deps": "warn",
"react-hooks/rules-of-hooks": "error",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/jsx-indent-props": [2, 4],
"react/jsx-indent": [2, 4],
"react/jsx-one-expression-per-line": [0],
"react/prefer-stateless-function": [1],
"react/static-property-placement": [1, "property assignment"],
"react/prop-types": "off"
}
}
Run Code Online (Sandbox Code Playgroud)
在规则部分中,覆盖更漂亮的配置,如下所示:
"rules": {
"prettier/prettier": ["error", { "semi": false }],
}
Run Code Online (Sandbox Code Playgroud)
根据更漂亮的规则,这将不允许在不需要的地方使用分号。
我通过将 .eslintrc 中的 prettier 规则配置设置为:
"rules": {
"prettier/prettier": [
"error",
{
"endOfLine": "off"
}
],
Run Code Online (Sandbox Code Playgroud)
同时保留 .prettierrc:
"endOfLine": "auto"
Run Code Online (Sandbox Code Playgroud)
注意:这只是为了解决您(和我)遇到的错误,但我看到的效果是“endOfLine”规则在使用漂亮格式时有效,但在运行 eslint 时无效。
| 归档时间: |
|
| 查看次数: |
11661 次 |
| 最近记录: |