Skip to content

Commit 67812e8

Browse files
Trotttargos
authored andcommittedOct 4, 2021
tools: re-implement lint-md without unified-args
`unified-args` ignores settings in the preset, expecting them to be in remarkrc files or passed on the command line instead. Realizing that we always send the same configuration options via the command-line anyway, this removes `unified-args`. This means the preset settings are now respected and it removes nearly 30000 lines of code in the resulting rollup file. I wasn't sure I was going to want to keep rollup so I started re-implementing this without it, but ended up putting a minimal rollup back as it still saves about 90000 lines of code vs. checking in `node_modules`. PR-URL: #40180 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6489423 commit 67812e8

15 files changed

+22658
-51162
lines changed
 

‎.eslintignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ test/addons/??_*
44
test/fixtures
55
test/message/esm_display_syntax_error.mjs
66
tools/icu
7-
tools/lint-md.mjs
8-
tools/node-lint-md-cli-rollup/dist
7+
tools/lint-md/lint-md.mjs
98
benchmark/tmp
109
doc/**/*.js
1110
!.eslintrc.js

‎.github/workflows/linters.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Get release version numbers
5656
if: ${{ github.event.pull_request && github.event.pull_request.base.ref == github.event.pull_request.base.repo.default_branch }}
5757
id: get-released-versions
58-
run: ./tools/node-lint-md-cli-rollup/src/list-released-versions-from-changelogs.mjs
58+
run: ./tools/lint-md/list-released-versions-from-changelogs.mjs
5959
- name: Lint docs
6060
run: |
6161
echo "::add-matcher::.github/workflows/remark-lint-problem-matcher.json"

‎Makefile

+3-4
Original file line numberDiff line numberDiff line change
@@ -1221,12 +1221,11 @@ bench-addons-clean:
12211221
.PHONY: lint-md-rollup
12221222
lint-md-rollup:
12231223
$(RM) tools/.*mdlintstamp
1224-
cd tools/node-lint-md-cli-rollup && npm install
1225-
cd tools/node-lint-md-cli-rollup && npm run build-node
1224+
cd tools/lint-md && npm ci && npm run build
12261225

12271226
.PHONY: lint-md-clean
12281227
lint-md-clean:
1229-
$(RM) -r tools/node-lint-md-cli-rollup/node_modules
1228+
$(RM) -r tools/lint-md/node_modules
12301229
$(RM) tools/.*mdlintstamp
12311230

12321231
.PHONY: lint-md-build
@@ -1243,7 +1242,7 @@ LINT_MD_TARGETS = doc src lib benchmark test tools/doc tools/icu $(wildcard *.md
12431242
LINT_MD_FILES = $(shell $(FIND) $(LINT_MD_TARGETS) -type f \
12441243
! -path '*node_modules*' ! -path 'test/fixtures/*' -name '*.md' \
12451244
$(LINT_MD_NEWER))
1246-
run-lint-md = tools/lint-md.mjs -q -f --no-stdout $(LINT_MD_FILES)
1245+
run-lint-md = tools/lint-md/lint-md.mjs $(LINT_MD_FILES)
12471246
# Lint all changed markdown files maintained by us
12481247
tools/.mdlintstamp: $(LINT_MD_FILES)
12491248
$(info Running Markdown linter...)

‎tools/lint-md/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

‎tools/lint-md.mjs renamed to ‎tools/lint-md/lint-md.mjs

+22,489-49,567
Large diffs are not rendered by default.

‎tools/lint-md/lint-md.src.mjs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { unified } from 'unified';
2+
import remarkParse from 'remark-parse';
3+
import remarkStringify from 'remark-stringify';
4+
import presetLintNode from 'remark-preset-lint-node';
5+
import gfm from 'remark-gfm';
6+
import { read } from 'to-vfile';
7+
import { reporter } from 'vfile-reporter';
8+
9+
const paths = process.argv.slice(2);
10+
11+
const linter = unified()
12+
.use(remarkParse)
13+
.use(gfm)
14+
.use(presetLintNode)
15+
.use(remarkStringify);
16+
17+
paths.forEach(async (path) => {
18+
const file = await read(path);
19+
const result = await linter.process(file);
20+
if (result.messages.length) {
21+
process.exitCode = 1;
22+
console.error(reporter(result));
23+
}
24+
// TODO: allow reformatting by writing `String(result)` to the input file
25+
});

‎tools/node-lint-md-cli-rollup/src/list-released-versions-from-changelogs.mjs renamed to ‎tools/lint-md/list-released-versions-from-changelogs.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import fs from 'node:fs';
44
import { createInterface } from 'node:readline';
55

6-
const dataFolder = new URL('../../../doc/changelogs/', import.meta.url);
6+
const dataFolder = new URL('../../doc/changelogs/', import.meta.url);
77

88
const result = [];
99
async function getVersionsFromFile(file) {

‎tools/node-lint-md-cli-rollup/package-lock.json renamed to ‎tools/lint-md/package-lock.json

+114-1,443
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tools/lint-md/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "lint-md",
3+
"description": "markdown linting",
4+
"version": "1.0.0",
5+
"scripts": {
6+
"build": "rollup -f es -p '@rollup/plugin-node-resolve={exportConditions: [\"node\"]}' -p @rollup/plugin-commonjs lint-md.src.mjs --file lint-md.mjs"
7+
},
8+
"dependencies": {
9+
"remark-gfm": "^2.0.0",
10+
"remark-parse": "^10.0.0",
11+
"remark-preset-lint-node": "^3.0.1",
12+
"remark-stringify": "^10.0.0",
13+
"to-vfile": "^7.2.2",
14+
"unified": "^10.1.0",
15+
"vfile-reporter": "^7.0.2"
16+
},
17+
"devDependencies": {
18+
"@rollup/plugin-commonjs": "^20.0.0",
19+
"@rollup/plugin-node-resolve": "^13.0.5",
20+
"rollup": "^2.57.0"
21+
}
22+
}

‎tools/node-lint-md-cli-rollup/.gitignore

-3
This file was deleted.

‎tools/node-lint-md-cli-rollup/LICENSE

-32
This file was deleted.

‎tools/node-lint-md-cli-rollup/package.json

-24
This file was deleted.

‎tools/node-lint-md-cli-rollup/rollup.config.js

-57
This file was deleted.

‎tools/node-lint-md-cli-rollup/src/cli-entry.mjs

-27
This file was deleted.

‎vcbuild.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ for /D %%D IN (doc\*) do (
722722
set "lint_md_files="%%F" !lint_md_files!"
723723
)
724724
)
725-
%node_exe% tools\lint-md.mjs -q -f %lint_md_files%
725+
%node_exe% tools\lint-md\lint-md.mjs %lint_md_files%
726726
ENDLOCAL
727727
goto exit
728728

0 commit comments

Comments
 (0)
Please sign in to comment.