Eslint --fix удаляет аннотацию типа - PullRequest
0 голосов
/ 27 апреля 2020

У меня есть проект со стеком машинописи + eslint.

Проблема с правилом @typescript-eslint/typedef: При попытке использовать команду eslint --fix аннотация типа была удалена:

пример:

formCtrlName: string = '';

После команды eslint --fix я получу следующий код:

formCtrlName = '';

и ошибку:

26:3   error    expected formCtrlName to have a type annotation  @typescript-eslint/typedef

Правила для конкурса:

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    sourceType: 'module',
  },
  plugins: ['@typescript-eslint',
    'eslint-plugin-tsdoc',
    'simple-import-sort',
    'unicorn',
    'jsdoc'
  ],
  // camelcase, indent, no-array-constructor, and no-unused-vars are all
  // busted when using TypeScript at the moment. When you use this plugin, you're
  // forced to turn off the base rules from ESLint and turn on the TypeScript-friendly
  // variant that comes with @typescript-eslint/eslint-plugin.
  rules: {
    // tsdoc rules
    'tsdoc/syntax': 'error',
    'jsdoc/require-param-description': 2,
    'jsdoc/require-param-name': 2,
    'jsdoc/require-param': 2,
    'jsdoc/check-alignment': 2,
    'jsdoc/check-indentation': 2,
    'jsdoc/check-param-names': 2,
    'jsdoc/check-values': 2,
    'jsdoc/no-types': 2,
    // using a single import statement per module
    'no-duplicate-imports': ['error', { 'includeExports': true }],
    // avoid using methods on console
    'no-console': ['error', { allow: ['warn', 'error'] }],
    // camelcase interference fix.
    camelcase: 'off',
    '@typescript-eslint/camelcase': [2, { properties: 'never' }],
    // indent interference fix.
    indent: 'off',
    '@typescript-eslint/indent': ['error', 2, { SwitchCase: 1 }],
    // no-array-constructor interference fix.
    'no-array-constructor': 'off',
    '@typescript-eslint/no-array-constructor': 'error',
    // no-unused-vars interference fix.
    'no-unused-vars': 'off',
    '@typescript-eslint/no-unused-vars': 'error',
    '@typescript-eslint/no-empty-interface': 'error',
    '@typescript-eslint/explicit-function-return-type': [
      'error',
      {
        allowExpressions: true,
        allowTypedFunctionExpressions: true,
        allowHigherOrderFunctions: true,
      },
    ],
    '@typescript-eslint/no-explicit-any': ['warn', { 'ignoreRestArgs': false }],
    // note you must disable the base rule as it can report incorrect errors
    "no-magic-numbers": "off",
    // for future release
    // '@typescript-eslint/no-extra-non-null-assertion': ['warn'],
    '@typescript-eslint/no-magic-numbers': ['error', {
      'ignoreNumericLiteralTypes': true,
      'ignoreReadonlyClassProperties': true,
      'ignoreEnums': true,
      'ignoreArrayIndexes': true,
      'ignore': [0, 1, 2, 10, 100, 1000]
    }],
    '@typescript-eslint/no-unnecessary-condition': ['error'],
    // note you must disable the base rule as it can report incorrect errors
    'no-unused-expressions': 'off',
    '@typescript-eslint/no-unused-expressions': ['error'],
    '@typescript-eslint/no-use-before-define': ['error', { 'functions': true, 'classes': true }],
    '@typescript-eslint/restrict-plus-operands': 'error',
    // note you must disable the base rule as it can report incorrect errors
    'semi': 'off',
    '@typescript-eslint/semi': ['error'],
    '@typescript-eslint/strict-boolean-expressions': ['error'],
    '@typescript-eslint/type-annotation-spacing': ['error'],
    '@typescript-eslint/typedef': [
      'error',
      {
        'arrowParameter': false,
        'variableDeclaration': true,
      }
    ],
    'typescript-eslint/no-inferrable-types': 'off',
    // Enforces naming conventions for everything across a codebase
    "@typescript-eslint/naming-convention": [
      "error",
      {
        "selector": "default",
        "format": ["camelCase"]
      },

      {
        "selector": "variable",
        "format": ["camelCase", "UPPER_CASE"]
      },
      {
        "selector": "parameter",
        "format": ["camelCase"],
        "leadingUnderscore": "allow"
      },
      {
        "selector": "variable",
        "types": ["boolean"],
        "format": ["camelCase"],
        "prefix": ["is", "should", "has", "can", "did", "will"]
      },
      {
        "selector": "typeLike",
        "format": ["PascalCase"]
      }
    ],
    // disable eslint sort imports
    'sort-imports': 'off',
    'import/order': 'off',
    // checks all import declarations and verifies that all imports are first sorted by the used member syntax
    // and then alphabetically by the first member or alias name
    'simple-import-sort/sort': 'error',
    // check file names for kebabCase
    'unicorn/filename-case': ['error', { "case": "kebabCase" }],
  },
};

Как я могу это исправить? Когда я пытаюсь использовать правило @typescript-eslint/no-inferrable-types, возникает конфликт с правилом @typescript-eslint/typedef.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...