Skip to content

Commit

Permalink
Add support for presets, more
Browse files Browse the repository at this point in the history
The following updates each include major breaking changes,
which are exposed to user and to plugins.

* **vfile**: <https://github.com/wooorm/vfile/releases/tag/2.0.0>
* **load-plugin**: <https://github.com/wooorm/load-plugin/releases/tag/2.0.0>
* **unified**: <https://github.com/wooorm/unified/releases/tag/5.0.0>
* **vfile-reporter**: <https://github.com/wooorm/vfile-reporter/releases/tag/3.0.0>

It’s now possible to load configuration files from `node_modules`.
This works similar to how babel presets work (instead of ESLint’s
shareable configuration files).

* It’s now possible to pass in YAML, JS, or `package.json`
  configuration files to `rcPath`;
* Plugins are now loaded from the directory of the configuration file
  as well;

* Files are now ignored relative to the ignore file;

Closes remarkjs/remark#183.
Related to remarkjs/remark-lint#81.
  • Loading branch information
wooorm committed Aug 21, 2016
1 parent d45fb4a commit 850d3f2
Show file tree
Hide file tree
Showing 80 changed files with 856 additions and 373 deletions.
73 changes: 53 additions & 20 deletions doc/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ through configuration files.
* If [`packageField`][package-field] is given, `package.json`
(JSON) files are loaded and their `$packageField`s are
used as configuration.
* One configuration file (JSON) can be given through [`rcPath`][rc-path],
* One configuration file can be given through [`rcPath`][rc-path],
this is loaded regardless of `detectConfig` and `rcName`.

###### Example
Expand All @@ -20,49 +20,39 @@ An example **rc** file could look as follows:
```json
{
"output": true,
"presets": ["lint-recommended"],
"settings": {
"bullet": "*",
"ruleRepetition": 3,
"fences": true
},
"plugins": {
"inline-links": null,
"lint": {
"external": [
"remark-lint-no-empty-sections"
],
"maximum-line-length": false
}
}
"plugins": ["inline-links"]
}
```

###### Example

An example **rc.js** file could look as follows:

Scripts expose either an object, or a function which when invoked
returns an object. The latter is given the current configuration for
a file. This configuration always has a `plugins` object where the
keys are resolved absolute paths to plugins, where the values are
objects or `false`.

An example **rc.js** file could look as follows:

```js
/**
* @fileoverview Local remark configuration.
*/

module.exports = {
output: true,
plugins: {
preset: 'lint-recommended',
plugins: [
/* Custom natural-language validation. */
'script/natural-language': null,
'lint': {
/* Ignore `final-definition` for `license` */
'final-definition': false
},
'license': null
},
'script/natural-language',
'license'
],
settings: {
/* I personally like asterisks. */
bullet: '*'
Expand Down Expand Up @@ -200,6 +190,49 @@ configures the parser and compiler of the processor.

* Type: `Object`.

###### `presets`

The `presets` field has either a list of preset names (or paths) or an
object mapping presets to their options. It’s also possible to pass
one preset by passing a `string`.

Presets are in fact configuration files as well: go ahead and publish
your configuration files, if they’re in JSON or JS, on npm.

Accepts a string:

```json
{
"presets": "foo"
}
```

Accepts an array:

```json
{
"presets": [
"foo",
"bar"
]
}
```

Or an object:

```json
{
"presets": {
"foo": null,
"bar": {
"baz": "qux"
}
}
}
```

* Type: `string`, `Array.<string>` or `Object.<string, Object>`.

###### `plugins`

The `plugins` field, related to [`plugins`][plugins] in `options`, has
Expand Down
45 changes: 43 additions & 2 deletions doc/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ authors.
* [options.silentlyIgnore](#optionssilentlyignore)
* [options.plugins](#optionsplugins)
* [options.pluginPrefix](#optionspluginprefix)
* [options.presetPrefix](#optionspresetprefix)
* [options.injectedPlugins](#optionsinjectedplugins)
* [options.color](#optionscolor)
* [options.silent](#optionssilent)
Expand Down Expand Up @@ -327,10 +328,10 @@ be set from configuration files.

* When `true`, overwrites the given files;
* When pointing to an existing directory, files are written
to that directory and keep their filenames and extensions;
to that directory and keep their basename;
* When the parent directory of the given path exists and one
file is processed, the file is written to the given path
using the given filename (and optionally extension);
using the given basename;
* Otherwise, a fatal error is thrown.

<!-- Info: -->
Expand Down Expand Up @@ -831,6 +832,46 @@ engine({
});
```

## `options.presetPrefix`

Allow presets to be loaded from configuration files without their
prefix.

* Type: `string` or `false`, optional.

###### Example

The following example processes `readme.md` and loads the
`lint-recommended` preset (from a `package.json`).
Because `presetPrefix` is given, this resolves to
`remark-preset-lint-recommended`.

```js
var engine = require('unified-engine');
var remark = require('remark');

engine({
processor: remark(),
globs: ['readme.md'],
packageField: 'remarkConfig',
presetPrefix: 'remark-preset'
}, function (err) {
if (err) throw err;
});
```

Where `package.json` contains:

```json
{
"name": "foo",
"private": true,
"remarkConfig": {
"presets": "lint-recommended"
}
}
```

## `options.injectedPlugins`

Already loaded plug-ins to attach with their options to the processor
Expand Down
2 changes: 1 addition & 1 deletion doc/plug-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var remark = require('remark');
function plugin(processor, options, set) {
function completer(set) {
console.log('done:', set.valueOf().map(function (file) {
return file.filePath();
return file.path;
}));
}

Expand Down
Loading

0 comments on commit 850d3f2

Please sign in to comment.