mdx-js / eslint-mdx

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

mdx files are linted as markdown if the first processed file is not mdx #400

Closed gyanta closed 2 years ago

gyanta commented 2 years ago

Initial checklist

Affected packages and versions

1.17.0, 2.0.0-next.5

Link to runnable example

https://github.com/gyanta/mdxlint_repro

Steps to reproduce

Run eslint on the example repo and force that the first linted file is / is not an .mdx file

yarn eslint README.md src/DEMO.mdx
yarn eslint src/DEMO.mdx README.md

Expected behavior

A lint error should be reported for both eslint runs

Actual behavior

The lint error from the .mdx file is only reported if the first linted file is .mdx

I believe the culprit is here: https://github.com/mdx-js/eslint-mdx/blob/16c5934530b2f55059dcb7695707f721a693a0d6/packages/eslint-mdx/src/processor.ts#L91

The processor is initialized with or without the remark-mdx plugin depending on what the first processed file is, and then the same processor is used for both .md and .mdx files because the cache key is an empty string.

Runtime

Node v16

Package manager

yarn v1

OS

macOS

Build and bundle tools

Other (please specify in steps to reproduce)

JounQin commented 2 years ago

Nice catch, a workaround is adding a .remarkrc file for now.

@gyanta Are you willing to raise a PR for it? It should be very easy to fix.

const cacheKey = result ? `${String(isMdx)}-${result.filepath}` : String(isMdx)