Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use eslint-plugin-mdx for md/mdx files #353

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"eslint-plugin-jsdoc": "^46.9.0",
"eslint-plugin-jsonc": "^2.10.0",
"eslint-plugin-mdx": "^2.2.0",
"eslint-plugin-n": "^16.3.1",
"eslint-plugin-n": "^16.4.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-perfectionist": "^2.5.0",
"eslint-plugin-toml": "^0.7.1",
Expand Down
79 changes: 14 additions & 65 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 25 additions & 9 deletions src/configs/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as mdx from 'eslint-plugin-mdx'

import type { FlatConfigItem, OptionsComponentExts, OptionsFiles, OptionsOverrides } from '../types'
import { GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_OR_MDX } from '../globs'

Expand All @@ -11,21 +9,40 @@
overrides = {},
} = options

const [
mdx,
mdxParser,
] = await Promise.all([
// @ts-expect-error missing types

Check failure on line 16 in src/configs/markdown.ts

View workflow job for this annotation

GitHub Actions / typecheck

Unused '@ts-expect-error' directive.

Check failure on line 16 in src/configs/markdown.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

Unused '@ts-expect-error' directive.

Check failure on line 16 in src/configs/markdown.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, windows-latest)

Unused '@ts-expect-error' directive.

Check failure on line 16 in src/configs/markdown.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

Unused '@ts-expect-error' directive.
antfu marked this conversation as resolved.
Show resolved Hide resolved
import('eslint-plugin-mdx'),
import('eslint-mdx'),
])

return [
{
name: 'antfu:markdown-mdx',
...(mdx.flat as FlatConfigItem),
files: ['**/*.{md,mdx}'],
languageOptions: {
ecmaVersion: 'latest',
globals: {
React: false,
},
parser: mdxParser,
sourceType: 'module',
},
name: 'antfu:markdown-mdx:setup',
plugins: {
mdx,
},
processor: mdx.createRemarkProcessor({
lintCodeBlocks: true,
}),
rules: {
...mdx.flat.rules,
'mdx/remark': 'warn',
'no-unused-expressions': 'error',
'style/indent': 'off',
JounQin marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
name: 'antfu:markdown-mdx:code-blocks',
...(mdx.flatCodeBlocks as FlatConfigItem),
files: [
GLOB_MARKDOWN_CODE,
...componentExts.map(ext => `${GLOB_MARKDOWN_OR_MDX}/**/*.${ext}`),
Expand All @@ -37,9 +54,8 @@
},
},
},
name: 'antfu:markdown-mdx:code-blocks',
rules: {
...mdx.flatCodeBlocks.rules,

'import/newline-after-import': 'off',

'no-alert': 'off',
Expand Down
4 changes: 2 additions & 2 deletions src/globs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const GLOB_JSONC = '**/*.jsonc'

export const GLOB_MARKDOWN = '**/*.md'
export const GLOB_MDX = '**/*.mdx'
export const GLOB_MARKDOWN_OR_MDX = '**/*.md?(x)'
export const GLOB_MARKDOWN_OR_MDX_IN_MARKDOWN_OR_MDX = '**/*.md?(x)/*.md?(x)'
export const GLOB_MARKDOWN_OR_MDX = '**/*.{md,mdx}'
export const GLOB_MARKDOWN_OR_MDX_IN_MARKDOWN_OR_MDX = '**/*.{md,mdx}/*.{md,mdx}'
export const GLOB_VUE = '**/*.vue'
export const GLOB_YAML = '**/*.y?(a)ml'
export const GLOB_TOML = '**/*.toml'
Expand Down