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

tools: introduce make mdlint command and tools #12756

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ deps/npm/node_modules/.bin/

# test artifacts
tools/faketime
tools/remark-cli
tools/remark-preset-lint-node
icu_config.gypi
*.tap

Expand Down
64 changes: 3 additions & 61 deletions .remarkrc
Original file line number Diff line number Diff line change
@@ -1,63 +1,5 @@
{
"plugins": {
"remark-lint/": {
"blockquote-indentation": 2,
"checkbox-character-style": { "checked": "x", "unchecked": " " },
"checkbox-content-indent": true,
"code-block-style": "fenced",
"definition-case": false,
"definition-spacing": true,
"emphasis-marker": false,
"fenced-code-flag": true,
"fenced-code-marker": "`",
"file-extension": "md",
"final-definition": true,
"final-newline": true,
"first-heading-level": 1,
"hard-break-spaces": true,
"heading-increment": false,
"heading-style": "atx",
"link-title-style": false,
"list-item-bullet-indent": false,
"list-item-content-indent": false,
"list-item-indent": false,
"list-item-spacing": false,
"maximum-heading-length": false,
"maximum-line-length": false,
"no-auto-link-without-protocol": true,
"no-blockquote-without-caret": true,
"no-consecutive-blank-lines": false,
"no-duplicate-definitions": true,
"no-duplicate-headings": false,
"no-emphasis-as-heading": false,
"no-file-name-articles": true,
"no-file-name-consecutive-dashes": true,
"no-file-name-irregular-characters": false,
"no-file-name-mixed-case": false,
"no-file-name-outer-dashes": true,
"no-heading-content-indent": true,
"no-heading-indent": true,
"no-heading-punctuation": false,
"no-html": false,
"no-inline-padding": true,
"no-literal-urls": false,
"no-missing-blank-lines": false,
"no-multiple-toplevel-headings": true,
"no-shell-dollars": true,
"no-shortcut-reference-image": true,
"no-shortcut-reference-link": false,
"no-table-indentation": true,
"no-tabs": true,
"no-undefined-references": false,
"no-unused-definitions": true,
"ordered-list-marker-style": false,
"ordered-list-marker-value": false,
"rule-style": true,
"strong-marker": "*",
"table-cell-padding": "padded",
"table-pipe-alignment": false,
"table-pipes": true,
"unordered-list-marker-style": false
}
}
"plugins": [
"./tools/remark-preset-lint-node/"
]
}
23 changes: 21 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ $(TARBALL): release-only $(NODE_EXE) doc
$(RM) -r $(TARNAME)/deps/openssl/openssl/{doc,demos,test}
$(RM) -r $(TARNAME)/deps/zlib/contrib # too big, unused
$(RM) -r $(TARNAME)/.{editorconfig,git*,mailmap}
$(RM) -r $(TARNAME)/tools/{eslint,eslint-rules,osx-pkg.pmdoc,pkgsrc}
$(RM) -r $(TARNAME)/tools/{eslint,eslint-rules,osx-pkg.pmdoc,pkgsrc,remark-cli,remark-preset-lint-node}
$(RM) -r $(TARNAME)/tools/{osx-*,license-builder.sh,cpplint.py}
$(RM) -r $(TARNAME)/test*.tap
find $(TARNAME)/ -name ".eslint*" -maxdepth 2 | xargs $(RM)
Expand Down Expand Up @@ -945,6 +945,21 @@ bench: bench-net bench-http bench-fs bench-tls

bench-ci: bench

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably edit the $(TARBALL) target as well, to exclude the tools/remark*

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right! I added it on L717.

lint-md-clean:
$(RM) -r tools/remark-cli/node_modules
$(RM) -r tools/remark-preset-lint-node/node_modules

lint-md-build:
if [ ! -d tools/remark-cli/node_modules ]; then \
cd tools/remark-cli && ../../$(NODE) ../../$(NPM) install; fi
if [ ! -d tools/remark-preset-lint-node/node_modules ]; then \
cd tools/remark-preset-lint-node && ../../$(NODE) ../../$(NPM) install; fi

lint-md: lint-md-build
@echo "Running Markdown linter..."
$(NODE) tools/remark-cli/cli.js -q -f \
./*.md doc src lib benchmark tools/doc/ tools/icu/

LINT_JS_TARGETS = benchmark doc lib test tools

lint-js:
Expand Down Expand Up @@ -1002,9 +1017,10 @@ lint:
@EXIT_STATUS=0 ; \
$(MAKE) lint-js || EXIT_STATUS=$$? ; \
$(MAKE) lint-cpp || EXIT_STATUS=$$? ; \
$(MAKE) lint-md || EXIT_STATUS=$$? ; \
exit $$EXIT_STATUS
CONFLICT_RE=^>>>>>>> [0-9A-Fa-f]+|^<<<<<<< [A-Za-z]+
lint-ci: lint-js-ci lint-cpp
lint-ci: lint-js-ci lint-cpp lint-md
@if ! ( grep -IEqrs "$(CONFLICT_RE)" benchmark deps doc lib src test tools ) \
&& ! ( find . -maxdepth 1 -type f | xargs grep -IEqs "$(CONFLICT_RE)" ); then \
exit 0 ; \
Expand Down Expand Up @@ -1067,6 +1083,9 @@ endif
lint-js \
lint-js-ci \
list-gtests \
lint-md \
lint-md-build \
lint-md-clean \
pkg \
release-only \
run-ci \
Expand Down
34 changes: 34 additions & 0 deletions tools/remark-cli/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module remark:cli
* @fileoverview CLI to process markdown.
*/

