From 9999860e031737c401675f520c794ce7b342e174 Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Sat, 10 Sep 2022 22:40:52 +0900 Subject: [PATCH 1/9] feat: support new config system --- index.mjs | 6 +++++ lib/configs/recommended.mjs | 44 +++++++++++++++++++++++++++++++++++++ package.json | 11 +++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 index.mjs create mode 100644 lib/configs/recommended.mjs diff --git a/index.mjs b/index.mjs new file mode 100644 index 00000000..cbaf549b --- /dev/null +++ b/index.mjs @@ -0,0 +1,6 @@ +import processor from './lib/processor.js' + +export default { + processor +} + diff --git a/lib/configs/recommended.mjs b/lib/configs/recommended.mjs new file mode 100644 index 00000000..ae9c50fa --- /dev/null +++ b/lib/configs/recommended.mjs @@ -0,0 +1,44 @@ +import markdown from '../../index.mjs' + +export default [ + { + files: ["*.md"], + plugins: { + markdown + }, + processor: "markdown/markdown" + }, + { + files: ["**/*.md/**"], + plugins: { + markdown + }, + parserOptions: { + ecmaFeatures: { + // Adding a "use strict" directive at the top of + // every code block is tedious and distracting, so + // opt into strict mode parsing without the + // directive. + impliedStrict: true + } + }, + rules: { + // The Markdown parser automatically trims trailing + // newlines from code blocks. + "eol-last": "off", + // In code snippets and examples, these rules are often + // counterproductive to clarity and brevity. + "no-undef": "off", + "no-unused-expressions": "off", + "no-unused-vars": "off", + "padded-blocks": "off", + // Adding a "use strict" directive at the top of every + // code block is tedious and distracting. The config + // opts into strict mode parsing without the directive. + strict: "off", + // The processor will not receive a Unicode Byte Order + // Mark from the Markdown parser. + "unicode-bom": "off" + } + } +] diff --git a/package.json b/package.json index b22b87c3..a3628ff4 100644 --- a/package.json +++ b/package.json @@ -31,10 +31,19 @@ "publish-release": "eslint-publish-release" }, "main": "index.js", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + }, + "./recommended": "./lib/configs/recommended.mjs" + }, "files": [ "index.js", + "index.mjs", "lib/index.js", - "lib/processor.js" + "lib/processor.js", + "lib/configs/recommended.mjs" ], "devDependencies": { "chai": "^4.2.0", From 95f965e96c308505b05bbb80acc5154ea8478af4 Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Tue, 13 Sep 2022 18:32:30 +0900 Subject: [PATCH 2/9] fix: languageOptions in the recommenced new config --- index.mjs | 5 ++--- lib/configs/recommended.mjs | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/index.mjs b/index.mjs index cbaf549b..c386427e 100644 --- a/index.mjs +++ b/index.mjs @@ -1,6 +1,5 @@ -import processor from './lib/processor.js' +import processor from "./lib/processor.js"; export default { processor -} - +}; diff --git a/lib/configs/recommended.mjs b/lib/configs/recommended.mjs index ae9c50fa..a6ae3269 100644 --- a/lib/configs/recommended.mjs +++ b/lib/configs/recommended.mjs @@ -1,4 +1,4 @@ -import markdown from '../../index.mjs' +import markdown from "../../index.mjs"; export default [ { @@ -13,32 +13,39 @@ export default [ plugins: { markdown }, - parserOptions: { - ecmaFeatures: { - // Adding a "use strict" directive at the top of - // every code block is tedious and distracting, so - // opt into strict mode parsing without the - // directive. - impliedStrict: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + + // Adding a "use strict" directive at the top of + // every code block is tedious and distracting, so + // opt into strict mode parsing without the + // directive. + impliedStrict: true + } } }, rules: { + // The Markdown parser automatically trims trailing // newlines from code blocks. "eol-last": "off", + // In code snippets and examples, these rules are often // counterproductive to clarity and brevity. "no-undef": "off", "no-unused-expressions": "off", "no-unused-vars": "off", "padded-blocks": "off", + // Adding a "use strict" directive at the top of every // code block is tedious and distracting. The config // opts into strict mode parsing without the directive. strict: "off", + // The processor will not receive a Unicode Byte Order // Mark from the Markdown parser. "unicode-bom": "off" } } -] +]; From 432b2b93e6e1855b0a4162cd9fe63818443e248c Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Tue, 13 Sep 2022 19:04:25 +0900 Subject: [PATCH 3/9] docs: guide the new config system --- README.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 58dda721..8d733d46 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Install the plugin alongside ESLint v6 or greater: npm install --save-dev eslint eslint-plugin-markdown ``` -### Configuring +### Configuring (legacy: `.eslintrc*`) Extending the `plugin:markdown/recommended` config will enable the Markdown processor on all `.md` files: @@ -201,6 +201,76 @@ module.exports = { }; ``` +### Configuring (new: `eslint.config.js`) + +From [`v8.21.0`](https://github.com/eslint/eslint/releases/tag/v8.21.0), eslint announced a new config system. +In the new system, `.eslintrc*` is no longer used. `eslint.config.js` would be the default config file name. +In eslint `v8`, the legacy system (`.eslintrc*`) would still be supported, while in eslint `v9`, only the new system would be supported. + +And from [`v8.23.0`](https://github.com/eslint/eslint/releases/tag/v8.23.0), eslint CLI starts to look up `eslint.config.js`. +**So, if your eslint is `>=8.23.0`, you're 100% ready to use the new config system.** + +You might want to check out the official blog posts, + +- +- +- + +and the [official docs](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new). + +If your `eslint.config.js` is CJS, change it to ESM. + +### Shareable config + +Extending the the `recommended` config will enable the Markdown processor on all .md files. + +```js +import markdown from 'eslint-plugin-markdown/recommended' + +export default [ + // --- snip --- + ...markdown, + // --- snip --- +] +``` + +### Plugin + +The default export of `eslint-plugin-markdown` is a plugin object. + +For example, a basic skeleton would be like this. + +```js +import markdown from "eslint-plugin-markdown" + +export default [ + { + files: ["*.md"], + plugins: { + markdown + }, + processor: "markdown/markdown" + }, + { + files: ["**/*.md/*.js"], + plugins: { + markdown + }, + languageOptions: { + parserOptions: { + // ... + }, + }, + // ... + rules: { + // ... + }, + }, +] +``` + +For more usage tips, refer to [Advanced Configuration](#advanced-configuration), [Frequently-Disabled Rules](#frequently-disabled-rules), [strict-mode](#strict-mode), [Unsatisfiable Rules](#unsatisfiable-rules), and [Migrating from `eslint-plugin-markdown` v1](#migrating-from-eslint-plugin-markdown-v1). Those usage details are different as they are based on the legacy config system, but the concepts behind of it is same between the legacy and the new. Thus you will be able to understand how to adapt it to the new config system. + ### Running #### ESLint v7 From cfb683d7188d4f602dde8f3ac41cc06d419f88bc Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Tue, 13 Sep 2022 19:07:09 +0900 Subject: [PATCH 4/9] docs: elaborate --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d733d46..be9c0009 100644 --- a/README.md +++ b/README.md @@ -236,9 +236,10 @@ export default [ ### Plugin -The default export of `eslint-plugin-markdown` is a plugin object. +If the `recommended` shareable does not fit to you, use plugin directly and configure from the ground up. -For example, a basic skeleton would be like this. +The default export of `eslint-plugin-markdown` is a plugin object. +A basic usage skeleton would be like this. ```js import markdown from "eslint-plugin-markdown" From cebb1164bace4bbfeb746c3a4ac3c1308acdf9dd Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Tue, 13 Sep 2022 19:11:01 +0900 Subject: [PATCH 5/9] docs: fix lint err --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index be9c0009..d73986f5 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ If your `eslint.config.js` is CJS, change it to ESM. Extending the the `recommended` config will enable the Markdown processor on all .md files. -```js +```ts import markdown from 'eslint-plugin-markdown/recommended' export default [ @@ -241,7 +241,7 @@ If the `recommended` shareable does not fit to you, use plugin directly and conf The default export of `eslint-plugin-markdown` is a plugin object. A basic usage skeleton would be like this. -```js +```ts import markdown from "eslint-plugin-markdown" export default [ From dd9a5b60506b358450286f73e8179ba1290c1e85 Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Tue, 13 Sep 2022 19:30:36 +0900 Subject: [PATCH 6/9] feat: support new config system in CJS --- README.md | 70 ++++++++++++------- index.js | 11 ++- index.mjs | 5 -- legacy.js | 8 +++ .../{recommended.mjs => recommended.js} | 6 +- package.json | 5 +- tests/lib/plugin.js | 2 +- 7 files changed, 64 insertions(+), 43 deletions(-) delete mode 100644 index.mjs create mode 100644 legacy.js rename lib/configs/{recommended.mjs => recommended.js} (95%) diff --git a/README.md b/README.md index d73986f5..9dd1f4cd 100644 --- a/README.md +++ b/README.md @@ -218,14 +218,12 @@ You might want to check out the official blog posts, and the [official docs](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new). -If your `eslint.config.js` is CJS, change it to ESM. - ### Shareable config Extending the the `recommended` config will enable the Markdown processor on all .md files. ```ts -import markdown from 'eslint-plugin-markdown/recommended' +import markdown from 'eslint-plugin-markdown/recommended' // <== trailing '/recommended' export default [ // --- snip --- @@ -236,41 +234,59 @@ export default [ ### Plugin -If the `recommended` shareable does not fit to you, use plugin directly and configure from the ground up. +The `recommended` shareable config might not fit to you. +Then use plugin object directly instead of the config object. +Unlike `eslint-plugin-markdown/recommended`, the default export of `eslint-plugin-markdown` is a plugin object. -The default export of `eslint-plugin-markdown` is a plugin object. -A basic usage skeleton would be like this. +If your `eslint.config.js` is ESM, you can import and use the plugin like this. -```ts + +```js import markdown from "eslint-plugin-markdown" export default [ - { - files: ["*.md"], - plugins: { - markdown - }, - processor: "markdown/markdown" - }, - { - files: ["**/*.md/*.js"], - plugins: { - markdown + { + files: ["*.md"], + plugins: { + markdown + }, + processor: "markdown/markdown" }, - languageOptions: { - parserOptions: { + { + files: ["**/*.md/*.js"], + plugins: { + markdown + }, + languageOptions: { + parserOptions: { + // ... + }, + }, // ... - }, - }, - // ... - rules: { - // ... + rules: { + // ... + }, }, - }, ] ``` -For more usage tips, refer to [Advanced Configuration](#advanced-configuration), [Frequently-Disabled Rules](#frequently-disabled-rules), [strict-mode](#strict-mode), [Unsatisfiable Rules](#unsatisfiable-rules), and [Migrating from `eslint-plugin-markdown` v1](#migrating-from-eslint-plugin-markdown-v1). Those usage details are different as they are based on the legacy config system, but the concepts behind of it is same between the legacy and the new. Thus you will be able to understand how to adapt it to the new config system. +If your `eslint.config.js` is CJS, you can import and use the plugin like this. + + +```js +const markdown = require("eslint-plugin-markdown/new"); // <== trailing '/new' + +module.exports = [ + { + // ... others are omitted for brevity + plugins: { + markdown + } + } +]; +``` + +For more usage tips, refer to [Advanced Configuration](#advanced-configuration), [Frequently-Disabled Rules](#frequently-disabled-rules), [strict-mode](#strict-mode), [Unsatisfiable Rules](#unsatisfiable-rules), and [Migrating from `eslint-plugin-markdown` v1](#migrating-from-eslint-plugin-markdown-v1). Those usage details are different as they are based on the legacy config system, but the concepts behind of it is same between the legacy and the new. Thus if you already have prerequisite understanding of the new config system, you will be able to know how to adapt it to the new config system. ### Running diff --git a/index.js b/index.js index 1638f11e..c5bb77d3 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,7 @@ -/** - * @fileoverview Exports the processor. - * @author Brandon Mills - */ - "use strict"; -module.exports = require("./lib"); +const processor = require("./lib/processor"); + +module.exports = { + processor +}; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c386427e..00000000 --- a/index.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import processor from "./lib/processor.js"; - -export default { - processor -}; diff --git a/legacy.js b/legacy.js new file mode 100644 index 00000000..1638f11e --- /dev/null +++ b/legacy.js @@ -0,0 +1,8 @@ +/** + * @fileoverview Exports the processor. + * @author Brandon Mills + */ + +"use strict"; + +module.exports = require("./lib"); diff --git a/lib/configs/recommended.mjs b/lib/configs/recommended.js similarity index 95% rename from lib/configs/recommended.mjs rename to lib/configs/recommended.js index a6ae3269..e50a23c4 100644 --- a/lib/configs/recommended.mjs +++ b/lib/configs/recommended.js @@ -1,6 +1,8 @@ -import markdown from "../../index.mjs"; +"use strict"; -export default [ +const markdown = require("../../index"); + +module.exports = [ { files: ["*.md"], plugins: { diff --git a/package.json b/package.json index a3628ff4..999cd0dc 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,10 @@ "main": "index.js", "exports": { ".": { - "import": "./index.mjs", - "require": "./index.js" + "import": "./index.js", + "require": "./legacy.js" }, + "./new": "./index.js", "./recommended": "./lib/configs/recommended.mjs" }, "files": [ diff --git a/tests/lib/plugin.js b/tests/lib/plugin.js index e554395b..fd7653d4 100644 --- a/tests/lib/plugin.js +++ b/tests/lib/plugin.js @@ -9,7 +9,7 @@ const assert = require("chai").assert; const execSync = require("child_process").execSync; const { CLIEngine, ESLint } = require("eslint"); const path = require("path"); -const plugin = require("../.."); +const plugin = require("../../legacy"); /** * @typedef {import('eslint/lib/cli-engine/cli-engine').CLIEngineOptions} CLIEngineOptions From ef60d6957f9067dab5668037923cddccd8c4fd81 Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Wed, 21 Sep 2022 16:00:46 +0900 Subject: [PATCH 7/9] docs: fix EOL of legacy config --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9dd1f4cd..460e965f 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,6 @@ module.exports = { From [`v8.21.0`](https://github.com/eslint/eslint/releases/tag/v8.21.0), eslint announced a new config system. In the new system, `.eslintrc*` is no longer used. `eslint.config.js` would be the default config file name. -In eslint `v8`, the legacy system (`.eslintrc*`) would still be supported, while in eslint `v9`, only the new system would be supported. And from [`v8.23.0`](https://github.com/eslint/eslint/releases/tag/v8.23.0), eslint CLI starts to look up `eslint.config.js`. **So, if your eslint is `>=8.23.0`, you're 100% ready to use the new config system.** From 82dcf31272e60f52e21b1858054db54e145753fe Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Wed, 21 Sep 2022 17:56:03 +0900 Subject: [PATCH 8/9] fix: exports --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 999cd0dc..251306d5 100644 --- a/package.json +++ b/package.json @@ -37,14 +37,14 @@ "require": "./legacy.js" }, "./new": "./index.js", - "./recommended": "./lib/configs/recommended.mjs" + "./recommended": "./lib/configs/recommended.js" }, "files": [ "index.js", - "index.mjs", + "legacy.js" "lib/index.js", "lib/processor.js", - "lib/configs/recommended.mjs" + "lib/configs/recommended.js" ], "devDependencies": { "chai": "^4.2.0", From 7ac2be4d08a1c976785d8406bc152e238614eea0 Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Wed, 21 Sep 2022 18:00:31 +0900 Subject: [PATCH 9/9] fix: typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 251306d5..b6e83b01 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ }, "files": [ "index.js", - "legacy.js" + "legacy.js", "lib/index.js", "lib/processor.js", "lib/configs/recommended.js"