feat!: add meta.languages to Markdown rules#664
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
| name: "markdown/recommended", | ||
| files: ["**/*.md"], | ||
| language: "markdown/commonmark", | ||
| language: "markdown/gfm", |
There was a problem hiding this comment.
Since the table-column-count rule only works in GFM mode, using the recommended config with commonmark causes the following error:
Oops! Something went wrong! :(
ESLint: 10.6.0
The following rules do not support the language "markdown/commonmark":
- "markdown/table-column-count"
To fix this error, either:
- Remove the rule from your configuration, or set its severity to "off".
- Use the "files" option to apply the rule only to files of the supported language, for example:
{
files: ["**/*.js"],
rules: { "markdown/table-column-count": "error" }
}
See https://eslint.org/docs/latest/use/configure/rules for more information.I think there are two possible approaches to resolve this:
The first is to set the recommended config's language to gfm.
The second is to remove the table-column-count rule from the recommended config and keep commonmark mode.
I'm personally inclined to use gfm since GFM syntax is widely used in Markdown documentation, but I'd like to bring this up in case others have a different perspective.
There was a problem hiding this comment.
Since rules currently can't tell which language they're running under (the rule context exposes languageOptions but not language) this doesn’t seem solvable in the rule itself.
Given that, I wonder if the better option might be to keep markdown/commonmark as the default language, since it's the more general subset, and remove rules that aren't compatible with CommonMark from the recommended config. Interested to hear what others think. @eslint/eslint-team
There was a problem hiding this comment.
I agree that the default recommended config should stay with commonmark mode.
As such I think we should introduce recommended-gfm which sets the language to markdown/gfm and includes table-column-count.
For recommended we can remove table-column-count as it would never report anyway as there are no table elements in commonmark.
There was a problem hiding this comment.
Does the table selector used in table-column-count only exist in GFM? If so, perhaps we could declare that the rule supports both "markdown/commonmark" and "markdown/gfm", but it would only report problems in GFM.
There was a problem hiding this comment.
Pull request overview
This PR introduces rule metadata that annotates which Markdown language/dialect(s) each rule applies to, aligning this plugin with similar metadata strategies used in other ESLint language plugins and enabling better rule applicability signaling.
Changes:
- Add
meta.languagesto rule definitions andmeta.docs.dialectsto rule docs metadata (marking GFM-only rules accordingly). - Add
plugin.meta.namespaceand extend tests to cover the new meta field and custom plugin namespaces. - Update the default
recommendedflat config language to GFM and bump ESLint devDependency versions used in this repo.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/types/types.test.ts | Extends type-level assertions to require markdown.meta.namespace. |
| tests/plugin.test.js | Updates runtime meta expectations and adds language/config coverage, including custom-namespace registration. |
| src/index.js | Adds plugin meta.namespace and switches configs.recommended to use language: "markdown/gfm". |
| src/rules/table-column-count.js | Marks the rule as GFM-only via meta.languages and meta.docs.dialects. |
| src/rules/no-bare-urls.js | Marks the rule as GFM-only via meta.languages and meta.docs.dialects. |
| src/rules/require-alt-text.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-unused-definitions.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-space-in-emphasis.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-reversed-media-syntax.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-reference-like-urls.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-multiple-h1.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-missing-link-fragments.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-missing-label-refs.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-missing-atx-heading-space.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-invalid-label-refs.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-html.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-empty-links.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-empty-images.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-empty-definitions.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-duplicate-headings.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/no-duplicate-definitions.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/heading-increment.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/fenced-code-meta.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| src/rules/fenced-code-language.js | Declares CommonMark+GFM applicability via meta.languages and meta.docs.dialects. |
| package.json | Bumps the repo’s ESLint devDependency to ^10.6.0. |
| examples/typescript/package.json | Keeps the TypeScript example aligned with the updated ESLint devDependency version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Prerequisites checklist
AI acknowledgment
What is the purpose of this pull request?
This PR resolves the issue mentioned in #339 and follows the same strategy used in eslint/json#238 and eslint/css#447.
Unlike the JSON and CSS implementations, Markdown has two rules that only work in GFM mode:
no-bare-urlstable-column-countThese rules should be marked as GFM-only, since they are no-ops in CommonMark mode.
What changes did you make? (Give an overview)
Added
meta.languagesandmeta.docs.dialects, along with test cases.Related Issues
Fixes: #339
Refs: eslint/json#238, eslint/css#447
Is there anything you'd like reviewers to focus on?
N/A