'use strict';

/* Dependencies. */
var start = require('unified-args');
var extensions = require('markdown-extensions');
var processor = require('remark');
var proc = require('remark/package.json');
var cli = require('./package.json');

/* Start. */
start({
processor: processor,
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
});
32 changes: 32 additions & 0 deletions tools/remark-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "remark-cli",
"version": "3.0.1",
"description": "CLI to process markdown with remark using plugins",
"license": "MIT",
"keywords": [
"markdown",
"remark",
"cli",
"bin"
],
"dependencies": {
"markdown-extensions": "^1.1.0",
"remark": "^7.0.0",
"unified-args": "^3.0.0"
},
"homepage": "http://remark.js.org",
"repository": "https://github.com/wooorm/remark/tree/master/packages/remark-cli",
"bugs": "https://github.com/wooorm/remark/issues",
"author": "Titus Wormer <[email protected]> (http://wooorm.com)",
"contributors": [
"Titus Wormer <[email protected]> (http://wooorm.com)"
],
"bin": {
"remark": "cli.js"
},
"files": [
"cli.js"
],
"scripts": {},
"xo": false
}
111 changes: 111 additions & 0 deletions tools/remark-cli/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# remark-cli [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]

Command-line interface for [**remark**][remark].

* Loads [`remark-` plugins][plugins]
* Searches for [markdown extensions][markdown-extensions]
* Ignores paths found in [`.remarkignore` files][ignore-file]
* Loads configuration from [`.remarkrc`, `.remarkrc.js` files][config-file]
* Uses configuration from [`remarkConfig` fields in `package.json`
files][config-file]

## Installation

[npm][]:

```sh
npm install remark-cli
```

## Usage

```sh
# Add a table of contents to `readme.md`
$ remark readme.md --use toc --output

# Lint markdown files in the current directory
# according to the markdown style guide.
$ remark . --use preset-lint-markdown-style-guide
```

## CLI

See [**unified-args**][unified-args], which provides the interface,
for more information on all available options.

```txt
Usage: remark [options] [path | glob ...]

CLI to process markdown with remark using plugins

Options:

-h --help output usage information
-v --version output version number
-o --output [path] specify output location
-r --rc-path <path> specify configuration file
-i --ignore-path <path> specify ignore file
-s --setting <settings> specify settings
-e --ext <extensions> specify extensions
-u --use <plugins> use plugins
-p --preset <presets> use presets
-w --watch watch for changes and reprocess
-q --quiet output only warnings and errors
-S --silent output only errors
-f --frail exit with 1 on warnings
-t --tree specify input and output as syntax tree
--file-path <path> specify path to process as
--tree-in specify input as syntax tree
--tree-out output syntax tree
--[no-]stdout specify writing to stdout (on by default)
--[no-]color specify color in report (on by default)
--[no-]config search for configuration files (on by default)
--[no-]ignore search for ignore files (on by default)

Examples:

# Process `input.md`
$ remark input.md -o output.md

# Pipe
$ remark < input.md > output.md

# Rewrite all applicable files
$ remark . -o
```

## License

[MIT][license] © [Titus Wormer][author]

<!-- Definitions -->

[build-badge]: https://img.shields.io/travis/wooorm/remark.svg

[build-status]: https://travis-ci.org/wooorm/remark

