mirror of
https://github.com/remarkjs/remark-lint.git
synced 2024-09-11 19:57:15 +03:00
Make reset
the default
Closes GH-81. This adds proper support for presets in **remark-lint**. This is a big one: **remark-lint** no longer does anything without you telling it to. * Update internals, docs, examples, to turn `reset` on by default; * Refactor project to monorepo; * Move library to `./packages/remark-lint`; * Add the following preset packages: * `remark-preset-lint-consistent`; * `remark-preset-lint-recommended`; * `remark-preset-lint-legacy`. If you’re using the CLI, please add one or more of these presets to your configuration file. On the API, note that presets are node modules, so it’s possible to `require` them as well.
This commit is contained in:
parent
6196124599
commit
f5c1227218
@ -1,12 +1,9 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '0.11'
|
||||
- '0.12'
|
||||
- '4.0'
|
||||
- '5.0'
|
||||
- '6.0'
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
after_success: bash <(curl -s https://codecov.io/bash)
|
||||
deploy:
|
||||
- provider: npm
|
||||
email: tituswormer@gmail.com
|
||||
|
@ -10,11 +10,11 @@ for markdown.
|
||||
|
||||
## Using external rules
|
||||
|
||||
External rules can be used by passing their file-path or their name,
|
||||
External rules can be used in two ways:
|
||||
Either by passing their file-path or their name,
|
||||
in which case `remark-lint-` can be omitted, in an `external` array
|
||||
to **remark-lint**. This only works in Node.js.
|
||||
|
||||
Alternatively, load modules yourself and pass them in the `external` array too.
|
||||
to **remark-lint** (this only works in Node.js), or by loading
|
||||
modules yourself and pass them in the `external` array too.
|
||||
|
||||
### CLI
|
||||
|
||||
@ -28,7 +28,8 @@ Create a `.remarkrc` file and add the following JSON:
|
||||
"lint": {
|
||||
"external": [
|
||||
"no-empty-sections"
|
||||
]
|
||||
],
|
||||
"empty-sections": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -62,7 +63,7 @@ That should show a report like:
|
||||
|
||||
```sh
|
||||
readme.md
|
||||
5:1-5:5 warning Remove empty section: "B (this section is empty!)" empty-sections
|
||||
5:1-5:5 warning Remove empty section: "B (this section is empty!)" empty-sections
|
||||
|
||||
⚠ 1 warning
|
||||
```
|
||||
@ -85,7 +86,10 @@ var report = require('vfile-reporter');
|
||||
var doc = fs.readFileSync('example.md', 'utf8');
|
||||
|
||||
remark()
|
||||
.use(lint, {external: ['no-url-trailing-slash']})
|
||||
.use(lint, {
|
||||
external: ['no-url-trailing-slash'],
|
||||
trailingSlash: true
|
||||
})
|
||||
.process(doc, function (err, file) {
|
||||
console.log(report(err || file));
|
||||
});
|
||||
@ -131,7 +135,7 @@ a [virtual file][vfile], and a setting.
|
||||
|
||||
The setting is never `true` or `false`, those are used later to filter
|
||||
messages. Rules always run, even when they’re turned off, as they can
|
||||
be turned on from within markdown code through [comments][]
|
||||
be turned on from within markdown code through [comments][].
|
||||
|
||||
An example, `./rules/code-js-flag.js`, is as follows:
|
||||
|
||||
|
23
doc/rules.md
23
doc/rules.md
@ -11,7 +11,7 @@ are supported in configuration objects:
|
||||
|
||||
```json
|
||||
{
|
||||
"final-newline": false
|
||||
"final-newline": true
|
||||
}
|
||||
```
|
||||
|
||||
@ -19,7 +19,7 @@ are supported in configuration objects:
|
||||
|
||||
```json
|
||||
{
|
||||
"finalNewline": false
|
||||
"finalNewline": true
|
||||
}
|
||||
```
|
||||
|
||||
@ -114,21 +114,8 @@ It’s also possible to pass both a severity and configuration:
|
||||
|
||||
## `reset`
|
||||
|
||||
By default, all rules are turned on unless explicitly
|
||||
set to `false`. When `reset: true`, the opposite is
|
||||
`true`: all rules are turned off, unless when given a
|
||||
non-nully and non-false value.
|
||||
|
||||
Options: `boolean`, default: `false`.
|
||||
|
||||
Explicitly activate rules:
|
||||
|
||||
```json
|
||||
{
|
||||
"reset": true,
|
||||
"final-newline": true
|
||||
}
|
||||
```
|
||||
Since version 5.0.0, **reset** is no longer available, and
|
||||
it is now the default behavour.
|
||||
|
||||
## `external`
|
||||
|
||||
@ -1139,7 +1126,7 @@ When `'invalid'` is passed in, the following error is given:
|
||||
Warn when list looseness is incorrect, such as being tight
|
||||
when it should be loose, and vice versa.
|
||||
|
||||
According the [markdown-style-guide](http://www.cirosantilli.com/markdown-style-guide/),
|
||||
According to the [markdown-style-guide](http://www.cirosantilli.com/markdown-style-guide/),
|
||||
if one or more list-items in a list spans more than one line,
|
||||
the list is required to have blank lines between each item.
|
||||
And otherwise, there should not be blank lines between items.
|
||||
|
4
lerna.json
Normal file
4
lerna.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"lerna": "2.0.0-beta.26",
|
||||
"version": "independent"
|
||||
}
|
59
package.json
59
package.json
@ -1,52 +1,20 @@
|
||||
{
|
||||
"name": "remark-lint",
|
||||
"version": "4.2.0",
|
||||
"description": "Lint markdown with remark",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"markdown",
|
||||
"lint",
|
||||
"validate",
|
||||
"remark"
|
||||
],
|
||||
"repository": "https://github.com/wooorm/remark-lint",
|
||||
"bugs": "https://github.com/wooorm/remark-lint/issues",
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
|
||||
"Stephan Schneider <stephanschndr@gmail.com>",
|
||||
"Ben Balter <ben.balter@github.com>",
|
||||
"Danny Arnold <despair.blue@gmail.com>",
|
||||
"Tony Brix <tony@brix.ninja>",
|
||||
"Michael Mior <michael.mior@gmail.com>",
|
||||
"Patrick Gilday <pcgilday@gmail.com>",
|
||||
"Yoshua Wuyts <yoshuawuyts@gmail.com>",
|
||||
"YJ Yang <chcokr@gmail.com>",
|
||||
"Burak Yiğit Kaya <ben@byk.im>"
|
||||
],
|
||||
"dependencies": {
|
||||
"decamelize": "^1.0.0",
|
||||
"load-plugin": "^2.0.0",
|
||||
"mdast-util-heading-style": "^1.0.0",
|
||||
"mdast-util-to-string": "^1.0.0",
|
||||
"plur": "^2.0.0",
|
||||
"remark-message-control": "^2.0.0",
|
||||
"trough": "^1.0.0",
|
||||
"unist-util-position": "^2.0.1",
|
||||
"unist-util-visit": "^1.0.0",
|
||||
"vfile-location": "^2.0.0",
|
||||
"vfile-sort": "^1.0.0",
|
||||
"wrapped": "^1.0.1"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib/"
|
||||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
|
||||
],
|
||||
"devDependencies": {
|
||||
"browserify": "^13.0.0",
|
||||
"chalk": "^1.1.3",
|
||||
"decamelize": "^1.2.0",
|
||||
"decamelize-keys": "^1.1.0",
|
||||
"dox": "^0.9.0",
|
||||
"esmangle": "^1.0.0",
|
||||
"lerna": "^2.0.0-beta.26",
|
||||
"nyc": "^8.0.0",
|
||||
"remark": "^6.0.0",
|
||||
"remark-cli": "^2.0.0",
|
||||
@ -64,12 +32,14 @@
|
||||
"xo": "^0.16.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublish": "lerna bootstrap",
|
||||
"build-index": "node script/build-index.js",
|
||||
"build-presets": "node script/build-presets.js",
|
||||
"build-rules": "node script/build-docs.js",
|
||||
"build-md": "remark . --quiet --frail",
|
||||
"build-bundle": "browserify index.js --bare -s remarkLint > remark-lint.js",
|
||||
"build-bundle": "browserify packages/remark-lint/index.js --bare -s remarkLint > remark-lint.js",
|
||||
"build-mangle": "esmangle remark-lint.js > remark-lint.min.js",
|
||||
"build": "npm run build-md && npm run build-index && npm run build-rules && npm run build-bundle && npm run build-mangle",
|
||||
"build": "npm run build-presets && npm run build-md && npm run build-index && npm run build-rules && npm run build-bundle && npm run build-mangle",
|
||||
"lint": "xo",
|
||||
"test-api": "tape test/index.js",
|
||||
"test-coverage": "nyc --reporter lcov tape test/index.js",
|
||||
@ -89,12 +59,15 @@
|
||||
"eqeqeq": "off"
|
||||
},
|
||||
"ignores": [
|
||||
"remark-lint.js",
|
||||
"remark-lint.min.js"
|
||||
"remark-lint.js"
|
||||
]
|
||||
},
|
||||
"remarkConfig": {
|
||||
"output": true,
|
||||
"presets": [
|
||||
"./packages/remark-preset-lint-recommended",
|
||||
"./packages/remark-preset-lint-consistent"
|
||||
],
|
||||
"plugins": {
|
||||
"comment-config": null,
|
||||
"github": null,
|
||||
@ -102,10 +75,6 @@
|
||||
"tight": true,
|
||||
"maxDepth": 2
|
||||
},
|
||||
"./": {
|
||||
"no-missing-blank-lines": false,
|
||||
"list-item-spacing": false
|
||||
},
|
||||
"validate-links": null
|
||||
},
|
||||
"settings": {
|
||||
|
@ -29,9 +29,7 @@ var SOURCE = 'remark-lint';
|
||||
/**
|
||||
* Lint attacher.
|
||||
*
|
||||
* By default, all rules are turned on unless explicitly
|
||||
* set to `false`. When `reset: true`, the opposite is
|
||||
* true: all rules are turned off, unless when given
|
||||
* All rules are turned off, unless when given
|
||||
* a non-nully and non-false value.
|
||||
*
|
||||
* @example
|
||||
@ -46,7 +44,6 @@ var SOURCE = 'remark-lint';
|
||||
function lint(remark, options) {
|
||||
var settings = decamelizeSettings(options || {});
|
||||
var rules = loadExternals(settings.external);
|
||||
var reset = options && options.reset;
|
||||
var enable = [];
|
||||
var disable = [];
|
||||
var known = [];
|
||||
@ -57,7 +54,7 @@ function lint(remark, options) {
|
||||
/* Add each rule. */
|
||||
for (id in rules) {
|
||||
known.push(id);
|
||||
config = coerce(id, settings[id], reset);
|
||||
config = coerce(id, settings[id]);
|
||||
|
||||
(config[0] ? enable : disable).push(id);
|
||||
|
||||
@ -75,7 +72,6 @@ function lint(remark, options) {
|
||||
remark.use(control, {
|
||||
name: 'lint',
|
||||
source: SOURCE,
|
||||
reset: reset,
|
||||
known: known,
|
||||
enable: enable,
|
||||
disable: disable
|
||||
@ -187,8 +183,8 @@ function decamelizeSettings(source) {
|
||||
}
|
||||
|
||||
/* Coerce a value to a severity--options tuple. */
|
||||
function coerce(name, value, reset) {
|
||||
var def = reset ? 0 : 1;
|
||||
function coerce(name, value) {
|
||||
var def = 0;
|
||||
var result;
|
||||
|
||||
if (value == null) {
|
@ -7,7 +7,7 @@
|
||||
* Warn when list looseness is incorrect, such as being tight
|
||||
* when it should be loose, and vice versa.
|
||||
*
|
||||
* According the [markdown-style-guide](http://www.cirosantilli.com/markdown-style-guide/),
|
||||
* According to the [markdown-style-guide](http://www.cirosantilli.com/markdown-style-guide/),
|
||||
* if one or more list-items in a list spans more than one line,
|
||||
* the list is required to have blank lines between each item.
|
||||
* And otherwise, there should not be blank lines between items.
|
45
packages/remark-lint/package.json
Normal file
45
packages/remark-lint/package.json
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "remark-lint",
|
||||
"version": "4.2.0",
|
||||
"description": "Lint markdown with remark",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"markdown",
|
||||
"lint",
|
||||
"validate",
|
||||
"remark"
|
||||
],
|
||||
"repository": "https://github.com/wooorm/remark-lint/tree/master/packages/remark-lint",
|
||||
"bugs": "https://github.com/wooorm/remark-lint/issues",
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
|
||||
"Stephan Schneider <stephanschndr@gmail.com>",
|
||||
"Ben Balter <ben.balter@github.com>",
|
||||
"Danny Arnold <despair.blue@gmail.com>",
|
||||
"Tony Brix <tony@brix.ninja>",
|
||||
"Michael Mior <michael.mior@gmail.com>",
|
||||
"Patrick Gilday <pcgilday@gmail.com>",
|
||||
"Yoshua Wuyts <yoshuawuyts@gmail.com>",
|
||||
"YJ Yang <chcokr@gmail.com>",
|
||||
"Burak Yiğit Kaya <ben@byk.im>"
|
||||
],
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib/"
|
||||
],
|
||||
"dependencies": {
|
||||
"decamelize": "^1.0.0",
|
||||
"load-plugin": "^2.0.0",
|
||||
"mdast-util-heading-style": "^1.0.0",
|
||||
"mdast-util-to-string": "^1.0.0",
|
||||
"plur": "^2.0.0",
|
||||
"remark-message-control": "^2.0.0",
|
||||
"trough": "^1.0.0",
|
||||
"unist-util-position": "^2.0.1",
|
||||
"unist-util-visit": "^1.0.0",
|
||||
"vfile-location": "^2.0.0",
|
||||
"vfile-sort": "^1.0.0",
|
||||
"wrapped": "^1.0.1"
|
||||
}
|
||||
}
|
27
packages/remark-preset-lint-consistent/index.js
Normal file
27
packages/remark-preset-lint-consistent/index.js
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @author Titus Wormer
|
||||
* @copyright 2016 Titus Wormer
|
||||
* @license MIT
|
||||
* @module remark:preset:lint-recommended
|
||||
* @fileoverview remark preset to configure remark-lint with
|
||||
* settings that enforce consistency.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports.plugins = {
|
||||
lint: {
|
||||
blockquoteIndentation: 'consistent',
|
||||
checkboxCharacterStyle: 'consistent',
|
||||
codeBlockStyle: 'consistent',
|
||||
emphasisMarker: 'consistent',
|
||||
fencedCodeMarker: 'consistent',
|
||||
headingStyle: 'consistent',
|
||||
linkTitleStyle: 'consistent',
|
||||
listItemContentIndent: true,
|
||||
orderedListMarkerStyle: 'consistent',
|
||||
ruleStyle: 'consistent',
|
||||
strongMarker: 'consistent',
|
||||
tableCellPadding: 'consistent'
|
||||
}
|
||||
};
|
24
packages/remark-preset-lint-consistent/package.json
Normal file
24
packages/remark-preset-lint-consistent/package.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "remark-preset-lint-consistent",
|
||||
"version": "0.0.0",
|
||||
"description": "remark preset to configure remark-lint with settings that enforce consistency",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"remark",
|
||||
"preset",
|
||||
"consistent",
|
||||
"consistency"
|
||||
],
|
||||
"repository": "https://github.com/wooorm/remark-lint/tree/master/packages/remark-preset-lint-recommended",
|
||||
"bugs": "https://github.com/wooorm/remark-lint/issues",
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"remark-lint": "^4.2.0"
|
||||
}
|
||||
}
|
44
packages/remark-preset-lint-consistent/readme.md
Normal file
44
packages/remark-preset-lint-consistent/readme.md
Normal file
@ -0,0 +1,44 @@
|
||||
<!--This file is generated-->
|
||||
|
||||
# remark-preset-lint-consistent
|
||||
|
||||
remark preset to configure remark-lint with settings that enforce consistency.
|
||||
|
||||
## Install
|
||||
|
||||
npm:
|
||||
|
||||
```sh
|
||||
npm install --save remark-preset-lint-consistent
|
||||
```
|
||||
|
||||
Then, add the following to your config file:
|
||||
|
||||
```diff
|
||||
...
|
||||
"remarkConfig": {
|
||||
+ "presets": [
|
||||
+ "remark-preset-lint-consistent"
|
||||
+ ]
|
||||
}
|
||||
...
|
||||
```
|
||||
|
||||
## Rules
|
||||
|
||||
This preset configures [remark-lint](https://github.com/wooorm/remark-lint) with the following rules:
|
||||
|
||||
| Rule | Setting |
|
||||
| ----------------------------------------------------------------------------------------------------------------------- | -------------- |
|
||||
| [`blockquote-indentation`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#blockquote-indentation) | `'consistent'` |
|
||||
| [`checkbox-character-style`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#checkbox-character-style) | `'consistent'` |
|
||||
| [`code-block-style`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#code-block-style) | `'consistent'` |
|
||||
| [`emphasis-marker`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#emphasis-marker) | `'consistent'` |
|
||||
| [`fenced-code-marker`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#fenced-code-marker) | `'consistent'` |
|
||||
| [`heading-style`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#heading-style) | `'consistent'` |
|
||||
| [`link-title-style`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#link-title-style) | `'consistent'` |
|
||||
| [`list-item-content-indent`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#list-item-content-indent) | `true` |
|
||||
| [`ordered-list-marker-style`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#ordered-list-marker-style) | `'consistent'` |
|
||||
| [`rule-style`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#rule-style) | `'consistent'` |
|
||||
| [`strong-marker`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#strong-marker) | `'consistent'` |
|
||||
| [`table-cell-padding`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#table-cell-padding) | `'consistent'` |
|
39
packages/remark-preset-lint-recommended/index.js
Normal file
39
packages/remark-preset-lint-recommended/index.js
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @author Titus Wormer
|
||||
* @copyright 2016 Titus Wormer
|
||||
* @license MIT
|
||||
* @module remark:preset:lint-recommended
|
||||
* @fileoverview remark preset to configure remark-lint with
|
||||
* settings that prevent mistakes or syntaxes that do not
|
||||
* work correctly across vendors.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports.plugins = {
|
||||
lint: {
|
||||
/* Unix compatibility. */
|
||||
finalNewline: true,
|
||||
|
||||
/* Rendering across vendors differs greatly
|
||||
* if using other styles. */
|
||||
listItemBulletIndent: true,
|
||||
listItemIndent: 'tab-size',
|
||||
|
||||
/* Differs or unsupported across vendors. */
|
||||
noAutoLinkWithoutProtocol: true,
|
||||
noBlockquoteWithoutCaret: true,
|
||||
noLiteralUrls: true,
|
||||
orderedListMarkerStyle: '.',
|
||||
|
||||
/* Mistakes. */
|
||||
hardBreakSpaces: true,
|
||||
noDuplicateDefinitions: true,
|
||||
noHeadingContentIndent: true,
|
||||
noInlinePadding: true,
|
||||
noShortcutReferenceImage: true,
|
||||
noShortcutReferenceLink: true,
|
||||
noUndefinedReferences: true,
|
||||
noUnusedDefinitions: true
|
||||
}
|
||||
};
|
23
packages/remark-preset-lint-recommended/package.json
Normal file
23
packages/remark-preset-lint-recommended/package.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "remark-preset-lint-recommended",
|
||||
"version": "0.0.0",
|
||||
"description": "remark preset to configure remark-lint with settings that prevent mistakes or syntaxes that do not work correctly across vendors",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"remark",
|
||||
"preset",
|
||||
"recommended"
|
||||
],
|
||||
"repository": "https://github.com/wooorm/remark-lint/tree/master/packages/remark-preset-lint-recommended",
|
||||
"bugs": "https://github.com/wooorm/remark-lint/issues",
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"remark-lint": "^4.2.0"
|
||||
}
|
||||
}
|
47
packages/remark-preset-lint-recommended/readme.md
Normal file
47
packages/remark-preset-lint-recommended/readme.md
Normal file
@ -0,0 +1,47 @@
|
||||
<!--This file is generated-->
|
||||
|
||||
# remark-preset-lint-recommended
|
||||
|
||||
remark preset to configure remark-lint with settings that prevent mistakes or syntaxes that do not work correctly across vendors.
|
||||
|
||||
## Install
|
||||
|
||||
npm:
|
||||
|
||||
```sh
|
||||
npm install --save remark-preset-lint-recommended
|
||||
```
|
||||
|
||||
Then, add the following to your config file:
|
||||
|
||||
```diff
|
||||
...
|
||||
"remarkConfig": {
|
||||
+ "presets": [
|
||||
+ "remark-preset-lint-recommended"
|
||||
+ ]
|
||||
}
|
||||
...
|
||||
```
|
||||
|
||||
## Rules
|
||||
|
||||
This preset configures [remark-lint](https://github.com/wooorm/remark-lint) with the following rules:
|
||||
|
||||
| Rule | Setting |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------- | ------------ |
|
||||
| [`final-newline`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#final-newline) | `true` |
|
||||
| [`list-item-bullet-indent`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#list-item-bullet-indent) | `true` |
|
||||
| [`list-item-indent`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#list-item-indent) | `'tab-size'` |
|
||||
| [`no-auto-link-without-protocol`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-auto-link-without-protocol) | `true` |
|
||||
| [`no-blockquote-without-caret`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-blockquote-without-caret) | `true` |
|
||||
| [`no-literal-urls`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-literal-urls) | `true` |
|
||||
| [`ordered-list-marker-style`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#ordered-list-marker-style) | `'.'` |
|
||||
| [`hard-break-spaces`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#hard-break-spaces) | `true` |
|
||||
| [`no-duplicate-definitions`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-duplicate-definitions) | `true` |
|
||||
| [`no-heading-content-indent`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-heading-content-indent) | `true` |
|
||||
| [`no-inline-padding`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-inline-padding) | `true` |
|
||||
| [`no-shortcut-reference-image`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-shortcut-reference-image) | `true` |
|
||||
| [`no-shortcut-reference-link`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-shortcut-reference-link) | `true` |
|
||||
| [`no-undefined-references`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-undefined-references) | `true` |
|
||||
| [`no-unused-definitions`](https://github.com/wooorm/remark-lint/blob/master/doc/rules.md#no-unused-definitions) | `true` |
|
75
readme.md
75
readme.md
@ -7,8 +7,9 @@
|
||||
**remark-lint** is a markdown code style linter. Another linter? Yes.
|
||||
Ensuring the markdown you (and contributors) write is of great quality will
|
||||
provide better rendering in all the different markdown parsers, and makes
|
||||
sure less refactoring is needed afterwards. What is quality? That’s up to you,
|
||||
but the defaults are sensible :ok_hand:.
|
||||
sure less refactoring is needed afterwards.
|
||||
|
||||
What is quality? That’s up to you, but there are sensible [presets][].
|
||||
|
||||
**remark-lint** is built on [**remark**][remark], a powerful markdown
|
||||
processor powered by [plugins][remark-plugins] (such as this one).
|
||||
@ -22,6 +23,7 @@ processor powered by [plugins][remark-plugins] (such as this one).
|
||||
* [Configuring remark-lint](#configuring-remark-lint)
|
||||
* [Using remark to fix your markdown](#using-remark-to-fix-your-markdown)
|
||||
* [Editor Integrations](#editor-integrations)
|
||||
* [List of Presets](#list-of-presets)
|
||||
* [List of External Rules](#list-of-external-rules)
|
||||
* [Related](#related)
|
||||
* [License](#license)
|
||||
@ -41,13 +43,28 @@ module, [uncompressed and compressed][releases].
|
||||
|
||||
![Example of how remark-lint looks on screen][screenshot]
|
||||
|
||||
Use `remark-lint` together with [`remark-cli`][cli]:
|
||||
Use `remark-lint` together with [`remark-cli`][cli], and a
|
||||
[preset][preset-recommended].
|
||||
|
||||
```bash
|
||||
npm install --global remark-cli remark-lint
|
||||
npm install --save remark-cli remark-lint remark-preset-lint-recommended
|
||||
```
|
||||
|
||||
Let’s say `example.md` looks as follows:
|
||||
Then, configure **remark** in your `package.json`:
|
||||
|
||||
```js
|
||||
// ...
|
||||
"scripts": {
|
||||
"lint-md": "remark ."
|
||||
},
|
||||
// ...
|
||||
"remarkConfig": {
|
||||
"presets": ["lint-recommended"]
|
||||
}
|
||||
// ...
|
||||
```
|
||||
|
||||
Let’s say there’s an `example.md`, which looks as follows:
|
||||
|
||||
```md
|
||||
* Hello
|
||||
@ -55,12 +72,12 @@ Let’s say `example.md` looks as follows:
|
||||
[World][]
|
||||
```
|
||||
|
||||
Now, running `remark example.md -u remark-lint` yields:
|
||||
Now, running our `lint-md` script with npm, `npm run lint-md`, yields:
|
||||
|
||||
```txt
|
||||
example.md
|
||||
1:3 warning Incorrect list-item indent: add 2 spaces list-item-indent
|
||||
3:1-3:10 warning Found reference to undefined definition no-undefined-references
|
||||
1:3 warning Incorrect list-item indent: add 2 spaces list-item-indent
|
||||
3:1-3:10 warning Found reference to undefined definition no-undefined-references
|
||||
⚠ 2 warnings
|
||||
```
|
||||
|
||||
@ -82,7 +99,9 @@ var report = require('vfile-reporter');
|
||||
var remark = require('remark');
|
||||
var lint = require('remark-lint');
|
||||
|
||||
var file = remark().use(lint).process('## Hello world!');
|
||||
var file = remark().use(lint, {
|
||||
firstHeadingLevel: true
|
||||
}).process('## Hello world!');
|
||||
|
||||
console.log(report(file));
|
||||
```
|
||||
@ -90,11 +109,9 @@ console.log(report(file));
|
||||
Now, running `node example.js` yields:
|
||||
|
||||
```txt
|
||||
1:1 warning Missing newline character at end of file final-newline
|
||||
1:1-1:16 warning First heading level should be `1` first-heading-level
|
||||
1:1-1:16 warning Don’t add a trailing `!` to headings no-heading-punctuation
|
||||
1:1-1:16 warning First heading level should be `1` first-heading-level
|
||||
|
||||
⚠ 3 warnings
|
||||
⚠ 1 warning
|
||||
```
|
||||
|
||||
### `remark.use(lint[, options])`
|
||||
@ -136,18 +153,17 @@ An example `.remarkrc` file could look as follows:
|
||||
|
||||
```json
|
||||
{
|
||||
"presets": ["lint-recommended"],
|
||||
"plugins": {
|
||||
"remark-lint": {
|
||||
"no-multiple-toplevel-headings": false,
|
||||
"list-item-indent": false,
|
||||
"maximum-line-length": 79
|
||||
"lint": {
|
||||
"list-item-indent": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Where the object at `plugins['remark-lint']` is a map of `ruleId`s and
|
||||
their values.
|
||||
Where the object at `plugins.lint` is a map of `ruleId`s and
|
||||
their values, which precede over presets.
|
||||
|
||||
Using our `example.md` from before:
|
||||
|
||||
@ -157,8 +173,7 @@ Using our `example.md` from before:
|
||||
[World][]
|
||||
```
|
||||
|
||||
Now, running `remark example.md` (**without `-u remark-lint`** since
|
||||
our `.remarkrc` includes the lint plugin) yields:
|
||||
Now, running `npm run lint-md` yields:
|
||||
|
||||
```bash
|
||||
example.md
|
||||
@ -221,6 +236,16 @@ To run **remark**, optionally with **remark-lint** from **Gulp**, use
|
||||
|
||||
I’m very interested in more integrations. Let me know if I can help.
|
||||
|
||||
## List of Presets
|
||||
|
||||
Presets can be loaded through the [`preset` setting][config-preset].
|
||||
|
||||
* [`remark-preset-lint-consistent`][preset-consistent]
|
||||
— Rules that enforce consistency;
|
||||
* [`remark-preset-lint-recommended`][preset-recommended]
|
||||
— Rules that prevent mistakes or syntaxes that do not work
|
||||
correctly across vendors.
|
||||
|
||||
## List of External Rules
|
||||
|
||||
External rules can be loaded through the [`external` setting][external].
|
||||
@ -308,3 +333,11 @@ excluding `remark-lint-no-` or `remark-lint-`
|
||||
[external]: doc/rules.md#external
|
||||
|
||||
[doc-external]: doc/external.md
|
||||
|
||||
[config-preset]: https://github.com/wooorm/unified-engine/blob/master/doc/configure.md#presets
|
||||
|
||||
[preset-consistent]: https://github.com/wooorm/remark-lint/blob/master/packages/remark-preset-lint-consistent
|
||||
|
||||
[preset-recommended]: https://github.com/wooorm/remark-lint/blob/master/packages/remark-preset-lint-recommended
|
||||
|
||||
[presets]: #list-of-presets
|
||||
|
@ -23,7 +23,9 @@ var rule = require('./util/rule');
|
||||
var markdown = remark().use(toc);
|
||||
|
||||
/* Generate. */
|
||||
[path.join(process.cwd())].forEach(function (filePath) {
|
||||
[
|
||||
path.join(process.cwd(), 'packages', 'remark-lint')
|
||||
].forEach(function (filePath) {
|
||||
var children = [];
|
||||
var all = rules(filePath);
|
||||
var root;
|
||||
@ -109,7 +111,7 @@ var markdown = remark().use(toc);
|
||||
'',
|
||||
'```json',
|
||||
'{',
|
||||
' "final-newline": false',
|
||||
' "final-newline": true',
|
||||
'}',
|
||||
'```',
|
||||
'',
|
||||
@ -117,7 +119,7 @@ var markdown = remark().use(toc);
|
||||
'',
|
||||
'```json',
|
||||
'{',
|
||||
' "finalNewline": false',
|
||||
' "finalNewline": true',
|
||||
'}',
|
||||
'```',
|
||||
'',
|
||||
@ -152,21 +154,8 @@ var markdown = remark().use(toc);
|
||||
'',
|
||||
'## `reset`',
|
||||
'',
|
||||
'By default, all rules are turned on unless explicitly',
|
||||
'set to `false`. When `reset: true`, the opposite is',
|
||||
'`true`: all rules are turned off, unless when given a',
|
||||
'non-nully and non-false value.',
|
||||
'',
|
||||
'Options: `boolean`, default: `false`.',
|
||||
'',
|
||||
'Explicitly activate rules:',
|
||||
'',
|
||||
'```json',
|
||||
'{',
|
||||
' "reset": true,',
|
||||
' "final-newline": true',
|
||||
'}',
|
||||
'```',
|
||||
'Since version 5.0.0, **reset** is no longer available, and',
|
||||
'it is now the default behavour.',
|
||||
'',
|
||||
'## `external`',
|
||||
'',
|
||||
@ -199,7 +188,7 @@ var markdown = remark().use(toc);
|
||||
markdown.run(root);
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(filePath, 'doc', 'rules.md'),
|
||||
path.join(process.cwd(), 'doc', 'rules.md'),
|
||||
markdown.stringify(root)
|
||||
);
|
||||
|
||||
|
@ -15,7 +15,9 @@ var chalk = require('chalk');
|
||||
var rules = require('./util/rules');
|
||||
|
||||
/* Generate. */
|
||||
[path.join(process.cwd())].forEach(function (filePath) {
|
||||
[
|
||||
path.join(process.cwd(), 'packages', 'remark-lint')
|
||||
].forEach(function (filePath) {
|
||||
var base = path.resolve(filePath, 'lib', 'rules.js');
|
||||
var doc = [];
|
||||
|
||||
|
92
script/build-presets.js
Normal file
92
script/build-presets.js
Normal file
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* @author Titus Wormer
|
||||
* @copyright 2016 Titus Wormer
|
||||
* @license MIT
|
||||
* @module remark:lint:script:build-indices
|
||||
* @fileoverview Creates `index.js` files for rules.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/* Dependencies. */
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var inspect = require('util').inspect;
|
||||
var u = require('unist-builder');
|
||||
var chalk = require('chalk');
|
||||
var remark = require('remark');
|
||||
var decamelize = require('decamelize-keys');
|
||||
var remote = require('../package.json').repository;
|
||||
var rules = require('./util/rules');
|
||||
|
||||
var root = path.join(process.cwd(), 'packages');
|
||||
var core = path.join(root, 'remark-lint');
|
||||
|
||||
rules = rules(core).map(function (fp) {
|
||||
return path.basename(fp, path.extname(fp));
|
||||
});
|
||||
|
||||
/* Generate. */
|
||||
fs
|
||||
.readdirSync(root)
|
||||
.filter(function (basename) {
|
||||
return /remark-preset/.test(basename);
|
||||
})
|
||||
.forEach(function (basename) {
|
||||
var base = path.resolve(root, basename);
|
||||
var pack = require(path.join(base, 'package.json'));
|
||||
var value = decamelize(require(base).plugins.lint, '-');
|
||||
var doc;
|
||||
var rows = [];
|
||||
|
||||
rows.push(u('tableRow', [
|
||||
u('tableCell', [u('text', 'Rule')]),
|
||||
u('tableCell', [u('text', 'Setting')])
|
||||
]));
|
||||
|
||||
Object.keys(value).forEach(function (rule) {
|
||||
var url = remote + '/blob/master/doc/rules.md#' + rule;
|
||||
|
||||
rows.push(u('tableRow', [
|
||||
u('tableCell', [
|
||||
u('link', {url: url, title: null}, [u('inlineCode', rule)])
|
||||
]),
|
||||
u('tableCell', [u('inlineCode', inspect(value[rule]))])
|
||||
]));
|
||||
});
|
||||
|
||||
doc = u('root', [
|
||||
u('html', '<!--This file is generated-->'),
|
||||
u('heading', {depth: 1}, [u('text', pack.name)]),
|
||||
u('paragraph', [u('text', pack.description + '.')]),
|
||||
u('heading', {depth: 2}, [u('text', 'Install')]),
|
||||
u('paragraph', [u('text', 'npm:')]),
|
||||
u('code', {lang: 'sh'}, 'npm install --save ' + pack.name),
|
||||
u('paragraph', [u('text', 'Then, add the following to your config file:')]),
|
||||
u('code', {lang: 'diff'}, [
|
||||
' ...',
|
||||
' "remarkConfig": {',
|
||||
'+ "presets": [',
|
||||
'+ "' + pack.name + '"',
|
||||
'+ ]',
|
||||
' }',
|
||||
' ...'
|
||||
].join('\n')),
|
||||
u('heading', {depth: 2}, [u('text', 'Rules')]),
|
||||
u('paragraph', [
|
||||
u('text', 'This preset configures '),
|
||||
u('link', {url: remote}, [u('text', 'remark-lint')]),
|
||||
u('text', ' with the following rules:')
|
||||
]),
|
||||
u('table', {align: []}, rows)
|
||||
]);
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(base, 'readme.md'),
|
||||
remark().stringify(doc)
|
||||
);
|
||||
|
||||
console.log(
|
||||
chalk.green('✓') + ' wrote `readme.md` in `' + basename + '`'
|
||||
);
|
||||
});
|
@ -16,7 +16,7 @@ var test = require('tape');
|
||||
var vfile = require('to-vfile');
|
||||
var removePosition = require('unist-util-remove-position');
|
||||
var remark = require('remark');
|
||||
var lint = require('..');
|
||||
var lint = require('../packages/remark-lint');
|
||||
var rules = require('../script/util/rules');
|
||||
var rule = require('../script/util/rule');
|
||||
|
||||
@ -38,7 +38,10 @@ test('core', function (t) {
|
||||
].join('\n');
|
||||
|
||||
remark()
|
||||
.use(lint, {finalNewline: false})
|
||||
.use(lint, {
|
||||
noHeadingPunctuation: true,
|
||||
noMultipleToplevelHeadings: true
|
||||
})
|
||||
.process(doc, function (err) {
|
||||
st.ifErr(err, 'should not fail');
|
||||
st.deepEqual(
|
||||
@ -57,7 +60,7 @@ test('core', function (t) {
|
||||
st.ifErr(err, 'should not fail');
|
||||
st.deepEqual(
|
||||
file.messages.map(String),
|
||||
['1:1: Missing newline character at end of file'],
|
||||
[],
|
||||
'should warn for missing new lines'
|
||||
);
|
||||
});
|
||||
@ -89,7 +92,7 @@ test('core', function (t) {
|
||||
st.plan(3);
|
||||
|
||||
remark()
|
||||
.use(lint, {reset: true, finalNewline: [2]})
|
||||
.use(lint, {finalNewline: [2]})
|
||||
.process('.', function (err, file) {
|
||||
st.ifErr(err, 'should not fail');
|
||||
st.equal(
|
||||
@ -159,7 +162,8 @@ test('external rules', function (t) {
|
||||
|
||||
remark()
|
||||
.use(lint, {
|
||||
external: tests[label]
|
||||
external: tests[label],
|
||||
trailingSlash: true
|
||||
})
|
||||
.process(doc, function (err, file) {
|
||||
st.ifErr(err, 'should not fail');
|
||||
@ -174,7 +178,7 @@ test('external rules', function (t) {
|
||||
});
|
||||
|
||||
test('rules', function (t) {
|
||||
var all = rules(process.cwd());
|
||||
var all = rules(path.join(process.cwd(), 'packages', 'remark-lint'));
|
||||
|
||||
t.plan(all.length);
|
||||
|
||||
@ -225,7 +229,7 @@ function assertFixture(t, rule, fixture, basename, setting) {
|
||||
var ruleId = rule.ruleId;
|
||||
var file = vfile(basename);
|
||||
var expected = fixture.output;
|
||||
var options = {reset: true};
|
||||
var options = {};
|
||||
var positionless = fixture.config.positionless;
|
||||
|
||||
options[ruleId] = setting;
|
||||
|
Loading…
Reference in New Issue
Block a user