Skip to content

Commit e7a7701

Browse files
committed
Update docs
1 parent f5cb7d2 commit e7a7701

File tree

77 files changed

+765
-510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+765
-510
lines changed

doc/create-a-custom-rule.md

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,25 @@ We then export the result of calling `rule` by providing the *namespace and rule
131131

132132
```js
133133
// rules/no-gif-allowed.js
134+
import {lintRule} from 'unified-lint-rule'
134135

135-
var rule = require('unified-lint-rule')
136-
function noGifAllowed(tree, file, options) {
137-
// Rule implementation
138-
}
139-
module.exports = rule('remark-lint:no-gif-allowed', noGifAllowed)
136+
const remarkLintNoGifAllowed = lintRule(
137+
'remark-lint:no-gif-allowed',
138+
(tree, file, options) => {
139+
// Rule implementation
140+
}
141+
)
142+
143+
export default remarkLintNoGifAllowed
140144
```
141145

142146
Let’s say you want all your custom rules to be defined as part of your project namespace.
143147
If your project was named `my-project`, then you can export your rule as:
144148

145149
```js
146-
module.exports = rule('my-project-name:no-gif-allowed', noGifAllowed)
150+
const remarkLintNoGifAllowed = lintRule('my-project-name:no-gif-allowed', () => {})
147151
// Or:
148-
module.exports = rule('my-npm-published-package:no-gif-allowed', noGifAllowed)
152+
const remarkLintNoGifAllowed = lintRule('my-npm-published-package:no-gif-allowed', () => {})
149153
```
150154

151155
This can help you when wanting to create a group of rules under the same *namespace*.
@@ -157,7 +161,7 @@ This can help you when wanting to create a group of rules under the same *namesp
157161
Your rule function will receive three arguments:
158162

159163
```js
160-
function noGifAllowed(tree, file, options) {}
164+
(tree, file, options) => {}
161165
```
162166

