From 4474305ba7bb3f8ce3b86f51fe5965954f51aa5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Thu, 21 Aug 2025 23:46:17 +0900 Subject: [PATCH 1/4] build: add `prettier` to `update-rules-docs` script --- .prettierignore | 1 + README.md | 167 +++++++++++++++++++------------------ tools/update-rules-docs.js | 13 ++- 3 files changed, 99 insertions(+), 82 deletions(-) diff --git a/.prettierignore b/.prettierignore index 107e831b..beb2c492 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,3 +2,4 @@ dist CHANGELOG.md jsr.json **/*.md +!README.md \ No newline at end of file diff --git a/README.md b/README.md index 1a985e0b..77122f0a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Lint Markdown with ESLint, as well JS, JSX, TypeScript, and more inside Markdown ### Installing -Install the plugin alongside ESLint v9 or greater. +Install the plugin alongside ESLint v9 or greater. For Node.js and compatible runtimes: @@ -39,10 +39,10 @@ deno add jsr:@eslint/markdown ### Configurations -| **Configuration Name** | **Description** | -|---------------|-----------------| -| `recommended` | Lints all `.md` files with the recommended rules and assumes [CommonMark](https://commonmark.org/) format. | -| `processor` | Enables extracting code blocks from all `.md` files so code blocks can be individually linted. | +| **Configuration Name** | **Description** | +| ---------------------- | ---------------------------------------------------------------------------------------------------------- | +| `recommended` | Lints all `.md` files with the recommended rules and assumes [CommonMark](https://commonmark.org/) format. | +| `processor` | Enables extracting code blocks from all `.md` files so code blocks can be individually linted. | In your `eslint.config.js` file, import `@eslint/markdown` and include the recommended config to enable Markdown parsing and linting: @@ -52,9 +52,9 @@ import { defineConfig } from "eslint/config"; import markdown from "@eslint/markdown"; export default defineConfig([ - markdown.configs.recommended + markdown.configs.recommended, - // your other configs here + // your other configs here ]); ``` @@ -66,17 +66,17 @@ import { defineConfig } from "eslint/config"; import markdown from "@eslint/markdown"; export default defineConfig([ - { - plugins: { - markdown - }, - extends: ["markdown/recommended"], - rules: { - "markdown/no-html": "error" - } - } - - // your other configs here + { + plugins: { + markdown, + }, + extends: ["markdown/recommended"], + rules: { + "markdown/no-html": "error", + }, + }, + + // your other configs here ]); ``` @@ -85,27 +85,29 @@ export default defineConfig([ -| **Rule Name** | **Description** | **Recommended** | -| :- | :- | :-: | -| [`fenced-code-language`](./docs/rules/fenced-code-language.md) | Require languages for fenced code blocks | yes | -| [`heading-increment`](./docs/rules/heading-increment.md) | Enforce heading levels increment by one | yes | -| [`no-bare-urls`](./docs/rules/no-bare-urls.md) | Disallow bare URLs | no | -| [`no-duplicate-definitions`](./docs/rules/no-duplicate-definitions.md) | Disallow duplicate definitions | yes | -| [`no-duplicate-headings`](./docs/rules/no-duplicate-headings.md) | Disallow duplicate headings in the same document | no | -| [`no-empty-definitions`](./docs/rules/no-empty-definitions.md) | Disallow empty definitions | yes | -| [`no-empty-images`](./docs/rules/no-empty-images.md) | Disallow empty images | yes | -| [`no-empty-links`](./docs/rules/no-empty-links.md) | Disallow empty links | yes | -| [`no-html`](./docs/rules/no-html.md) | Disallow HTML tags | no | -| [`no-invalid-label-refs`](./docs/rules/no-invalid-label-refs.md) | Disallow invalid label references | yes | -| [`no-missing-atx-heading-space`](./docs/rules/no-missing-atx-heading-space.md) | Disallow headings without a space after the hash characters | yes | -| [`no-missing-label-refs`](./docs/rules/no-missing-label-refs.md) | Disallow missing label references | yes | -| [`no-missing-link-fragments`](./docs/rules/no-missing-link-fragments.md) | Disallow link fragments that do not reference valid headings | yes | -| [`no-multiple-h1`](./docs/rules/no-multiple-h1.md) | Disallow multiple H1 headings in the same document | yes | -| [`no-reversed-media-syntax`](./docs/rules/no-reversed-media-syntax.md) | Disallow reversed link and image syntax | yes | -| [`no-space-in-emphasis`](./docs/rules/no-space-in-emphasis.md) | Disallow spaces around emphasis markers | yes | -| [`no-unused-definitions`](./docs/rules/no-unused-definitions.md) | Disallow unused definitions | yes | -| [`require-alt-text`](./docs/rules/require-alt-text.md) | Require alternative text for images | yes | -| [`table-column-count`](./docs/rules/table-column-count.md) | Disallow data rows in a GitHub Flavored Markdown table from having more cells than the header row | yes | + +| **Rule Name** | **Description** | **Recommended** | +| :----------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------ | :-------------: | +| [`fenced-code-language`](./docs/rules/fenced-code-language.md) | Require languages for fenced code blocks | yes | +| [`heading-increment`](./docs/rules/heading-increment.md) | Enforce heading levels increment by one | yes | +| [`no-bare-urls`](./docs/rules/no-bare-urls.md) | Disallow bare URLs | no | +| [`no-duplicate-definitions`](./docs/rules/no-duplicate-definitions.md) | Disallow duplicate definitions | yes | +| [`no-duplicate-headings`](./docs/rules/no-duplicate-headings.md) | Disallow duplicate headings in the same document | no | +| [`no-empty-definitions`](./docs/rules/no-empty-definitions.md) | Disallow empty definitions | yes | +| [`no-empty-images`](./docs/rules/no-empty-images.md) | Disallow empty images | yes | +| [`no-empty-links`](./docs/rules/no-empty-links.md) | Disallow empty links | yes | +| [`no-html`](./docs/rules/no-html.md) | Disallow HTML tags | no | +| [`no-invalid-label-refs`](./docs/rules/no-invalid-label-refs.md) | Disallow invalid label references | yes | +| [`no-missing-atx-heading-space`](./docs/rules/no-missing-atx-heading-space.md) | Disallow headings without a space after the hash characters | yes | +| [`no-missing-label-refs`](./docs/rules/no-missing-label-refs.md) | Disallow missing label references | yes | +| [`no-missing-link-fragments`](./docs/rules/no-missing-link-fragments.md) | Disallow link fragments that do not reference valid headings | yes | +| [`no-multiple-h1`](./docs/rules/no-multiple-h1.md) | Disallow multiple H1 headings in the same document | yes | +| [`no-reversed-media-syntax`](./docs/rules/no-reversed-media-syntax.md) | Disallow reversed link and image syntax | yes | +| [`no-space-in-emphasis`](./docs/rules/no-space-in-emphasis.md) | Disallow spaces around emphasis markers | yes | +| [`no-unused-definitions`](./docs/rules/no-unused-definitions.md) | Disallow unused definitions | yes | +| [`require-alt-text`](./docs/rules/require-alt-text.md) | Require alternative text for images | yes | +| [`table-column-count`](./docs/rules/table-column-count.md) | Disallow data rows in a GitHub Flavored Markdown table from having more cells than the header row | yes | + **Note:** This plugin does not provide formatting rules. We recommend using a source code formatter such as [Prettier](https://prettier.io) for that purpose. @@ -118,16 +120,16 @@ import { defineConfig } from "eslint/config"; import markdown from "@eslint/markdown"; export default defineConfig([ - { - files: ["**/*.md"], - plugins: { - markdown - }, - language: "markdown/commonmark", - rules: { - "markdown/no-html": "error" - } - } + { + files: ["**/*.md"], + plugins: { + markdown, + }, + language: "markdown/commonmark", + rules: { + "markdown/no-html": "error", + }, + }, ]); ``` @@ -135,10 +137,13 @@ You can individually disable rules in Markdown using HTML comments, such as: ```markdown + Hello world! + Goodbye world! + [Object] @@ -146,10 +151,10 @@ You can individually disable rules in Markdown using HTML comments, such as: ### Languages -| **Language Name** | **Description** | -|---------------|-----------------| -| `commonmark` | Parse using [CommonMark](https://commonmark.org) Markdown format | -| `gfm` | Parse using [GitHub-Flavored Markdown](https://github.github.com/gfm/) format | +| **Language Name** | **Description** | +| ----------------- | ----------------------------------------------------------------------------- | +| `commonmark` | Parse using [CommonMark](https://commonmark.org) Markdown format | +| `gfm` | Parse using [GitHub-Flavored Markdown](https://github.github.com/gfm/) format | In order to individually configure a language in your `eslint.config.js` file, import `@eslint/markdown` and configure a `language`: @@ -159,16 +164,16 @@ import { defineConfig } from "eslint/config"; import markdown from "@eslint/markdown"; export default defineConfig([ - { - files: ["**/*.md"], - plugins: { - markdown - }, - language: "markdown/gfm", - rules: { - "markdown/no-html": "error" - } - } + { + files: ["**/*.md"], + plugins: { + markdown, + }, + language: "markdown/gfm", + rules: { + "markdown/no-html": "error", + }, + }, ]); ``` @@ -176,12 +181,12 @@ export default defineConfig([ #### Enabling Front Matter in both `commonmark` and `gfm` -By default, Markdown parsers do not support [front matter](https://jekyllrb.com/docs/front-matter/). To enable front matter in both `commonmark` and `gfm`, you can use the `frontmatter` option in `languageOptions`. +By default, Markdown parsers do not support [front matter](https://jekyllrb.com/docs/front-matter/). To enable front matter in both `commonmark` and `gfm`, you can use the `frontmatter` option in `languageOptions`. > `@eslint/markdown` internally uses [`micromark-extension-frontmatter`](https://github.com/micromark/micromark-extension-frontmatter) and [`mdast-util-frontmatter`](https://github.com/syntax-tree/mdast-util-frontmatter) to parse front matter. | **Option Value** | **Description** | -|------------------|------------------------------------------------------------| +| ---------------- | ---------------------------------------------------------- | | `false` | Disables front matter parsing in Markdown files. (Default) | | `"yaml"` | Enables YAML front matter parsing in Markdown files. | | `"toml"` | Enables TOML front matter parsing in Markdown files. | @@ -193,27 +198,27 @@ import { defineConfig } from "eslint/config"; import markdown from "@eslint/markdown"; export default defineConfig([ - { - files: ["**/*.md"], - plugins: { - markdown - }, - language: "markdown/gfm", - languageOptions: { - frontmatter: "yaml", // Or pass `"toml"` or `"json"` to enable TOML or JSON front matter parsing. - }, - rules: { - "markdown/no-html": "error" - } - } + { + files: ["**/*.md"], + plugins: { + markdown, + }, + language: "markdown/gfm", + languageOptions: { + frontmatter: "yaml", // Or pass `"toml"` or `"json"` to enable TOML or JSON front matter parsing. + }, + rules: { + "markdown/no-html": "error", + }, + }, ]); ``` ### Processors -| **Processor Name** | **Description** | -|---------------|-----------------| -| [`markdown`](./docs/processors/markdown.md) | Extract fenced code blocks from the Markdown code so they can be linted separately. | +| **Processor Name** | **Description** | +| ------------------------------------------- | ----------------------------------------------------------------------------------- | +| [`markdown`](./docs/processors/markdown.md) | Extract fenced code blocks from the Markdown code so they can be linted separately. | ## Editor Integrations diff --git a/tools/update-rules-docs.js b/tools/update-rules-docs.js index 07a3be93..e2062286 100644 --- a/tools/update-rules-docs.js +++ b/tools/update-rules-docs.js @@ -15,6 +15,7 @@ import { fromMarkdown } from "mdast-util-from-markdown"; import fs from "node:fs/promises"; import path from "node:path"; +import prettier from "prettier"; //----------------------------------------------------------------------------- // Type Definitions @@ -99,4 +100,14 @@ const tableText = await createRulesTableText(); docsText = `${docsText.slice(0, rulesTableRange[0])}\n${tableText}\n${docsText.slice(rulesTableRange[1])}`; -await fs.writeFile(docsFileURL, docsText); +// load prettier config +const prettierConfig = await prettier.resolveConfig(docsFileURL); + +// format and write the file +await fs.writeFile( + docsFileURL, + await prettier.format(docsText, { + filepath: docsFileURL.pathname, + ...prettierConfig, + }), +); From 30f6affd09af8f4d27e963615d6805fd82ba126b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Thu, 21 Aug 2025 23:55:13 +0900 Subject: [PATCH 2/4] wip --- .prettierignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index beb2c492..17be25bd 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,4 +2,4 @@ dist CHANGELOG.md jsr.json **/*.md -!README.md \ No newline at end of file +!README.md From 5703b0e4c9b451ebccef0d3de647ca3711afc8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Fri, 22 Aug 2025 00:01:13 +0900 Subject: [PATCH 3/4] wip --- .prettierignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index 17be25bd..737576ce 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,4 +2,4 @@ dist CHANGELOG.md jsr.json **/*.md -!README.md +!/README.md From ba965900111a5decc7999e32d023b6e7367cb50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Sat, 23 Aug 2025 16:44:31 +0900 Subject: [PATCH 4/4] wip: add prettier-ignore --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 77122f0a..b67af806 100644 --- a/README.md +++ b/README.md @@ -135,19 +135,18 @@ export default defineConfig([ You can individually disable rules in Markdown using HTML comments, such as: + ```markdown - Hello world! - Goodbye world! - [Object] ``` + ### Languages