Skip to content

Commit ccbd76a

Browse files
committed
refactor(eslint-config): utilise multi-target patterns for shared JSX/MDX rules
1 parent 233b96e commit ccbd76a

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

packages/eslint-config/src/react/config.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,25 @@ import * as rules from './rules/index.js';
1313

1414
export const config = [
1515
{
16-
files: ['**/*.tsx'],
17-
plugins: {
18-
formatjs,
19-
react,
20-
'react-hooks': reactHooks,
21-
},
22-
languageOptions: {
23-
parserOptions: {
24-
ecmaFeatures: { jsx: true },
25-
},
26-
globals: globals.browser,
27-
},
16+
files: ['**/*.{mdx,tsx}'],
17+
plugins: { react },
2818
rules: {
29-
...baseRules.typescript,
3019
...react.configs.flat.recommended.rules,
3120
...react.configs.flat['jsx-runtime'].rules,
3221
...rules.common,
33-
...rules.formatjs,
34-
...rules.hooks,
3522
...rules.jsx,
3623
},
37-
settings: {
38-
react: { version: 'detect' },
24+
settings: { react: { version: 'detect' } },
25+
},
26+
{ files: ['**/*.{ts,tsx}'], plugins: { formatjs }, rules: { ...baseRules.typescript, ...rules.formatjs } },
27+
{
28+
files: ['**/*.{mdx,ts,tsx}'],
29+
languageOptions: {
30+
globals: globals.browser,
31+
parserOptions: { ecmaFeatures: { jsx: true } },
3932
},
33+
plugins: { 'react-hooks': reactHooks },
34+
rules: rules.hooks,
4035
},
4136
{
4237
files: [
@@ -74,10 +69,13 @@ export const config = [
7469
},
7570
{
7671
files: ['**/*.mdx'],
77-
plugins: {
78-
mdx,
79-
},
72+
languageOptions: mdx.configs.flat.languageOptions as Linter.LanguageOptions,
73+
plugins: { mdx },
8074
processor: mdx.createRemarkProcessor({ lintCodeBlocks: true }),
81-
rules: { ...mdx.configs.flat.rules, ...mdx.configs.flatCodeBlocks.rules, ...rules.mdx },
75+
rules: { ...mdx.configs.flat.rules, ...rules.mdx },
76+
},
77+
{
78+
...mdx.configs.flatCodeBlocks,
79+
files: ['**/*.mdx/*'],
8280
},
8381
] satisfies Linter.Config[];
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { Linter } from 'eslint';
22

33
export const mdx: Linter.RulesRecord = {
4-
'react/jsx-filename-extension': 'off', // Allow .mdx files to contain JSX
5-
'react/jsx-sort-props': 'off', // Props sorting with MDX parser does not work as expected (props are sorted but values are not)
6-
'react/self-closing-comp': 'off', // MDX parser wrongly converts some non-void elements to self-closing and removes their children
4+
'react/jsx-filename-extension': [
5+
// Allow JSX in MDX files
6+
'error',
7+
{ allow: 'as-needed', extensions: ['.mdx'] },
8+
],
79
};

0 commit comments

Comments
 (0)