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: support new config system #210

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 87 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -201,6 +201,92 @@ 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.

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,

- <https://eslint.org/blog/2022/08/new-config-system-part-1/>
- <https://eslint.org/blog/2022/08/new-config-system-part-2/>
- <https://eslint.org/blog/2022/08/new-config-system-part-3/>

and the [official docs](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new).

### Shareable config

Extending the the `recommended` config will enable the Markdown processor on all .md files.

```ts
import markdown from 'eslint-plugin-markdown/recommended' // <== trailing '/recommended'

export default [
// --- snip ---
...markdown,
// --- snip ---
]
```

### Plugin

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.

If your `eslint.config.js` is ESM, you can import and use the plugin like this.

<!-- eslint-skip -->
```js
import markdown from "eslint-plugin-markdown"

export default [
{
files: ["*.md"],
plugins: {
markdown
},
processor: "markdown/markdown"
},
{
files: ["**/*.md/*.js"],
plugins: {
markdown
},
languageOptions: {
parserOptions: {
// ...
},
},
// ...
rules: {
// ...
},
},
]
```

If your `eslint.config.js` is CJS, you can import and use the plugin like this.

<!-- eslint-skip -->
```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

#### ESLint v7
Expand Down
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
};
8 changes: 8 additions & 0 deletions legacy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @fileoverview Exports the processor.
* @author Brandon Mills
*/

"use strict";

module.exports = require("./lib");
53 changes: 53 additions & 0 deletions lib/configs/recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use strict";

const markdown = require("../../index");

module.exports = [
{
files: ["*.md"],
plugins: {
markdown
},
processor: "markdown/markdown"
},
{
files: ["**/*.md/**"],
plugins: {
markdown
},
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"
}
}
];
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@
"publish-release": "eslint-publish-release"
},
"main": "index.js",
"exports": {
".": {
"import": "./index.js",
"require": "./legacy.js"
},
"./new": "./index.js",
"./recommended": "./lib/configs/recommended.js"
},
"files": [
"index.js",
"legacy.js",
"lib/index.js",
"lib/processor.js"
"lib/processor.js",
"lib/configs/recommended.js"
],
"devDependencies": {
"chai": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down