Skip to content

Commit

Permalink
Make reset the default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wooorm committed Aug 22, 2016
1 parent 6196124 commit f5c1227
Show file tree
Hide file tree
Showing 77 changed files with 458 additions and 132 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 12 additions & 8 deletions doc/external.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,7 +28,8 @@ Create a `.remarkrc` file and add the following JSON:
"lint": {
"external": [
"no-empty-sections"
]
],
"empty-sections": true
}
}
}
Expand Down Expand Up @@ -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
```
Expand All @@ -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));
});
Expand Down Expand Up @@ -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:

Expand Down
23 changes: 5 additions & 18 deletions doc/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ are supported in configuration objects:

```json
{
"final-newline": false
"final-newline": true
}
```

...is treated the same as:

```json
{
"finalNewline": false
"finalNewline": true
}
```

Expand Down Expand Up @@ -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`

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"lerna": "2.0.0-beta.26",
"version": "independent"
}
59 changes: 14 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -89,23 +59,22 @@
"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,
"toc": {
"tight": true,
"maxDepth": 2
},
"./": {
"no-missing-blank-lines": false,
"list-item-spacing": false
},
"validate-links": null
},
"settings": {
Expand Down
File renamed without changes.
12 changes: 4 additions & 8 deletions lib/index.js → packages/remark-lint/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [];
Expand All @@ -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);

Expand All @@ -75,7 +72,6 @@ function lint(remark, options) {
remark.use(control, {
name: 'lint',
source: SOURCE,
reset: reset,
known: known,
enable: enable,
disable: disable
Expand Down Expand Up @@ -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) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions packages/remark-lint/package.json
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions packages/remark-preset-lint-consistent/index.js
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions packages/remark-preset-lint-consistent/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit f5c1227

Please sign in to comment.