[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/remark.svg

[coverage-status]: https://codecov.io/github/wooorm/remark

[chat-badge]: https://img.shields.io/gitter/room/wooorm/remark.svg

[chat]: https://gitter.im/wooorm/remark

[license]: https://github.com/wooorm/remark/blob/master/LICENSE

[author]: http://wooorm.com

[npm]: https://docs.npmjs.com/cli/install

[remark]: https://github.com/wooorm/remark

[plugins]: https://github.com/wooorm/remark/blob/master/doc/plugins.md

[markdown-extensions]: https://github.com/sindresorhus/markdown-extensions

[config-file]: https://github.com/wooorm/unified-engine/blob/master/doc/configure.md

[ignore-file]: https://github.com/wooorm/unified-engine/blob/master/doc/ignore.md

[unified-args]: https://github.com/wooorm/unified-args#cli
44 changes: 44 additions & 0 deletions tools/remark-preset-lint-node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// @see https://github.com/nodejs/node/blob/master/doc/STYLE_GUIDE.md

'use strict';

module.exports.plugins = [
require('remark-lint'),
require('remark-lint-checkbox-content-indent'),
require('remark-lint-definition-spacing'),
require('remark-lint-fenced-code-flag'),
require('remark-lint-final-definition'),
require('remark-lint-final-newline'),
require('remark-lint-hard-break-spaces'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are trailing spaces (necessary for this rule) possible in our docs? Should they be eliminated but properly configured git on committing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was possible but apply.whitespace=fix strips trailing white spaces when running git apply or git am
IMHO https://stackoverflow.com/questions/39752867/git-ignore-trailing-whitespace-in-markdown-files-only is a valid solution

 .gitattributes | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitattributes b/.gitattributes
index fa5162684b..ad2efae71b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,2 +1,3 @@
 test/fixtures/* -text
 vcbuild.bat text eol=crlf
+**/*.md  whitespace=-trailing-space,space-before-tab,-indent-with-non-tab,tab-in-indent,cr-at-eol

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe <br> would be a simpler solution for hard breaks?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we have no trailing spaces in docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we do | git am -3 --whitespace=fix and have killed them all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I mean if we manage without trailing spaces so far, may be it is not worth to bring them in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.
Lint out all trailing spaces.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a pity that remark-lint-no-trailing-spaces "has not been updates for remark-lint 6.0.0". Can we still use it?

require('remark-lint-no-auto-link-without-protocol'),
require('remark-lint-no-blockquote-without-caret'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require('remark-lint-no-duplicate-definitions'),
require('remark-lint-no-file-name-articles'),
require('remark-lint-no-file-name-consecutive-dashes'),
require('remark-lint-no-file-name-outer-dashes'),
require('remark-lint-no-heading-content-indent'),
require('remark-lint-no-heading-indent'),
require('remark-lint-no-inline-padding'),
require('remark-lint-no-multiple-toplevel-headings'),
require('remark-lint-no-shell-dollars'),
require('remark-lint-no-shortcut-reference-image'),
require('remark-lint-no-table-indentation'),
require('remark-lint-no-tabs'),
require('remark-lint-no-unused-definitions'),
require('remark-lint-rule-style'),
require('remark-lint-table-pipes'),
[require('remark-lint-blockquote-indentation'), 2],
[
require('remark-lint-checkbox-character-style'),
{
'checked': 'x', 'unchecked': ' '
}
],
[require('remark-lint-code-block-style'), 'fenced'],
[require('remark-lint-fenced-code-marker'), '`'],
[require('remark-lint-file-extension'), 'md'],
[require('remark-lint-first-heading-level'), 1],
[require('remark-lint-heading-style'), 'atx'],
[require('remark-lint-strong-marker'), '*'],
[require('remark-lint-table-cell-padding'), 'padded']
];
42 changes: 42 additions & 0 deletions tools/remark-preset-lint-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"private": true,
"name": "remark-preset-lint-node",
"version": "1.0.0",
"description": "remark preset to configure remark-lint with settings for nodejs/node",
"main": "index.js",
"dependencies": {
"remark-lint": "^6.0.0",
"remark-lint-blockquote-indentation": "^1.0.0",
"remark-lint-checkbox-character-style": "^1.0.0",
"remark-lint-checkbox-content-indent": "^1.0.0",
"remark-lint-code-block-style": "^1.0.0",
"remark-lint-definition-spacing": "^1.0.0",
"remark-lint-fenced-code-flag": "^1.0.0",
"remark-lint-fenced-code-marker": "^1.0.0",
"remark-lint-file-extension": "^1.0.0",
"remark-lint-final-definition": "^1.0.0",
"remark-lint-final-newline": "^1.0.0",
"remark-lint-first-heading-level": "^1.0.0",
"remark-lint-hard-break-spaces": "^1.0.1",
"remark-lint-heading-style": "^1.0.0",
"remark-lint-no-auto-link-without-protocol": "^1.0.0",
"remark-lint-no-blockquote-without-caret": "^1.0.0",
"remark-lint-no-duplicate-definitions": "^1.0.0",
"remark-lint-no-file-name-articles": "^1.0.0",
"remark-lint-no-file-name-consecutive-dashes": "^1.0.0",
"remark-lint-no-file-name-outer-dashes": "^1.0.0",
"remark-lint-no-heading-content-indent": "^1.0.0",
"remark-lint-no-heading-indent": "^1.0.0",
"remark-lint-no-inline-padding": "^1.0.0",
"remark-lint-no-multiple-toplevel-headings": "^1.0.0",
"remark-lint-no-shell-dollars": "^1.0.0",
"remark-lint-no-shortcut-reference-image": "^1.0.0",
"remark-lint-no-table-indentation": "^1.0.0",
"remark-lint-no-tabs": "^1.0.0",
"remark-lint-no-unused-definitions": "^1.0.0",
"remark-lint-rule-style": "^1.0.0",
"remark-lint-strong-marker": "^1.0.0",
"remark-lint-table-cell-padding": "^1.0.0",
"remark-lint-table-pipes": "^1.0.0"
}
}