diff --git a/.gitignore b/.gitignore index 72ccaddaceb4f5..922ef6733e6816 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.remarkrc b/.remarkrc index b8cee4c2bb8651..34400ece0dc648 100644 --- a/.remarkrc +++ b/.remarkrc @@ -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/" + ] } diff --git a/Makefile b/Makefile index 1017452f0879e7..fccf6451cc5a63 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -945,6 +945,21 @@ bench: bench-net bench-http bench-fs bench-tls bench-ci: bench +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: @@ -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 ; \ @@ -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 \ diff --git a/tools/remark-cli/cli.js b/tools/remark-cli/cli.js new file mode 100755 index 00000000000000..6bbb1d656410c1 --- /dev/null +++ b/tools/remark-cli/cli.js @@ -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 +}); diff --git a/tools/remark-cli/package.json b/tools/remark-cli/package.json new file mode 100644 index 00000000000000..c6e24e44676683 --- /dev/null +++ b/tools/remark-cli/package.json @@ -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 (http://wooorm.com)", + "contributors": [ + "Titus Wormer (http://wooorm.com)" + ], + "bin": { + "remark": "cli.js" + }, + "files": [ + "cli.js" + ], + "scripts": {}, + "xo": false +} diff --git a/tools/remark-cli/readme.md b/tools/remark-cli/readme.md new file mode 100644 index 00000000000000..ede14ec3687b71 --- /dev/null +++ b/tools/remark-cli/readme.md @@ -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 specify configuration file + -i --ignore-path specify ignore file + -s --setting specify settings + -e --ext specify extensions + -u --use use plugins + -p --preset 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 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] + + + +[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 diff --git a/tools/remark-preset-lint-node/index.js b/tools/remark-preset-lint-node/index.js new file mode 100644 index 00000000000000..132bc7eae24210 --- /dev/null +++ b/tools/remark-preset-lint-node/index.js @@ -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'), + require('remark-lint-no-auto-link-without-protocol'), + require('remark-lint-no-blockquote-without-caret'), + 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'] +]; diff --git a/tools/remark-preset-lint-node/package.json b/tools/remark-preset-lint-node/package.json new file mode 100644 index 00000000000000..000a5a2901d4e7 --- /dev/null +++ b/tools/remark-preset-lint-node/package.json @@ -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" + } +}