AlloyTeam / eslint-config-alloy

Progressive ESLint config for your React/Vue/TypeScript projects
https://alloyteam.github.io/eslint-config-alloy/
2.65k stars 317 forks source link

typescript 是不是应该只作用于 ts、tsx 文件? #216

Closed daolou closed 2 years ago

daolou commented 2 years ago

项目中 js/ts 共存,此时一些 ts 的规则会应用到 js 文件上

xcatliu commented 2 years ago

可以根据文件名后缀使用不同的配置的,可以参考下 https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work

daolou commented 2 years ago
module.exports = {
  extends: ['alloy'],
  parserOptions: {
    // Only ESLint 6.2.0 and later support ES2020.
    ecmaVersion: 2020,
    sourceType: 'module'
  },
  rules: {
    // 自定义你的规则
    'no-param-reassign': 1,
  },
  overrides: [
    {
      files: ["src/*.ts","src/*.tsx"],
      extends: ['alloy/typescript'],
      rules: {
        '@typescript-eslint/no-require-imports': 1
      }
    }
  ]
};

这样么?我印象中 overrides 不能配置 extends 吧?

daolou commented 2 years ago

这么用好像是可以