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 - 如何将JSON数据放入变量、解析、输出为HTML

typescript - 可迭代 setter/getter 的语法?

typescript - TypeORM:一对一关系不会为子表创建外键

javascript - vimscript 替换最后一次出现(用于打开相应的测试/规范文件)

javascript - 如何重新连接浏览器websocket客户端?

javascript - 将 $scope 传递给 Angularjs 中的服务

javascript - 使用一些预填充数据打印一个 Div,然后打印一个隐藏的 div

typescript - 如何在 deno 中获取 Base64 图像的宽度/高度?

以 ; 开头的行的 Vim 自定义高亮显示

vim - 当 { 和 } 位于同一行时,Vim 中出现奇怪的折叠。&*