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!: Convert to ESM #259

Merged
merged 10 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ jobs:
node-version: lts/*
registry-url: https://registry.npmjs.org
if: ${{ steps.release.outputs.release_created }}
- run: npm publish --provenance
- run: |
npm install
npm run build --if-present
npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: ${{ steps.release.outputs.release_created }}
Expand Down
59 changes: 0 additions & 59 deletions README.md
nzakas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ export default [
];
```

If you are still using the deprecated `.eslintrc.js` file format for ESLint, you can extend the `plugin:markdown/recommended-legacy` config to enable the Markdown processor on all `.md` files:

```js
// .eslintrc.js
module.exports = {
extends: "plugin:markdown/recommended-legacy"
};
```

#### Advanced Configuration

You can manually include the Markdown processor by setting the `processor` option in your configuration file for all `.md` files.
Expand Down Expand Up @@ -96,32 +87,6 @@ export default [
];
```

In the deprecated `.eslintrc.js` format:

```js
// .eslintrc.js
module.exports = {
// 1. Add the plugin.
plugins: ["markdown"],
overrides: [
{
// 2. Enable the Markdown processor for all .md files.
files: ["**/*.md"],
processor: "markdown/markdown"
},
{
// 3. Optionally, customize the configuration ESLint uses for ```js
// fenced code blocks inside .md files.
files: ["**/*.md/*.js"],
// ...
rules: {
// ...
}
}
]
};
```

#### Frequently-Disabled Rules

Some rules that catch mistakes in regular code are less helpful in documentation.
Expand Down Expand Up @@ -163,30 +128,6 @@ export default [
];
```

And in the deprecated `.eslintrc.js` format:

