mdx-js / eslint-mdx

ESLint Parser/Plugin for MDX
https://npmjs.org/eslint-plugin-mdx
MIT License
264 stars 32 forks source link

Does it possible to lint React components in mdx files? #388

Closed dimaMachina closed 2 years ago

dimaMachina commented 2 years ago

Initial checklist

Problem

For example I have a mdx file

// example.mdx

<Example prop={"foo"}></Example>

Solution

with configured react/self-closing-comp and react/jsx-curly-brace-presence should suggest to replace it to

// example.mdx

<Example prop="foo" />
JounQin commented 2 years ago

Please provide a minimal and runnable reproduction.

dimaMachina commented 2 years ago

It's possible, at first I was confused overrides configuration.

dimaMachina commented 2 years ago

Btw you should keep the line order of errors, note that errors from mdx file come first than the error from js code block, but I expected to see first errors from line 4 and after from line 7 and not viceverca

# Hello world

\```js
<Example prop={"foo"}></Example>
\```

<Example prop={"foo"}></Example>
/Users/dimitri/Desktop/mdx-repro/test.mdx
  7:1   error  Empty components are self-closing  react/self-closing-comp
  7:15  error  Curly braces are unnecessary here  react/jsx-curly-brace-presence
  4:1   error  Empty components are self-closing  react/self-closing-comp
  4:15  error  Curly braces are unnecessary here  react/jsx-curly-brace-presence

✖ 4 problems (4 errors, 0 warnings)
  4 errors and 0 warnings potentially fixable with the `--fix` option.
JounQin commented 2 years ago

The order seems making sense, PR welcome to reorder them correctly at https://github.com/mdx-js/eslint-mdx/blob/fd18bed8374e23d64128481c9b17afefee5164ba/packages/eslint-plugin-mdx/src/processors/remark.ts#L29