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

标签 javascript typescript vim eslint prettier

我正在设置基于 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/

相关文章:

JavaScript 过滤数组和映射

javascript - 如果我使用 JQuery $.each() 迭代对象属性,是否有索引?

javascript - 如何使用 JQuery 在我的导航栏中点击滑动条

javascript - 在响应式触摸设备中,复选框和单选按钮可从外部区域单击,如何解决这个问题?

angular - 在 Angular 2 中使用 @Inject 时无法扩展父类(super class)

javascript - Angular2 - 如何从 typescript 获取变量到我的 html dom

typescript - 在 Jest 测试期间无法从 '../build/Release/magic' 找到模块 'index.js'

vim - 在 vim 中更改 # 后 n/N 的行为?

bash - egrep 结果到 vim 作为行引用的文件列表

c++ - Vim 中的自动补全