Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): add files entry to react flat configs to avoid applying TS rules to JSON files #29457

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/eslint-plugin/src/flat-configs/react-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import tseslint from 'typescript-eslint';
* https://github.com/facebook/create-react-app/blob/567f36c9235f1e1fd4a76dc6d1ae00be754ca047/packages/eslint-config-react-app/index.js
*/
export default tseslint.config({
// Files need to be specified or else typescript-eslint rules will be
// applied to non-TS files. For example, libs add rules to *.json
// files, and TS rules should not apply to them.
// See: https://github.com/nrwl/nx/issues/28245
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
plugins: { import: importPlugin },
languageOptions: {
globals: {
Expand Down
10 changes: 10 additions & 0 deletions packages/eslint-plugin/src/flat-configs/react-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ import tseslint from 'typescript-eslint';
*/
export default tseslint.config(
{
// Files need to be specified or else typescript-eslint rules will be
// applied to non-TS files. For example, libs add rules to *.json
// files, and TS rules should not apply to them.
// See: https://github.com/nrwl/nx/issues/28245
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
plugins: {
'react-hooks': reactHooksPlugin,
},
rules: reactHooksPlugin.configs.recommended.rules,
},
{
// Files need to be specified or else typescript-eslint rules will be
// applied to non-TS files. For example, libs add rules to *.json
// files, and TS rules should not apply to them.
// See: https://github.com/nrwl/nx/issues/28245
files: ['**/*.tsx', '**/*.jsx'],
settings: { react: { version: 'detect' } },
plugins: {
'jsx-a11y': jsxA11yPlugin,
Expand Down
5 changes: 5 additions & 0 deletions packages/eslint-plugin/src/flat-configs/react-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import tseslint from 'typescript-eslint';
* package.
*/
export default tseslint.config({
// Files need to be specified or else typescript-eslint rules will be
// applied to non-TS files. For example, libs add rules to *.json
// files, and TS rules should not apply to them.
// See: https://github.com/nrwl/nx/issues/28245
files: ['**/*.ts', '**/*.tsx'],
rules: {
// TypeScript"s `noFallthroughCasesInSwitch` option is more robust (#6906)
'default-case': 'off',
Expand Down