'How to run eslint rules on just typescript files?

I have a codebase with lots of .js and .ts/.tsx files. I want to run some rules on the whole codebase and some rules just on typescript files.

How can I achieve this in the best possible way?

specifically I want the rule: "react/prop-types": "error", to only run on .ts files

but it only gives one option of error, so not sure how to say just .ts for this?



Solution 1:[1]

you can use an overrides option in your .eslintrc file:

{
  rules: {
    // all your general rules that apply to everyone
  },
  overrides: {
    files: ['*.ts', '*.tsx'],
    rules: {
      // rules you want for ts/tsx files
      react/prop-types: 'error',
    },
  },
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Wheale