Skip to content

Commit a45ee72

Browse files
authored
fix: pass through remarkConfigPath of parserOptions (#591)
1 parent 51f359c commit a45ee72

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

.changeset/wise-spiders-suffer.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"eslint-mdx": patch
3+
"eslint-plugin-mdx": patch
4+
---
5+
6+
fix: pass through `remarkConfigPath` of `parserOptions`

packages/eslint-mdx/src/types.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import type { JSXElement } from 'estree-jsx'
55
import type { Root } from 'mdast'
66
import type { VFileMessage } from 'vfile-message'
77

8-
export interface ParserOptions extends Linter.ParserOptions {
8+
export interface CommonOptions {
9+
ignoreRemarkConfig?: boolean
10+
remarkConfigPath?: string
11+
}
12+
13+
export interface ParserOptions extends Linter.ParserOptions, CommonOptions {
914
extensions?: string[] | string
1015
markdownExtensions?: string[] | string
1116
filePath?: string
12-
ignoreRemarkConfig?: boolean
13-
remarkConfigPath?: string
1417
}
1518

1619
export interface NormalPosition {
@@ -23,10 +26,8 @@ export interface NormalPosition {
2326
range: [number, number]
2427
}
2528

26-
export interface SyncOptions {
29+
export interface SyncOptions extends CommonOptions {
2730
cwd?: string
28-
ignoreRemarkConfig?: boolean
29-
remarkConfigPath?: string
3031
}
3132

3233
export interface WorkerOptions extends SyncOptions {

packages/eslint-plugin-mdx/src/rules/remark.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,31 @@ export const remark: Rule.RuleModule = {
2727
const extname = path.extname(filename)
2828
// eslint-disable-next-line sonarjs/deprecation -- FIXME: ESLint 8.40+ required
2929
const sourceCode = context.getSourceCode()
30-
// eslint-disable-next-line sonarjs/deprecation -- FIXME: ESLint 8.40+ required
31-
const options = context.parserOptions as ParserOptions
32-
const isMdx = [
33-
...DEFAULT_EXTENSIONS,
34-
...(options.extensions || []),
35-
].includes(extname)
30+
31+
const {
32+
extensions,
33+
markdownExtensions,
34+
ignoreRemarkConfig,
35+
remarkConfigPath,
36+
} =
37+
// eslint-disable-next-line sonarjs/deprecation -- FIXME: ESLint 8.40+ required
38+
context.parserOptions as ParserOptions
39+
40+
const isMdx = [...DEFAULT_EXTENSIONS, ...(extensions || [])].includes(
41+
extname,
42+
)
3643
const isMarkdown = [
3744
...MARKDOWN_EXTENSIONS,
38-
...(options.markdownExtensions || []),
45+
...(markdownExtensions || []),
3946
].includes(extname)
47+
4048
return {
4149
Program(node) {
4250
/* istanbul ignore if */
4351
if (!isMdx && !isMarkdown) {
4452
return
4553
}
4654

47-
const ignoreRemarkConfig = Boolean(options.ignoreRemarkConfig)
48-
4955
const sourceText = sourceCode.getText(node)
5056

5157
const { messages, content: fixedText } = performSyncWork({
@@ -56,6 +62,7 @@ export const remark: Rule.RuleModule = {
5662
isMdx,
5763
process: true,
5864
ignoreRemarkConfig,
65+
remarkConfigPath,
5966
})
6067

6168
let fixed = 0

0 commit comments

Comments
 (0)