Skip to content

Commit 607c420

Browse files
Bump to 0.2.0 (ESM Migration)
* chore(deps-dev): bump markdownlint from 0.36.1 to 0.37.3 Bumps [markdownlint](https://github.com/DavidAnson/markdownlint) from 0.36.1 to 0.37.3. - [Changelog](https://github.com/DavidAnson/markdownlint/blob/main/CHANGELOG.md) - [Commits](DavidAnson/markdownlint@v0.36.1...v0.37.3) --- updated-dependencies: - dependency-name: markdownlint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * breaking: convert from CommonJS -> ESM * Update `README` with ESM examples * Update to version 0.2.0 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Joyce Zhu <[email protected]>
1 parent 8493df4 commit 607c420

23 files changed

+175
-150
lines changed

.eslintrc.js

-18
This file was deleted.

.eslintrc.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"root": true,
3+
"parserOptions": {
4+
"ecmaVersion": 2020
5+
},
6+
"env": {
7+
"es6": true,
8+
"node": true,
9+
"jest": true
10+
},
11+
"plugins": ["github"],
12+
"extends": ["plugin:github/recommended"],
13+
"rules": {
14+
"filenames/match-regex": "off",
15+
"i18n-text/no-en": "off",
16+
"import/extensions": ["error", { "js": "ignorePackages"}],
17+
"import/no-unresolved": [
18+
"error",
19+
{
20+
"ignore": ["^markdownlint/.+"]
21+
}
22+
]
23+
}
24+
}

.markdownlint-cli2.cjs

-12
This file was deleted.

.markdownlint-cli2.mjs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { init } from "./index.js";
2+
3+
const configOptions = await init({
4+
default: false,
5+
"heading-increment": true,
6+
"no-alt-text": true,
7+
"single-h1": true,
8+
"no-emphasis-as-heading": true,
9+
"first-line-heading": true,
10+
});
11+
const options = {
12+
config: configOptions,
13+
customRules: ["./index.js"],
14+
};
15+
export default options;

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14
1+
18

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
## 0.2.0
4+
5+
* BREAKING change: Convert to ECMAScript modules (ESM)
6+
7+
## 0.1.0
8+
9+
* Initial release

