1+ import fs from 'node:fs'
12import { createRequire } from 'node:module'
3+ import path from 'node:path'
24import { fileURLToPath } from 'node:url'
35
46import type { Options } from '@cspell/eslint-plugin'
@@ -13,17 +15,43 @@ import globals from 'globals'
1315import tseslint from 'typescript-eslint'
1416
1517import { loadConfig } from './cli/load-config.js'
18+ import { getGlobalComponentNames } from './plugins/global/components.js'
19+ import { pkgResolve } from './utils/index.js'
1620
1721const cjsRequire = createRequire ( import . meta. url )
1822
19- let remarkConfigPath : string
23+ let remarkConfigPath : string | undefined
24+
25+ const isLoadableRemarkConfigPath = ( filepath : string ) =>
26+ [ '.cjs' , '.js' , '.mjs' ] . includes ( path . extname ( filepath ) )
2027
2128try {
22- remarkConfigPath = fileURLToPath ( import . meta. resolve ( './remarkrc.js' ) )
29+ const resolvedRemarkConfigPath = fileURLToPath (
30+ import . meta. resolve ( './remarkrc.js' ) ,
31+ )
32+ if ( isLoadableRemarkConfigPath ( resolvedRemarkConfigPath ) ) {
33+ remarkConfigPath = resolvedRemarkConfigPath
34+ }
2335} catch {
24- remarkConfigPath = cjsRequire . resolve ( './remarkrc.js' )
36+ try {
37+ const resolvedRemarkConfigPath = cjsRequire . resolve ( './remarkrc.js' )
38+ if ( isLoadableRemarkConfigPath ( resolvedRemarkConfigPath ) ) {
39+ remarkConfigPath = resolvedRemarkConfigPath
40+ }
41+ } catch {
42+ remarkConfigPath = undefined
43+ }
44+ }
45+
46+ const builtRemarkConfigPath = pkgResolve ( 'lib/remarkrc.js' )
47+ if ( ! remarkConfigPath && fs . existsSync ( builtRemarkConfigPath ) ) {
48+ remarkConfigPath = builtRemarkConfigPath
2549}
2650
51+ const globalComponentGlobals = Object . fromEntries (
52+ getGlobalComponentNames ( ) . map ( ( name ) => [ name , 'readonly' ] ) ,
53+ ) as Record < string , 'readonly' >
54+
2755async function doom (
2856 userConfig ?: UserConfig | null ,
2957) : Promise < tseslint . ConfigArray >
@@ -64,7 +92,7 @@ async function doom(userConfigOrRoot?: UserConfig | string | null | URL) {
6492 languageOptions : {
6593 globals : globals . browser ,
6694 parserOptions : {
67- remarkConfigPath,
95+ ... ( remarkConfigPath && { remarkConfigPath } ) ,
6896 } ,
6997 } ,
7098 rules : cspellEnabled
@@ -81,6 +109,9 @@ async function doom(userConfigOrRoot?: UserConfig | string | null | URL) {
81109 } ,
82110 {
83111 files : [ '**/*.mdx' ] ,
112+ languageOptions : {
113+ globals : globalComponentGlobals ,
114+ } ,
84115 rules : {
85116 '@eslint-react/jsx-no-children-prop' : 'off' ,
86117 '@eslint-react/rules-of-hooks' : 'off' ,
0 commit comments