Edg*_*rka 23 javascript vim typescript eslint prettier
我正在设置基于 vim 的打字稿开发环境,但在缩进管理方面存在问题。
可能 'eslint' 说:重新格式化indent: Expected indentation of 2 spaces but found 4.
后prettier
。
我的.eslintrc.js
:
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
tsx: true, // Allows for the parsing of TSX ???
},
},
rules: {
indent: ['error', 2],
quotes: ['error', 'single'],
semi: ['error', 'never'],
'sort-keys': ['error', 'asc', { caseSensitive: true, natural: false }],
},
}
Run Code Online (Sandbox Code Playgroud)
我的.prettierc
:
module.exports = {
semi: false,
trailingComma: 'all',
singleQuote: true,
printWidth: 80,
tabWidth: 2,
};
Run Code Online (Sandbox Code Playgroud)
say*_*ode 14
我遇到了同样的问题。问题是你可以手动覆盖任何冲突的规则。就我而言,它是prettier/prettier
ESLint 的插件,因此可以在所需插件下添加缩进规则来解决。
"rules": {
// "indent":["error",10]
"prettier/prettier":[ //or whatever plugin that is causing the clash
"error",
{
"tabWidth":4
}
]
}
Run Code Online (Sandbox Code Playgroud)
您可以覆盖这样的特定规则,以消除任何冲突。
小智 9
关闭默认的 Visual Studio Code 解析器并仅将 eslint 解析器保留为保存状态即可修复此问题。
只需转到设置Ctrl/Cmd + ,
,选择User
(全局设置)或Workspace
(仅适用于工作存储库),然后单击右上角带有旋转箭头的纸张。这将打开 json 文件中声明的设置。通过以下设置,它应该适用于任何情况:
{
// other settings
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.organizeImports": false
},
// other settings
}
Run Code Online (Sandbox Code Playgroud)
通常,在 Visual Studio Code 窗口的底部有一个Fix on save: X
标志。这应该与此设置相关联,因此请确保保持一致。
小智 5
这应该修复它https://github.com/prettier/eslint-config-prettier
它禁用 eslint 中与 prettier 冲突的规则
归档时间: |
|
查看次数: |
24898 次 |
最近记录: |