Skip to content

Commit

Permalink
Bump to 0.2.0 (ESM Migration)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
dependabot[bot] and JoyceZhu authored Jan 23, 2025
1 parent 8493df4 commit 607c420
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 150 deletions.
18 changes: 0 additions & 18 deletions .eslintrc.js

This file was deleted.

24 changes: 24 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": 2020
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"plugins": ["github"],
"extends": ["plugin:github/recommended"],
"rules": {
"filenames/match-regex": "off",
"i18n-text/no-en": "off",
"import/extensions": ["error", { "js": "ignorePackages"}],
"import/no-unresolved": [
"error",
{
"ignore": ["^markdownlint/.+"]
}
]
}
}
12 changes: 0 additions & 12 deletions .markdownlint-cli2.cjs

This file was deleted.

15 changes: 15 additions & 0 deletions .markdownlint-cli2.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { init } from "./index.js";

const configOptions = await init({
default: false,
"heading-increment": true,
"no-alt-text": true,
"single-h1": true,
"no-emphasis-as-heading": true,
"first-line-heading": true,
});
const options = {
config: configOptions,
customRules: ["./index.js"],
};
export default options;
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
18
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## 0.2.0

* BREAKING change: Convert to ECMAScript modules (ESM)

## 0.1.0

* Initial release
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ See [`markdownlint` rules](https://github.com/DavidAnson/markdownlint#rules--ali

**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.

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

```bash
touch .markdownlint-cli2.cjs
touch .markdownlint-cli2.mjs
```

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

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

```js
const options = require('@github/markdownlint-github').init()
module.exports = {
config: options,
import configOptions, {init} from "@github/markdownlint-github"
const options = {
config: init(),
customRules: ["@github/markdownlint-github"],
outputFormatters: [
[ "markdownlint-cli2-formatter-pretty", { "appendLink": true } ] // ensures the error message includes a link to the rule documentation
]
}
export default options
```
Or, you can also pass in configuration options that you wish to override the default. Read more at [Customizing configurations](#customizing-configurations).
Or, you can also pass in configuration options that you wish to override the default. Read more at [Customizing configurations](#customizing-configurations).
This looks like:
```js
const options = require('@github/markdownlint-github').init({
import configOptions, {init} from "@github/markdownlint-github"
const overriddenOptions = init({
'fenced-code-language': false, // Custom overrides
})
module.exports = {
config: options,
const options = {
config: overriddenOptions,
customRules: ["@github/markdownlint-github"],
outputFormatters: [
[ "markdownlint-cli2-formatter-pretty", { "appendLink": true } ]
]
}
export default options
```
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.
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.
### Customizing configurations
Expand All @@ -89,13 +92,15 @@ To review configurations supported by `markdownlint`, see [`markdownlint-cli2` c
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.
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:
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:
```js
module.exports = require('@github/markdownlint-github').init({
import configOptions, {init} from "@github/markdownlint-github"
const options = init({
"some-rule": true,
customRules: ["@github/markdownlint-github", "some-rule.js"],
})
export default options
```
See [`markdownlint-cli2` configuration](https://github.com/DavidAnson/markdownlint-cli2#configuration).
Expand All @@ -104,7 +109,8 @@ Consider upstreaming any rules you find useful as proposals to this repository.
## License
This project is licensed under the terms of the MIT open source license. Please refer to [MIT](./LICENSE.txt) for the full terms.
This project is licensed under the terms of the MIT open source license. Please
refer to [the MIT license](./LICENSE.txt) for the full terms.
## Maintainers
Expand Down
32 changes: 19 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
const _ = require("lodash");
import { readFile } from "fs/promises";
import _ from "lodash-es";
import { githubMarkdownLint } from "./src/rules/index.js";

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

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

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

for (const rule of gitHubCustomRules) {
const ruleName = rule.names[1];
base[ruleName] = offByDefault.includes(ruleName) ? false : true;
}
for (const rule of githubMarkdownLint) {
const ruleName = rule.names[1];
base[ruleName] = offByDefault.includes(ruleName) ? false : true;
}

module.exports.init = function init(consumerConfig) {
// left overwrites right
return _.defaultsDeep(consumerConfig, accessibilityRules, base);
};
}

export default githubMarkdownLint;
4 changes: 4 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"transform": {
}
}
68 changes: 27 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
{
"name": "@github/markdownlint-github",
"version": "0.1.0",
"version": "0.2.0",
"description": "An opinionated collection of markdownlint rules used by GitHub.",
"main": "index.js",
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=18"
},
"directories": {
"test": "test"
},
"scripts": {
"publish": "npm publish --access public --@github:registry=https://registry.npmjs.org",
"test": "npm run lint && jest",
"test": "npm run lint && NODE_OPTIONS=--experimental-vm-modules jest",
"lint": "markdownlint-cli2 \"**/*.{md,mdx}\" \"!node_modules\" \"!docs/rules\" \"!test/example.md\" && eslint .",
"lint:fix": "npm run lint -- --fix"
},
"dependencies": {
"lodash": "^4.17.15"
"lodash-es": "^4.17.15"
},
"devDependencies": {
"eslint": "^8.22.0",
"eslint-plugin-github": "^5.0.1",
"jest": "^29.5.0",
"markdownlint": "^0.36.1",
"markdownlint": "^0.37.3",
"markdownlint-cli2": "^0.17.1"
},
"repository": {
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/strip-and-downcase-text.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* Downcase and strip extra whitespaces and punctuation */
function stripAndDowncaseText(text) {
export function stripAndDowncaseText(text) {
return text
.toLowerCase()
.replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, "")
.replace(/\s+/g, " ")
.trim();
}

module.exports = { stripAndDowncaseText };
Loading

0 comments on commit 607c420

Please sign in to comment.