```js
// .eslintrc.js
module.exports = {
plugins: ["markdown"],
overrides: [
{
files: ["**/*.md"],
processor: "markdown/markdown"
},
{
// 1. Target ```js code blocks in .md files.
files: ["**/*.md/*.js"],
rules: {
// 2. Disable other rules.
"no-console": "off",
"import/no-unresolved": "off"
}
}
]
};
```

#### Strict Mode

`"use strict"` directives in every code block would be annoying.
Expand Down
21 changes: 12 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"use strict";
import globals from "globals";
import eslintConfigESLint from "eslint-config-eslint";
import eslintConfigESLintFormatting from "eslint-config-eslint/formatting";
import markdown from "./src/index.js";

module.exports = [
...require("eslint-config-eslint/cjs").map(config => ({
...config,
files: ["**/*.js"]
})),
export default [
...eslintConfigESLint,
{
...require("eslint-config-eslint/formatting"),
...eslintConfigESLintFormatting,
files: ["**/*.js"]
},
nzakas marked this conversation as resolved.
Show resolved Hide resolved
{
plugins: {
markdown: require(".")
markdown
}
},
{
Expand All @@ -25,8 +25,11 @@ module.exports = [
files: ["tests/**/*.js"],
languageOptions: {
globals: {
...require("globals").mocha
...globals.mocha
}
},
rules: {
"no-underscore-dangle": "off"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use strict";

const markdown = require("eslint-plugin-markdown");
const js = require("@eslint/js");
const globals = require("globals");
import js from "@eslint/js";
import markdown from "../../src/index.js";
import globals from "globals";
import reactRecommended from "eslint-plugin-react/configs/recommended.js";

module.exports = [
export default [
js.configs.recommended,
...markdown.configs.recommended,
require("eslint-plugin-react/configs/recommended"),
reactRecommended,
{
settings: {
react: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";
import js from "@eslint/js";
import markdown from "../../src/index.js";
import tseslint from "typescript-eslint";

const markdown = require("eslint-plugin-markdown");
const js = require("@eslint/js")
const tseslint = require("typescript-eslint");

module.exports = tseslint.config(
export default tseslint.config(
js.configs.recommended,
...markdown.configs.recommended,
{
Expand Down
8 changes: 0 additions & 8 deletions index.js

This file was deleted.

File renamed without changes.
29 changes: 17 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
"name": "Brandon Mills",
"url": "https://github.com/btmills"
},
"type": "module",
"main": "src/index.js",
"exports": {
"import": {
"default": "./srcindex.js"
nzakas marked this conversation as resolved.
Show resolved Hide resolved
}
},
"files": [
"src"
],
"repository": "eslint/eslint-plugin-markdown",
"bugs": {
"url": "https://github.com/eslint/eslint-plugin-markdown/issues"
Expand All @@ -21,32 +31,27 @@
],
"scripts": {
"lint": "eslint .",
"prepare": "node ./npm-prepare.js",
"prepare": "node ./npm-prepare.cjs",
"release:generate:latest": "eslint-generate-release",
"release:generate:alpha": "eslint-generate-prerelease alpha",
"release:generate:beta": "eslint-generate-prerelease beta",
"release:generate:rc": "eslint-generate-prerelease rc",
"release:publish": "eslint-publish-release",
"test": "nyc _mocha -- -c tests/{examples,lib}/**/*.js --timeout 30000"
"test": "c8 mocha tests/**/*.test.js --timeout 30000"
nzakas marked this conversation as resolved.
Show resolved Hide resolved
},
"main": "index.js",
"files": [
"index.js",
"lib/index.js",
"lib/processor.js"
],
"devDependencies": {
"@eslint/core": "^0.2.0",
"@eslint/js": "^9.4.0",
"chai": "^4.2.0",
"c8": "^10.1.2",
"chai": "^5.1.1",
"eslint": "^9.4.0",
"eslint-config-eslint": "^11.0.0",
"eslint-release": "^3.1.2",
"globals": "^15.1.0",
"mocha": "^6.2.2",
"nyc": "^14.1.1"
"mocha": "^10.6.0"
},
"dependencies": {
"mdast-util-from-markdown": "^0.8.5"
"mdast-util-from-markdown": "^2.0.1"
},
"peerDependencies": {
"eslint": ">=8"
nzakas marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
6 changes: 2 additions & 4 deletions lib/index.js → src/index.js
mdjermanovic marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* @author Brandon Mills
*/

"use strict";

const processor = require("./processor");
import { processor } from "./processor.js";

const rulesConfig = {

Expand Down Expand Up @@ -100,4 +98,4 @@ plugin.configs.recommended = [
}
];

module.exports = plugin;
export default plugin;
8 changes: 3 additions & 5 deletions lib/processor.js → src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
* @typedef {ASTNode & BlockBase} Block
*/

"use strict";

const parse = require("mdast-util-from-markdown");
import { fromMarkdown } from "mdast-util-from-markdown";

const UNSATISFIABLE_RULES = new Set([
"eol-last", // The Markdown parser strips trailing newlines in code fences
Expand Down Expand Up @@ -248,7 +246,7 @@ const languageToFileExtension = {
* @returns {Array<{ filename: string, text: string }>} Source code blocks to lint.
*/
function preprocess(text, filename) {
const ast = parse(text);
const ast = fromMarkdown(text);
const blocks = [];

blocksCache.set(filename, blocks);
Expand Down Expand Up @@ -409,7 +407,7 @@ function postprocess(messages, filename) {
});
}

module.exports = {
export const processor = {
meta: {
name: "eslint-plugin-markdown/markdown",
version: "5.1.0" // x-release-please-version
Expand Down
17 changes: 10 additions & 7 deletions tests/examples/all.js → tests/examples/all.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"use strict";

const assert = require("chai").assert;
const fs = require("fs");
const path = require("path");
const semver = require("semver");
import { assert } from "chai";
import fs from "node:fs";
import path from "node:path";
import semver from "semver";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";

const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const examplesDir = path.resolve(__dirname, "../../examples/");
const examples = fs.readdirSync(examplesDir)
.filter(exampleDir => fs.statSync(path.join(examplesDir, exampleDir)).isDirectory())
Expand All @@ -14,7 +17,7 @@ for (const example of examples) {
const cwd = path.join(examplesDir, example);

// The plugin officially supports ESLint as early as v6, but the examples
// use ESLint v7, which has a higher minimum Node.js version than does v6.
// use ESLint v8, which has a higher minimum Node.js version than does v6.
// Only exercise the example if the running Node.js version satisfies the
// minimum version constraint. In CI, this will skip these tests in Node.js
// v8 and run them on all other Node.js versions.
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const markdown = require("../../");
const globals = require("globals");
import markdown from "../../src/index.js";
import globals from "globals";

module.exports = [
export default [
{
plugins: {
markdown
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/recommended.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const markdown = require("../../");
const js = require("@eslint/js")
import markdown from "../../src/index.js";
import js from "@eslint/js";

module.exports = [
export default [
js.configs.recommended,
...markdown.configs.recommended,
{
Expand Down
Loading