首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更漂亮的缩进和eslint缩进不能一起使用

问更漂亮的缩进和eslint缩进不能一起使用
EN

Stack Overflow用户
提问于 2019-05-28 15:35:45
回答 9查看 30.6K关注 0票数 32

我尝试设置基于vim的typescript开发环境,但有一个缩进管理的问题。

​

​

可能'eslint‘说的是:prettier重新格式化后的indent: Expected indentation of 2 spaces but found 4.。

我的.eslintrc.js

代码语言:javascript
复制
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:

代码语言:javascript
复制
 module.exports = { 
  semi: false,
  trailingComma: 'all',
  singleQuote: true,
  printWidth: 80, 
  tabWidth: 2,
};
EN

回答 9

Stack Overflow用户

发布于 2019-11-21 23:02:24

根据凯卡塔尔多对这个GitHub issue的评论

ESLint的缩进规则和Prettier的缩进样式不匹配-它们是完全独立的实现,是解决同一问题的两种不同方法(“我们如何在项目中强制一致缩排”)。

因此,在使用prettier时,最好禁用eslint的indent规则。它们肯定会发生冲突。

票数 17
EN

Stack Overflow用户

发布于 2021-01-08 03:53:12

在eslintrc中添加indent: [2, 2, { SwitchCase: 1}]

票数 9
EN

Stack Overflow用户

发布于 2019-05-29 06:09:32

这应该可以修复它,https://github.com/prettier/eslint-config-prettier

它禁用eslint中与更漂亮的冲突的规则

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56337176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档