如何禁用有关未使用的参数的警告,但保留“ no-unused-vars”

时间:2020-09-24 18:27:44

标签: eslint

我想禁用所有未使用的参数警告,但保留“未使用的变量”警告。

对于此代码:

const Query = objectType({
  name: 'Query',
  definition(t) {
    t.field('test', {
      type: 'Test',
      resolve: (root, args, ctx) => {
        const x = 1

        return { id: 1, time: new Date().toString() }
      },
    })
  },
})

我收到警告:

  26:17  warning  'root' is defined but never used        @typescript-eslint/no-unused-vars
  26:23  warning  'args' is defined but never used        @typescript-eslint/no-unused-vars
  26:29  warning  'ctx' is defined but never used         @typescript-eslint/no-unused-vars
  27:15  warning  'x' is assigned a value but never used  @typescript-eslint/no-unused-vars

eslint配置:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  parserOptions: { ecmaVersion: 2020, ecmaFeatures: { jsx: true } },
  env: {
    browser: true,
    node: true,
  },
  extends: ['plugin:react-hooks/recommended', 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react/recommended'],
  settings: {
    react: {
      version: 'detect',
    },
  },
  rules: {
    '@typescript-eslint/no-empty-function': 'off',
    'react/react-in-jsx-scope': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
    'react/prop-types': 'off',
    '@typescript-eslint/no-var-requires': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    'no-unused-vars': 'off',
    '@typescript-eslint/no-unused-vars': ['off'],
  },
  ignorePatterns: ['**/generated/*'],
}

我试图以某种方式禁用它,但是只找到了禁用所有内容的该选项:

'no-unused-vars':'off', '@ typescript-eslint / no-unused-vars':['off'],

1 个答案:

答案 0 :(得分:1)

我发现的唯一方法是对未使用的参数使用下划线。

 '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
相关问题