Commit 96fffcf 1 parent 80686eb commit 96fffcf Copy full SHA for 96fffcf
File tree 3 files changed +19
-10
lines changed
eslint-plugin-mdx/src/rules
3 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ import {
24
24
ParserOptions ,
25
25
} from './types'
26
26
27
- export const mdxProcessor = unified ( ) . use ( remarkParse ) . use ( remarkMdx ) . freeze ( )
27
+ export const mdProcessor = unified ( ) . use ( remarkParse ) . freeze ( )
28
+ export const mdxProcessor = mdProcessor ( ) . use ( remarkMdx ) . freeze ( )
28
29
29
30
export const AST_PROPS = [ 'body' , 'comments' , 'tokens' ] as const
30
31
export const ES_NODE_TYPES : readonly string [ ] = [ 'export' , 'import' , 'jsx' ]
@@ -157,7 +158,7 @@ export class Parser {
157
158
return this . _eslintParse ( code , options )
158
159
}
159
160
160
- const root = mdxProcessor . parse ( code ) as Parent
161
+ const root = ( isMdx ? mdxProcessor : mdProcessor ) . parse ( code ) as Parent
161
162
162
163
this . _ast = {
163
164
...normalizePosition ( root . position ) ,
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export const requirePkg = (
41
41
let searchSync : ( searchFrom ?: string ) => CosmiconfigResult
42
42
let remarkProcessor : Processor
43
43
44
- export const getRemarkProcessor = ( searchFrom : string ) => {
44
+ export const getRemarkProcessor = ( searchFrom : string , isMdx : boolean ) => {
45
45
if ( ! searchSync ) {
46
46
searchSync = cosmiconfigSync ( 'remark' , {
47
47
packageProp : 'remarkConfig' ,
@@ -66,6 +66,12 @@ export const getRemarkProcessor = (searchFrom: string) => {
66
66
// just ignore if the package does not exist
67
67
}
68
68
69
+ const initProcessor = remarkProcessor ( ) . use ( { settings } ) . use ( remarkStringify )
70
+
71
+ if ( isMdx ) {
72
+ initProcessor . use ( remarkMdx )
73
+ }
74
+
69
75
return plugins
70
76
. reduce ( ( processor , pluginWithSettings ) => {
71
77
const [ plugin , ...pluginSettings ] = Array . isArray ( pluginWithSettings )
@@ -78,6 +84,6 @@ export const getRemarkProcessor = (searchFrom: string) => {
78
84
: plugin ,
79
85
...pluginSettings ,
80
86
)
81
- } , remarkProcessor ( ) . use ( { settings } ) . use ( remarkStringify ) . use ( remarkMdx ) )
87
+ } , initProcessor )
82
88
. freeze ( )
83
89
}
Original file line number Diff line number Diff line change @@ -24,19 +24,21 @@ export const remark: Rule.RuleModule = {
24
24
const filename = context . getFilename ( )
25
25
const extname = path . extname ( filename )
26
26
const sourceCode = context . getSourceCode ( )
27
- const extensions = DEFAULT_EXTENSIONS . concat (
28
- context . parserOptions . extensions || [ ] ,
29
- MARKDOWN_EXTENSIONS ,
30
- context . parserOptions . markdownExtensions || [ ] ,
27
+ const options = context . parserOptions
28
+ const isMdx = DEFAULT_EXTENSIONS . concat ( options . extensions || [ ] ) . includes (
29
+ extname ,
31
30
)
31
+ const isMarkdown = MARKDOWN_EXTENSIONS . concat (
32
+ options . markdownExtensions || [ ] ,
33
+ ) . includes ( extname )
32
34
return {
33
35
Program ( node ) {
34
36
/* istanbul ignore if */
35
- if ( ! extensions . includes ( extname ) ) {
37
+ if ( ! isMdx && ! isMarkdown ) {
36
38
return
37
39
}
38
40
const sourceText = sourceCode . getText ( node )
39
- const remarkProcessor = getRemarkProcessor ( filename )
41
+ const remarkProcessor = getRemarkProcessor ( filename , isMdx )
40
42
const file = vfile ( {
41
43
path : filename ,
42
44
contents : sourceText ,
You can’t perform that action at this time.
0 commit comments