首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我的开关-用之不竭-检查皮棉规则不起作用?

为什么我的开关-用之不竭-检查皮棉规则不起作用?
EN

Stack Overflow用户
提问于 2022-05-02 15:32:03
回答 1查看 155关注 0票数 1

下面的代码触发了一个标准的default-case lint错误,但是没有触发@typescript-eslint/switch-exhaustiveness-check。知道是什么导致的吗?其他@类型记录

代码语言:javascript
运行
复制
type Day = 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday';

const day = 'Monday' as Day;
let result = 0;

switch (day) {
  case 'Monday': {
    result = 1;
    break;
  }
}

这是我的.eslintrc.js

代码语言:javascript
运行
复制
module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: [
    'plugin:react/recommended',
    'airbnb',
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
  ],
  ignorePatterns: ['.eslintrc.js'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 'latest',
    sourceType: 'module',
    project: ['./tsconfig.json'],
  },
  plugins: ['react', '@typescript-eslint', 'react-hooks'],
  // Fix error "Unable to resolve path to module" for tsx files
  settings: {
    'import/resolver': {
      typescript: {},
    },
  },
  rules: {
    // Fix "React used before defined" error
    'no-use-before-define': 'off',
    '@typescript-eslint/no-use-before-define': ['error'],

    // Allow jsx
    'react/jsx-filename-extension': ['warn', { extensions: ['.tsx'] }],

    // Fix error "Missing file extension tsx"
    'import/extensions': [
      'error',
      'ignorePackages',
      {
        ts: 'never',
        tsx: 'never',
      },
    ],

    // Fix error "‘Enum’ is already declared in the upper scope"
    'no-shadow': 'off',
    '@typescript-eslint/no-shadow': ['error'],

    // Add rules for react hooks
    'react-hooks/rules-of-hooks': 'error',
    'react-hooks/exhaustive-deps': 'warn',

    // Use 120 character windows
    'max-len': [
      'error',
      {
        code: 120,
        ignoreUrls: true,
        ignoreStrings: true,
        ignoreTemplateLiterals: true,
        ignoreRegExpLiterals: true,
      },
    ],

    // Stop using default export
    'import/no-default-export': 'error',
    'import/prefer-default-export': 'off',

    // Since we use interfaces often in DDD and sometimes an implemented function uses this and sometimes not, it makes
    // this rule impractical.
    'class-methods-use-this': 'off',

    // Require accessibility modifiers on everything except public constructors
    '@typescript-eslint/explicit-member-accessibility': ['error', { overrides: { constructors: 'no-public' } }],

    // We use these many times in domain objects, so it makes sense to ignore them.
    '@typescript-eslint/no-empty-interface': 'off',

    // Allow test dependencies to appear in devDependencies
    'import/no-extraneous-dependencies': ['error', { devDependencies: ['**/*.test.ts', '**/*.test.tsx'] }],

    // Place default props inside class field
    'react/static-property-placement': ['error', 'static public field'],

    '@typescript-eslint/switch-exhaustiveness-check': ['error'],
  },
};
EN

回答 1

Stack Overflow用户

发布于 2022-09-07 21:10:28

实际上,error并不是穷竭性检查规则所支持的值,只有warn。下面是带有接受值的文档:https://typescript-eslint.io/rules/switch-exhaustiveness-check/

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

https://stackoverflow.com/questions/72089001

复制
相关文章

相似问题

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