【问题标题】:ESLint says that semicolons are missing even after adding themESLint 说即使在添加分号后也缺少分号
【发布时间】:2020-05-04 12:52:39
【问题描述】:

我的项目中有以下打字稿界面:

`

export default interface User {
    avatar: string;
    email: string;
    name: string;
}

`

用 Prettier 格式化后,ESLint 一直告诉我代码末尾缺少分号,现在格式化如下:

`

export default interface User {
    avatar: string;
    cpf: string;
    email: string;
    name: string;
};;;;;;;;;;;

`

我可以永远保持格式化和保存,它仍然会在该行的末尾添加分号

我的项目中有以下 .eslintrc

`

 module.exports = {
  env: {
    browser: true,
    es6: true
  },
  extends: [
    'plugin:react/recommended',
    'standard'
  ],
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly'
  },
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      jsx: true
    },
    ecmaVersion: 2018,
    sourceType: 'module'
  },
  plugins: [
    'react',
    '@typescript-eslint'
  ],
  rules: {
    "semi": [2, "always"]
  }
}

`

【问题讨论】:

    标签: typescript eslint


    【解决方案1】:

    我在https://github.com/typescript-eslint/typescript-eslint/issues/1695 提交了问题,他们回复说这是预期行为,因为您需要禁用semi,并改为启用@typescript-eslint/semi

    【讨论】:

    • 这解决了我的问题,只是禁用了默认的semi 规则,其值为off,并启用了@typescript-eslint/semi,其值为error
    【解决方案2】:

    我总是使用半规则作为never。见文档here

    module.exports = {
      env: {
        browser: true,
        es6: true
      },
      extends: [
        'plugin:react/recommended',
        'standard'
      ],
      globals: {
        Atomics: 'readonly',
        SharedArrayBuffer: 'readonly'
      },
      parser: '@typescript-eslint/parser',
      parserOptions: {
        ecmaFeatures: {
          jsx: true
        },
        ecmaVersion: 2018,
        sourceType: 'module'
      },
      plugins: [
        'react',
        '@typescript-eslint'
      ],
      rules: {
        "semi": [2, "never"]
      }
    }
    

    不确定一个是否比另一个更好,但在您的情况下,它应该可以解决您的问题。 我很惊讶它在always;你自己设置的?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-29
      • 2013-09-07
      • 2021-11-27
      • 2020-08-21
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 2012-04-26
      相关资源
      最近更新 更多