163167
* `tree` (*required*): [mdast](https://github.com/syntax-tree/mdast)
@@ -173,9 +177,9 @@ Because we will be inspecting [mdast](https://github.com/syntax-tree/mdast), whi
173177
For this example, we will use [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit) to recursively inspect all the image nodes, and [`unist-util-generated`](https://github.com/syntax-tree/unist-util-generated) to ensure we are not inspecting nodes that we have generated ourselves and do not belong to the `doc.md`.
174178

175179
```js
176-
const rule = require('unified-lint-rule')
177-
const visit = require('unist-visit-util')
178-
const generated = require('unist-util-generated')
180+
import {lintRule} from 'unified-lint-rule'
181+
import {visit} from 'unist-visit-util'
182+
import {generated} from 'unist-util-generated'
179183

180184
function isValidNode(node) {
181185
// Here we check whether the given node violates our rule.
@@ -185,27 +189,32 @@ function isValidNode(node) {
185189
return !node.url.endsWith('.gif')
186190
}
187191
}
188-
function noGifAllowed(tree, file, options) {
189-
visit(tree, 'image', visitor)
190-
function visitor(node) {
191-
if (!generated(node)) {
192-
// This is an extremely simplified example of how to structure
193-
// the logic to check whether a node violates your rule.
194-
// You have complete freedom over how to visit/inspect the tree,
195-
// and on how to implement the validation logic for your node.
196-
const isValid = isValidNode(node)
197-
if (!isValid) {
198-
// Remember to provide the node as second argument to the message,
199-
// in order to obtain the position and column where the violation occurred.
200-
file.message(
201-
'Invalid image file extentions. Please do not use gifs',
202-
node
203-
)
192+
193+
const remarkLintNoGifAllowed = lintRule(
194+
'remark-lint:no-gif-allowed',
195+
(tree, file, options) => {
196+
visit(tree, 'image', (node) => {
197+
if (!generated(node)) {
198+
// This is an extremely simplified example of how to structure
199+
// the logic to check whether a node violates your rule.
200+
// You have complete freedom over how to visit/inspect the tree,
201+
// and on how to implement the validation logic for your node.
202+
const isValid = isValidNode(node)
203+
204+
if (!isValid) {
205+
// Remember to provide the node as second argument to the message,
206+
// in order to obtain the position and column where the violation occurred.
207+
file.message(
208+
'Invalid image file extentions. Please do not use gifs',
209+
node
210+
)
211+
}
204212
}
205-
}
213+
})
206214
}
207-
}
208-
module.exports = rule('remark-lint:no-gif-allowed', noGifAllowed)
215+
)
216+
217+
export default remarkLintNoGifAllowed
209218
```
210219

211220
[Back to Top](#contents)
@@ -218,11 +227,15 @@ You can do that by importing your rule and adding it in `plugins` array:
218227

219228
```js
220229
// .remarkrc.js
221-
const noGifAllowed = require('./rules/no-gif-allowed.js')
230+
import remarkLintNoGifAllowed from './rules/no-gif-allowed.js'
222231

223-
module.exports = {
224-
plugins: [noGifAllowed]
232+
const plugins = {
233+
plugins: [remarkLintNoGifAllowed]
225234
}
235+
236+
const preset = {plugins}
237+
238+
export default preset
226239
```
227240

228241
[Back to Top](#contents)

doc/rules.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,52 @@ information.
1414
`false` turns rules off — the code no longer runs:
1515

1616
```js
17+
import remarkLintFinalNewline from 'remark-lint-final-newline'
18+
1719
remark()
18-
.use(require('remark-lint-final-newline'), false)
20+
.use(remarkLintFinalNewline, false)
1921
//
2022
```
2123

2224
`true` turns a rule on again:
2325

2426
```js
27+
import remarkLintFinalNewline from 'remark-lint-final-newline'
28+
2529
remark()
26-
.use(require('remark-lint-final-newline'), true)
30+
.use(remarkLintFinalNewline, true)
2731
//
2832
```
2933

3034
Rules can be configured with a severity too. The following ignores all
3135
messages from the plugin:
3236

3337
```js
38+
import remarkLintFinalNewline from 'remark-lint-final-newline'
39+
3440
remark()
35-
.use(require('remark-lint-final-newline'), [0])
41+
.use(remarkLintFinalNewline, [0])
3642
//
3743
```
3844

3945
…and passing `[1]` explicitly sets the normal behavior (warn for problems).
4046
To trigger an error instead of a warning, pass `2`:
4147

4248
```js
49+
import remarkLintFinalNewline from 'remark-lint-final-newline'
50+
4351
remark()
44-
.use(require('remark-lint-final-newline'), [2])
52+
.use(remarkLintFinalNewline, [2])
4553
//
4654
```
4755

4856
It’s also possible to pass both a severity and configuration:
4957

5058
```js
59+
import remarkLintMaximumLineLength from 'remark-lint-maximum-line-length'
60+
5161
remark()
52-
.use(require('remark-lint-maximum-line-length'), [2, 70])
62+
.use(remarkLintMaximumLineLength, [2, 70])
5363
//
5464
```
5565

@@ -58,8 +68,10 @@ Lastly, strings can also be passed, instead of numbers:
5868
`error` instead of `2`.
5969

6070
```js
71+
import remarkLintMaximumLineLength from 'remark-lint-maximum-line-length'
72+
6173
remark()
62-
.use(require('remark-lint-maximum-line-length'), ['error', 70])
74+
.use(remarkLintMaximumLineLength, ['error', 70])
6375
//
6476
```
6577

packages/remark-lint-blockquote-indentation/readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,17 @@ remark -u lint -u lint-blockquote-indentation readme.md
121121
Or use this on the API:
122122

123123
```diff
124-
var remark = require('remark')
125-
var report = require('vfile-reporter')
124+
import {remark} from 'remark'
125+
import {reporter} from 'vfile-reporter'
126+
import remarkLint from 'remark-lint'
127+
import remarkLintBlockquoteIndentation from 'remark-lint-blockquote-indentation'
126128

127129
remark()
128-
.use(require('remark-lint'))
129-
+ .use(require('remark-lint-blockquote-indentation'))
130-
.process('_Emphasis_ and **importance**', function (err, file) {
131-
console.error(report(err || file))
130+
.use(remarkLint)
131+
+ .use(remarkLintBlockquoteIndentation)
132+
.process('_Emphasis_ and **importance**')
133+
.then((file) => {
134+
console.error(reporter(file))
132135
})
133136
```
134137

packages/remark-lint-checkbox-character-style/readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,17 @@ remark -u lint -u lint-checkbox-character-style readme.md
192192
Or use this on the API:
193193

194194
```diff
195-
var remark = require('remark')
196-
var report = require('vfile-reporter')
195+
import {remark} from 'remark'
196+
import {reporter} from 'vfile-reporter'
197+
import remarkLint from 'remark-lint'
198+
import remarkLintCheckboxCharacterStyle from 'remark-lint-checkbox-character-style'
197199

198200
remark()
199-
.use(require('remark-lint'))
200-
+ .use(require('remark-lint-checkbox-character-style'))
201-
.process('_Emphasis_ and **importance**', function (err, file) {
202-
console.error(report(err || file))
201+
.use(remarkLint)
202+
+ .use(remarkLintCheckboxCharacterStyle)
203+
.process('_Emphasis_ and **importance**')
204+
.then((file) => {
205+
console.error(reporter(file))
203206
})
204207
```
205208

packages/remark-lint-checkbox-content-indent/readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,17 @@ remark -u lint -u lint-checkbox-content-indent readme.md
9090
Or use this on the API:
9191

9292
```diff
93-
var remark = require('remark')
94-
var report = require('vfile-reporter')
93+
import {remark} from 'remark'
94+
import {reporter} from 'vfile-reporter'
95+
import remarkLint from 'remark-lint'
96+
import remarkLintCheckboxContentIndent from 'remark-lint-checkbox-content-indent'
9597

9698
remark()
97-
.use(require('remark-lint'))
98-
+ .use(require('remark-lint-checkbox-content-indent'))
99-
.process('_Emphasis_ and **importance**', function (err, file) {
100-
console.error(report(err || file))
99+
.use(remarkLint)
100+
+ .use(remarkLintCheckboxContentIndent)
101+
.process('_Emphasis_ and **importance**')
102+
.then((file) => {
103+
console.error(reporter(file))
101104
})
102105
```
103106

packages/remark-lint-code-block-style/readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,17 @@ remark -u lint -u lint-code-block-style readme.md
190190
Or use this on the API:
191191

192192
```diff
193-
var remark = require('remark')
194-
var report = require('vfile-reporter')
193+
import {remark} from 'remark'
194+
import {reporter} from 'vfile-reporter'
195+
import remarkLint from 'remark-lint'
196+
import remarkLintCodeBlockStyle from 'remark-lint-code-block-style'
195197

196198
remark()
197-
.use(require('remark-lint'))
198-
+ .use(require('remark-lint-code-block-style'))
199-
.process('_Emphasis_ and **importance**', function (err, file) {
200-
console.error(report(err || file))
199+
.use(remarkLint)
200+
+ .use(remarkLintCodeBlockStyle)
201+
.process('_Emphasis_ and **importance**')
202+
.then((file) => {
203+
console.error(reporter(file))
201204
})
202205
```
203206

packages/remark-lint-definition-case/readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,17 @@ remark -u lint -u lint-definition-case readme.md
8282
Or use this on the API:
8383

8484
```diff
85-
var remark = require('remark')
86-
var report = require('vfile-reporter')
85+
import {remark} from 'remark'
86+
import {reporter} from 'vfile-reporter'
87+
import remarkLint from 'remark-lint'
88+
import remarkLintDefinitionCase from 'remark-lint-definition-case'
8789

8890
remark()
89-
.use(require('remark-lint'))
90-
+ .use(require('remark-lint-definition-case'))
91-
.process('_Emphasis_ and **importance**', function (err, file) {
92-
console.error(report(err || file))
91+
.use(remarkLint)
92+
+ .use(remarkLintDefinitionCase)
93+
.process('_Emphasis_ and **importance**')
94+
.then((file) => {
95+
console.error(reporter(file))
9396
})
9497
```
9598

packages/remark-lint-definition-spacing/readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ remark -u lint -u lint-definition-spacing readme.md
8484
Or use this on the API:
8585

8686
```diff
87-
var remark = require('remark')
88-
var report = require('vfile-reporter')
87+
import {remark} from 'remark'
88+
import {reporter} from 'vfile-reporter'
89+
import remarkLint from 'remark-lint'
90+
import remarkLintDefinitionSpacing from 'remark-lint-definition-spacing'
8991

9092
remark()
91-
.use(require('remark-lint'))
92-
+ .use(require('remark-lint-definition-spacing'))
93-
.process('_Emphasis_ and **importance**', function (err, file) {
94-
console.error(report(err || file))
93+
.use(remarkLint)
94+
+ .use(remarkLintDefinitionSpacing)
95+
.process('_Emphasis_ and **importance**')
96+
.then((file) => {
97+
console.error(reporter(file))
9598
})
9699
```
97100

packages/remark-lint-emphasis-marker/readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,17 @@ remark -u lint -u lint-emphasis-marker readme.md
158158
Or use this on the API:
159159

160160
```diff
161-
var remark = require('remark')
162-
var report = require('vfile-reporter')
161+
import {remark} from 'remark'
162+
import {reporter} from 'vfile-reporter'
163+
import remarkLint from 'remark-lint'
164+
import remarkLintEmphasisMarker from 'remark-lint-emphasis-marker'
163165

164166
remark()
165-
.use(require('remark-lint'))
166-
+ .use(require('remark-lint-emphasis-marker'))
167-
.process('_Emphasis_ and **importance**', function (err, file) {
168-
console.error(report(err || file))
167+
.use(remarkLint)
168+
+ .use(remarkLintEmphasisMarker)
169+
.process('_Emphasis_ and **importance**')
170+
.then((file) => {
171+
console.error(reporter(file))
169172
})
170173
```
171174

packages/remark-lint-fenced-code-flag/readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,17 @@ remark -u lint -u lint-fenced-code-flag readme.md
163163
Or use this on the API:
164164

165165
```diff
166-
var remark = require('remark')
167-
var report = require('vfile-reporter')
166+
import {remark} from 'remark'
167+
import {reporter} from 'vfile-reporter'
168+
import remarkLint from 'remark-lint'
169+
import remarkLintFencedCodeFlag from 'remark-lint-fenced-code-flag'
168170

169171
remark()
170-
.use(require('remark-lint'))
171-
+ .use(require('remark-lint-fenced-code-flag'))
172-
.process('_Emphasis_ and **importance**', function (err, file) {
173-
console.error(report(err || file))
172+
.use(remarkLint)
173+
+ .use(remarkLintFencedCodeFlag)
174+
.process('_Emphasis_ and **importance**')
175+
.then((file) => {
176+
console.error(reporter(file))
174177
})
175178
```
176179

0 commit comments

Comments
 (0)