Skip to content

Commit

Permalink
fix(linter): add files entry to react flat configs to avoid applying …
Browse files Browse the repository at this point in the history
…TS rules to JSON files (#29457)

This PR fixes an issue with React libs, where TS rules are being applied
to JSON files.

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #28245

---------

Co-authored-by: Colum Ferry <cferry09@gmail.com>
(cherry picked from commit cbbe14b)
  • Loading branch information
Bullfrog1234 authored and FrozenPandaz committed Feb 6, 2025
1 parent a667e41 commit 8c05b47
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
10 changes: 10 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,16 @@ 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: [
'**/*.ts',
'**/*.cts',
'**/*.mts',
'**/*.tsx',
'**/*.js',
'**/*.cjs',
'**/*.mjs',
'**/*.jsx',
],
plugins: { import: importPlugin },
languageOptions: {
globals: {
Expand Down
20 changes: 20 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,32 @@ import tseslint from 'typescript-eslint';
*/
export default tseslint.config(
{
files: [
'**/*.ts',
'**/*.cts',
'**/*.mts',
'**/*.tsx',
'**/*.js',
'**/*.cjs',
'**/*.mjs',
'**/*.jsx',
],
plugins: {
'react-hooks': reactHooksPlugin,
},
rules: reactHooksPlugin.configs.recommended.rules,
},
{
files: [
'**/*.ts',
'**/*.cts',
'**/*.mts',
'**/*.tsx',
'**/*.js',
'**/*.cjs',
'**/*.mjs',
'**/*.jsx',
],
settings: { react: { version: 'detect' } },
plugins: {
'jsx-a11y': jsxA11yPlugin,
Expand Down
10 changes: 10 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,16 @@ import tseslint from 'typescript-eslint';
* package.
*/
export default tseslint.config({
files: [
'**/*.ts',
'**/*.cts',
'**/*.mts',
'**/*.tsx',
'**/*.js',
'**/*.cjs',
'**/*.mjs',
'**/*.jsx',
],
rules: {
// TypeScript"s `noFallthroughCasesInSwitch` option is more robust (#6906)
'default-case': 'off',
Expand Down

0 comments on commit 8c05b47

Please sign in to comment.