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: https://github.com/nodejs/node/pull/40180
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Rich Trott authored and Node.js GitHub Bot committed 2021-09-25 03:51:52 +00:00
1 parent 80065865be
commit 8d83c47029
15 files changed
+5692 -34196

No files matched your search

+1 -2
View File
@@ -4,8 +4,7 @@ test/addons/??_*
test/fixtures
test/message/esm_display_syntax_error.mjs
tools/icu
tools/lint-md.mjs
tools/node-lint-md-cli-rollup/dist
tools/lint-md/lint-md.mjs
benchmark/tmp
doc/**/*.js
!.eslintrc.js
+1 -1
View File
@@ -55,7 +55,7 @@ jobs:
- name: Get release version numbers
if: ${{ github.event.pull_request && github.event.pull_request.base.ref == github.event.pull_request.base.repo.default_branch }}
id: get-released-versions
run: ./tools/node-lint-md-cli-rollup/src/list-released-versions-from-changelogs.mjs
run: ./tools/lint-md/list-released-versions-from-changelogs.mjs
- name: Lint docs
run: |
echo "::add-matcher::.github/workflows/remark-lint-problem-matcher.json"
+3 -4
View File
@@ -1221,12 +1221,11 @@ bench-addons-clean:
.PHONY: lint-md-rollup
lint-md-rollup:
$(RM) tools/.*mdlintstamp
cd tools/node-lint-md-cli-rollup && npm install
cd tools/node-lint-md-cli-rollup && npm run build-node
cd tools/lint-md && npm ci && npm run build
.PHONY: lint-md-clean
lint-md-clean:
$(RM) -r tools/node-lint-md-cli-rollup/node_modules
$(RM) -r tools/lint-md/node_modules
$(RM) tools/.*mdlintstamp
.PHONY: lint-md-build
@@ -1243,7 +1242,7 @@ LINT_MD_TARGETS = doc src lib benchmark test tools/doc tools/icu $(wildcard *.md
LINT_MD_FILES = $(shell $(FIND) $(LINT_MD_TARGETS) -type f \
! -path '*node_modules*' ! -path 'test/fixtures/*' -name '*.md' \
$(LINT_MD_NEWER))
run-lint-md = tools/lint-md.mjs -q -f --no-stdout $(LINT_MD_FILES)
run-lint-md = tools/lint-md/lint-md.mjs $(LINT_MD_FILES)
# Lint all changed markdown files maintained by us
tools/.mdlintstamp: $(LINT_MD_FILES)
$(info Running Markdown linter...)
+1
View File
@@ -0,0 +1 @@
node_modules
File diff suppressed because it is too large. Load diff
+25
View File
@@ -0,0 +1,25 @@
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import presetLintNode from 'remark-preset-lint-node';
import gfm from 'remark-gfm';
import { read } from 'to-vfile';
import { reporter } from 'vfile-reporter';
const paths = process.argv.slice(2);
const linter = unified()
.use(remarkParse)
.use(gfm)
.use(presetLintNode)
.use(remarkStringify);
paths.forEach(async (path) => {
const file = await read(path);
const result = await linter.process(file);
if (result.messages.length) {
process.exitCode = 1;
console.error(reporter(result));
}
// TODO: allow reformatting by writing `String(result)` to the input file
});
@@ -3,7 +3,7 @@
import fs from 'node:fs';
import { createInterface } from 'node:readline';
const dataFolder = new URL('../../../doc/changelogs/', import.meta.url);
const dataFolder = new URL('../../doc/changelogs/', import.meta.url);
const result = [];
async function getVersionsFromFile(file) {
File diff suppressed because it is too large. Load diff
+22
View File
@@ -0,0 +1,22 @@
{
"name": "lint-md",
"description": "markdown linting",
"version": "1.0.0",
"scripts": {
"build": "rollup -f es -p '@rollup/plugin-node-resolve={exportConditions: [\"node\"]}' -p @rollup/plugin-commonjs lint-md.src.mjs --file lint-md.mjs"
},
"dependencies": {
"remark-gfm": "^2.0.0",
"remark-parse": "^10.0.0",
"remark-preset-lint-node": "^3.0.1",
"remark-stringify": "^10.0.0",
"to-vfile": "^7.2.2",
"unified": "^10.1.0",
"vfile-reporter": "^7.0.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-node-resolve": "^13.0.5",
"rollup": "^2.57.0"
}
}
-3
View File
@@ -1,3 +0,0 @@
/node_modules/
/remark-preset-lint-node/node_modules/
/dist/
-32
View File
@@ -1,32 +0,0 @@
Copyright (c) 2018 Refael Ackermann<refack@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---
(The MIT License for `remark` https://github.com/remarkjs/remark/blob/master/LICENSE)
Copyright (c) 2014-2016 Titus Wormer <tituswormer@gmail.com>
Copyright (c) 2011-2014, Christopher Jeffrey (https://github.com/chjj/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -1,24 +0,0 @@
{
"name": "node-lint-md-cli-rollup",
"description": "remark packaged for Node.js Markdown linting",
"version": "2.0.2",
"devDependencies": {
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"rollup": "^2.56.3",
"shx": "^0.3.3"
},
"dependencies": {
"markdown-extensions": "^1.1.1",
"remark": "^14.0.1",
"remark-gfm": "^2.0.0",
"remark-preset-lint-node": "^3.0.1",
"unified-args": "^9.0.2"
},
"main": "dist/index.js",
"scripts": {
"build": "npx rollup -c",
"build-node": "npm run build && npx shx cp dist/index.mjs ../lint-md.mjs"
}
}
@@ -1,57 +0,0 @@
'use strict';
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const json = require('@rollup/plugin-json');
module.exports = {
input: 'src/cli-entry.mjs',
output: {
file: 'dist/index.mjs',
format: 'es',
sourcemap: false,
exports: 'none',
},
external: [
'node:events',
'node:fs',
'node:path',
'node:process',
'node:stream',
'node:url',
],
plugins: [
{
name: 'brute-replace',
transform(code, id) {
const normID = id.replace(__dirname, '').replace(/\\+/g, '/');
if (normID === '/node_modules/concat-stream/index.js') {
return code.replace('\'readable-stream\'', '\'stream\'');
}
if (normID === '/node_modules/unified-args/lib/options.js') {
return code.replace('\'./schema\'', '\'./schema.json\'');
}
if (normID === '/node_modules/chokidar/lib/fsevents-handler.js') {
return code.replace(
'fsevents = require(\'fsevents\');', 'fsevents = undefined;'
);
}
// Remove circular dependency in glob that messes up rollup
return code.replace("var Glob = require('./glob.js').Glob", '');
}
},
json({
preferConst: true
}),
nodeResolve({ exportConditions: ['node'] }),
commonjs(),
{
name: 'banner',
renderChunk(code) {
const banner = '// Don\'t change this file manually,\n' +
'// it is generated from tools/node-lint-md-cli-rollup';
return code.replace('\'use strict\';', '\'use strict\';\n\n' + banner);
}
},
]
};
@@ -1,27 +0,0 @@
// To aid in future maintenance, this layout closely matches remark-cli/cli.js.
// https://github.com/remarkjs/remark/blob/HEAD/packages/remark-cli/cli.js
import { args } from 'unified-args';
import extensions from 'markdown-extensions';
import { remark } from 'remark';
import proc from 'remark/package.json';
import cli from '../package.json';
import lintNode from 'remark-preset-lint-node';
import gfm from 'remark-gfm';
args({
processor: remark().use(gfm).use(lintNode),
name: proc.name,
description: cli.description,
version: [
proc.name + ': ' + proc.version,
cli.name + ': ' + cli.version,
].join(', '),
pluginPrefix: proc.name,
presetPrefix: proc.name + '-preset',
packageField: proc.name + 'Config',
rcName: '.' + proc.name + 'rc',
ignoreName: '.' + proc.name + 'ignore',
extensions: extensions,
detectConfig: false,
});
+1 -1
View File
@@ -722,7 +722,7 @@ for /D %%D IN (doc\*) do (
set "lint_md_files="%%F" !lint_md_files!"
)
)
%node_exe% tools\lint-md.mjs -q -f %lint_md_files%
%node_exe% tools\lint-md\lint-md.mjs %lint_md_files%
ENDLOCAL
goto exit