gpt4 book ai didi

javascript - Prettier 和 eslint 缩进不一起工作

转载 作者:行者123 更新时间:2023-12-01 04:28:23 30 4
gpt4 key购买 nike

我正在设置基于 vim 的 typescript 开发环境,但在缩进管理方面存在问题。

enter image description here

可能“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 }],
},
}

我的 .prettierc :
 module.exports = { 
semi: false,
trailingComma: 'all',
singleQuote: true,
printWidth: 80,
tabWidth: 2,
};

最佳答案

根据此 Kai Cataldo 对此 GitHub issue 的评论:

ESLint's indent rule and Prettier's indentation styles do not match - they're completely separate implementations and are two different approaches to solving the same problem ("how do we enforce consistent indentation in a project").



因此,当使用 prettier , 你最好禁用 eslint 的 indent规则。保证他们会发生冲突。

关于javascript - Prettier 和 eslint 缩进不一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56337176/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com