README.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ See [`markdownlint` rules](https://github.com/DavidAnson/markdownlint#rules--ali
2222

2323
**Important**: We support the use of `markdownlint` through [`markdownlint-cli2`](https://github.com/DavidAnson/markdownlint-cli2) instead of `markdownlint-cli` for compatibility with the [`vscode-markdownlint`](https://github.com/DavidAnson/vscode-markdownlint) plugin.
2424

25-
1. Create a `.markdownlint-cli2.cjs` file in the root of your repository.
25+
1. Create a `.markdownlint-cli2.mjs` file in the root of your repository.
2626

2727
```bash
28-
touch .markdownlint-cli2.cjs
28+
touch .markdownlint-cli2.mjs
2929
```
3030

3131
2. Install packages.
@@ -44,36 +44,39 @@ See [`markdownlint` rules](https://github.com/DavidAnson/markdownlint#rules--ali
4444
}
4545
```
4646

47-
4. Edit `.markdownlint-cli2.cjs` file to suit your needs. Start with
47+
4. Edit `.markdownlint-cli2.mjs` file to suit your needs. Start with
4848

4949
```js
50-
const options = require('@github/markdownlint-github').init()
51-
module.exports = {
52-
config: options,
50+
import configOptions, {init} from "@github/markdownlint-github"
51+
const options = {
52+
config: init(),
5353
customRules: ["@github/markdownlint-github"],
5454
outputFormatters: [
5555
[ "markdownlint-cli2-formatter-pretty", { "appendLink": true } ] // ensures the error message includes a link to the rule documentation
5656
]
5757
}
58+
export default options
5859
```
5960
60-
Or, you can also pass in configuration options that you wish to override the default. Read more at [Customizing configurations](#customizing-configurations).
61+
Or, you can also pass in configuration options that you wish to override the default. Read more at [Customizing configurations](#customizing-configurations).
6162
This looks like:
6263
6364
```js
64-
const options = require('@github/markdownlint-github').init({
65+
import configOptions, {init} from "@github/markdownlint-github"
66+
const overriddenOptions = init({
6567
'fenced-code-language': false, // Custom overrides
6668
})
67-
module.exports = {
68-
config: options,
69+
const options = {
70+
config: overriddenOptions,
6971
customRules: ["@github/markdownlint-github"],
7072
outputFormatters: [
7173
[ "markdownlint-cli2-formatter-pretty", { "appendLink": true } ]
7274
]
7375
}
76+
export default options
7477
```
7578
76-
5. Install the [`vscode-markdownlint`](https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint) plugin to ensure `markdownlint` violations are surfaced in the file. This plugin should flag rules based off your `.markdownlint-cli2.cjs` configuration. When you make edits to your configuration, you will need to reload the VSCode window (`Ctrl+Shift+P` -> `Reload Window`) to ensure the extension syncs. If your project runs on Codespaces, consider adding this extension to your `.devcontainer/devcontainer.json` so that this extension is installed to new Codespaces by default.
79+
5. Install the [`vscode-markdownlint`](https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint) plugin to ensure `markdownlint` violations are surfaced in the file. This plugin should flag rules based off your `.markdownlint-cli2.mjs` configuration. When you make edits to your configuration, you will need to reload the VSCode window (`Ctrl+Shift+P` -> `Reload Window`) to ensure the extension syncs. If your project runs on Codespaces, consider adding this extension to your `.devcontainer/devcontainer.json` so that this extension is installed to new Codespaces by default.
7780
7881
### Customizing configurations
7982
@@ -89,13 +92,15 @@ To review configurations supported by `markdownlint`, see [`markdownlint-cli2` c
8992
9093
You may write custom rules within your repository. Follow the [custom rules guide in `markdownlint`](https://github.com/DavidAnson/markdownlint/blob/main/doc/CustomRules.md) to write your rule.
9194
92-
The rule will need to be enabled in the configuration. For instance, if you introduce `some-rule.js` with the name "some-rule", you must set the path of the custom rule in the `.markdownlint-cli2.cjs` file:
95+
The rule will need to be enabled in the configuration. For instance, if you introduce `some-rule.js` with the name "some-rule", you must set the path of the custom rule in the `.markdownlint-cli2.mjs` file:
9396
9497
```js
95-
module.exports = require('@github/markdownlint-github').init({
98+
import configOptions, {init} from "@github/markdownlint-github"
99+
const options = init({
96100
"some-rule": true,
97101
customRules: ["@github/markdownlint-github", "some-rule.js"],
98102
})
103+
export default options
99104
```
100105
101106
See [`markdownlint-cli2` configuration](https://github.com/DavidAnson/markdownlint-cli2#configuration).
@@ -104,7 +109,8 @@ Consider upstreaming any rules you find useful as proposals to this repository.
104109
105110
## License
106111
107-
This project is licensed under the terms of the MIT open source license. Please refer to [MIT](./LICENSE.txt) for the full terms.
112+
This project is licensed under the terms of the MIT open source license. Please
113+
refer to [the MIT license](./LICENSE.txt) for the full terms.
108114
109115
## Maintainers
110116

index.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
const _ = require("lodash");
1+
import { readFile } from "fs/promises";
2+
import _ from "lodash-es";
3+
import { githubMarkdownLint } from "./src/rules/index.js";
24

3-
const accessibilityRules = require("./style/accessibility.json");
4-
const base = require("./style/base.json");
5-
const gitHubCustomRules = require("./src/rules/index").rules;
5+
const offByDefault = ["no-empty-alt-text"];
66

7-
module.exports = [...gitHubCustomRules];
7+
export async function init(consumerConfig) {
8+
// left overwrites right
9+
const accessibilityRules = JSON.parse(
10+
await readFile(new URL("./style/accessibility.json", import.meta.url)),
11+
);
812

9-
const offByDefault = ["no-empty-alt-text"];
13+
const base = JSON.parse(
14+
await readFile(new URL("./style/base.json", import.meta.url)),
15+
);
1016

11-
for (const rule of gitHubCustomRules) {
12-
const ruleName = rule.names[1];
13-
base[ruleName] = offByDefault.includes(ruleName) ? false : true;
14-
}
17+
for (const rule of githubMarkdownLint) {
18+
const ruleName = rule.names[1];
19+
base[ruleName] = offByDefault.includes(ruleName) ? false : true;
20+
}
1521

16-
module.exports.init = function init(consumerConfig) {
17-
// left overwrites right
1822
return _.defaultsDeep(consumerConfig, accessibilityRules, base);
19-
};
23+
}
24+
25+
export default githubMarkdownLint;

jest.config.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"transform": {
3+
}
4+
}

package-lock.json

+27-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
{
22
"name": "@github/markdownlint-github",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "An opinionated collection of markdownlint rules used by GitHub.",
5-
"main": "index.js",
5+
"type": "module",
6+
"exports": "./index.js",
7+
"engines": {
8+
"node": ">=18"
9+
},
610
"directories": {
711
"test": "test"
812
},
913
"scripts": {
1014
"publish": "npm publish --access public --@github:registry=https://registry.npmjs.org",
11-
"test": "npm run lint && jest",
15+
"test": "npm run lint && NODE_OPTIONS=--experimental-vm-modules jest",
1216
"lint": "markdownlint-cli2 \"**/*.{md,mdx}\" \"!node_modules\" \"!docs/rules\" \"!test/example.md\" && eslint .",
1317
"lint:fix": "npm run lint -- --fix"
1418
},
1519
"dependencies": {
16-
"lodash": "^4.17.15"
20+
"lodash-es": "^4.17.15"
1721
},
1822
"devDependencies": {
1923
"eslint": "^8.22.0",
2024
"eslint-plugin-github": "^5.0.1",
2125
"jest": "^29.5.0",
22-
"markdownlint": "^0.36.1",
26+
"markdownlint": "^0.37.3",
2327
"markdownlint-cli2": "^0.17.1"
2428
},
2529
"repository": {
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/* Downcase and strip extra whitespaces and punctuation */
2-
function stripAndDowncaseText(text) {
2+
export function stripAndDowncaseText(text) {
33
return text
44
.toLowerCase()
55
.replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, "")
66
.replace(/\s+/g, " ")
77
.trim();
88
}
9-
10-
module.exports = { stripAndDowncaseText };

0 commit comments

Comments
 (0)