7
7
[ ![ Backers] [ backers-badge ]] [ collective ]
8
8
[ ![ Chat] [ chat-badge ]] [ chat ]
9
9
10
- [ ** unified** ] [ unified ] plugin to ignore unrelated messages.
11
- Currently works in PRs on Travis and GitHub Actions .
10
+ ** [ unified] [ ] ** plugin to ignore unrelated messages in GitHub Actions and
11
+ Travis.
12
12
13
- When working with natural language, having tools that check cumbersome tasks
14
- can be very useful (think [ alex] [ ] or [ retext] [ ] plugins).
15
- However, natural language isn’t as strict as code.
16
- Integrating natural language checking in a CI often doesn’t work well due to
17
- false positives.
18
- It’s possible to add a long list of exceptions, but this soon becomes
19
- unmanageable.
13
+ ## Contents
20
14
21
- This plugin solves that problem, when in CIs, by ignoring any messages on
22
- unchanged lines.
23
- When run outside supported CIs this plugin doesn’t do anything.
15
+ * [ What is this?] ( #what-is-this )
16
+ * [ When should I use this?] ( #when-should-i-use-this )
17
+ * [ Install] ( #install )
18
+ * [ Use] ( #use )
19
+ * [ API] ( #api )
20
+ * [ ` unified().use(unifiedDiff) ` ] ( #unifieduseunifieddiff )
21
+ * [ Types] ( #types )
22
+ * [ Compatibility] ( #compatibility )
23
+ * [ Contribute] ( #contribute )
24
+ * [ License] ( #license )
24
25
25
- ## Install
26
+ ## What is this?
27
+
28
+ This package is a [ unified] [ ] plugin to ignore unrelated lint messages in a CI.
29
+
30
+ ** unified** is a project that transforms content with abstract syntax trees
31
+ (ASTs).
32
+ ** vfile** is the virtual file interface used in unified which manages messages.
33
+ This is a unified plugin that filters messages on the vfile.
26
34
27
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
28
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
35
+ ## When should I use this?
29
36
30
- [ npm] [ ] :
37
+ You can use this plugin when you are dealing with a large, existing project.
38
+
39
+ Using tools that check whether things follow a style guide is typically very
40
+ useful.
41
+ However, it can be hard to start using something in a large existing project.
42
+ This plugin helps, because it ignores messages that occur in lines that are not
43
+ touched by a PR in a CI.
44
+ When this plugin is used outside of a supported CIs, it doesn’t do anything.
45
+
46
+ ## Install
47
+
48
+ This package is [ ESM only] [ esm ] .
49
+ In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [ npm] [ ] :
31
50
32
51
``` sh
33
52
npm install unified-diff
34
53
```
35
54
55
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
56
+
57
+ ``` js
58
+ import unifiedDiff from ' https://esm.sh/unified-diff@4'
59
+ ```
60
+
61
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
62
+
63
+ ``` html
64
+ <script type =" module" >
65
+ import unifiedDiff from ' https://esm.sh/unified-diff@4?bundle'
66
+ </script >
67
+ ```
68
+
36
69
## Use
37
70
38
- Say we have this ` readme.md ` .
39
- Note the ` an an ` .
71
+ Say our document ` example.md ` contains:
40
72
41
73
``` markdown
42
74
This is an an example.
43
75
```
44
76
45
- Then, someone creates a PR which adds the following diff:
46
-
47
- ``` diff
48
- diff --git a/readme.md b/readme.md
49
- index 360b225..5a96b86 100644
50
- --- a/readme.md
51
- +++ b/readme.md
52
- @@ -1 +1,3 @@
53
- This is an an example.
54
- +
55
- + Some more more text. A error.
56
- ```
77
+ > 👉 ** Note** : ` an an ` is a typo.
57
78
58
- We have some natural language checking in ` lint .js` :
79
+ …and our module ` example .js` looks as follows :
59
80
60
81
``` js
61
- import {toVFile } from ' to-vfile'
82
+ import {read } from ' to-vfile'
62
83
import {reporter } from ' vfile-reporter'
63
84
import {unified } from ' unified'
64
85
import unifiedDiff from ' unified-diff'
@@ -69,57 +90,70 @@ import retextEnglish from 'retext-english'
69
90
import retextRepeatedWords from ' retext-repeated-words'
70
91
import retextIndefiniteArticle from ' retext-indefinite-article'
71
92
72
- toVFile .read (' readme.md' ).then ((file ) => {
73
- unified ()
74
- .use (remarkParse)
75
- .use (
76
- remarkRetext,
77
- unified ()
78
- .use (retextEnglish)
79
- .use (retextRepeatedWords)
80
- .use (retextIndefiniteArticle)
81
- )
82
- .use (remarkStringify)
83
- .use (unifiedDiff)
84
- .process (file)
85
- .then ((file ) => {
86
- console .error (reporter (file))
87
- process .exit (file .messages .length > 0 ? 1 : 0 )
88
- })
89
- })
93
+ const file = unified ()
94
+ .use (remarkParse)
95
+ .use (
96
+ remarkRetext,
97
+ unified ()
98
+ .use (retextEnglish)
99
+ .use (retextRepeatedWords)
100
+ .use (retextIndefiniteArticle)
101
+ )
102
+ .use (remarkStringify)
103
+ .use (unifiedDiff)
104
+ .process (await read (' example.md' ))
105
+
106
+ console .error (reporter (file))
107
+ process .exit (file .messages .length > 0 ? 1 : 0 )
90
108
```
91
109
92
- ` lint.js ` is hooked up to run on Travis in ` .travis.yml ` like so :
110
+ …and our Travis configuration ` .travis.yml ` contains :
93
111
94
112
``` yml
95
- # ...
113
+ # …
96
114
script :
97
115
- npm test
98
- - node lint.js
99
- # ...
116
+ - node example.js
117
+ # …
118
+ ```
119
+
120
+ > 👉 ** Note** : an equivalent GH Actions workflow file is also supported.
121
+
122
+ Then, say someone creates a PR which adds the following diff:
123
+
124
+ ``` diff
125
+ diff --git a/example.md b/example.md
126
+ index 360b225..5a96b86 100644
127
+ --- a/example.md
128
+ +++ b/example.md
129
+ @@ -1 +1,3 @@
130
+ This is an an example.
131
+ +
132
+ + Some more more text. A error.
100
133
```
101
134
102
- (or in an equivalent GH Actions workflow file)
135
+ > 👉 ** Note ** : ` more more ` and ` A ` before ` error ` are typos.
103
136
104
137
When run in CI, we’ll see the following printed on ** stderr** (4).
105
- Note that ` an an ` on L1 is not included because it’s unrelated to this PR.
106
138
107
139
``` txt
108
- readme .md
140
+ example .md
109
141
3:6-3:15 warning Expected `more` once, not twice retext-repeated-words retext-repeated-words
110
142
3:22-3:23 warning Use `An` before `error`, not `A` retext-indefinite-article retext-indefinite-article
111
143
112
144
⚠ 2 warnings
113
145
```
114
146
115
- As there are messages, the build exits with ` 1 ` , thus failing CI.
147
+ > 👉 ** Note** : ` an an ` on L1 is not included because it’s unrelated to this PR.
148
+
149
+ The build exits with ` 1 ` as there are messages, thus failing CI.
116
150
The user sees this and amends the PR to the following:
117
151
118
152
``` diff
119
- diff --git a/readme .md b/readme .md
153
+ diff --git a/example .md b/example .md
120
154
index 360b225..5a96b86 100644
121
- --- a/readme .md
122
- +++ b/readme .md
155
+ --- a/example .md
156
+ +++ b/example .md
123
157
@@ -1 +1,3 @@
124
158
This is an an example.
125
159
+
@@ -131,11 +165,12 @@ an error, but it’s unrelated to the PR.
131
165
132
166
## API
133
167
134
- This package exports a plugin as the default export.
168
+ This package exports no identifiers.
169
+ The default export is ` unifiedDiff ` .
135
170
136
- ### ` unified().use(diff ) `
171
+ ### ` unified().use(unifiedDiff ) `
137
172
138
- Ignore messages emitted by plugins before ` diff ` for lines that did not change .
173
+ Ignore unrelated messages in GitHub Actions and Travis .
139
174
140
175
There are no options.
141
176
If there’s a ` TRAVIS_COMMIT_RANGE ` , ` GITHUB_BASE_REF ` and ` GITHUB_HEAD_REF ` , or
@@ -145,10 +180,22 @@ nothing.
145
180
###### To do
146
181
147
182
* [ ] Add support for other CIs (ping if you want to work on this)
148
- * [ ] Add non-CI support (I’m not yet sure how though)
183
+ * [ ] Add non-CI support (I’m not sure how though)
149
184
150
185
PRs welcome!
151
186
187
+ ## Types
188
+
189
+ This package is fully typed with [ TypeScript] [ ] .
190
+ There are no additional exported types.
191
+
192
+ ## Compatibility
193
+
194
+ Projects maintained by the unified collective are compatible with all maintained
195
+ versions of Node.js.
196
+ As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
197
+ Our projects sometimes work with older versions, but this is not guaranteed.
198
+
152
199
## Contribute
153
200
154
201
See [ ` contributing.md ` ] [ contributing ] in [ ` unifiedjs/.github ` ] [ health ] for ways
@@ -189,20 +236,22 @@ abide by its terms.
189
236
190
237
[ npm ] : https://docs.npmjs.com/cli/install
191
238
239
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
240
+
241
+ [ esmsh ] : https://esm.sh
242
+
243
+ [ typescript ] : https://www.typescriptlang.org
244
+
192
245
[ health ] : https://github.com/unifiedjs/.github
193
246
194
- [ contributing ] : https://github.com/unifiedjs/.github/blob/HEAD /contributing.md
247
+ [ contributing ] : https://github.com/unifiedjs/.github/blob/main /contributing.md
195
248
196
- [ support ] : https://github.com/unifiedjs/.github/blob/HEAD /support.md
249
+ [ support ] : https://github.com/unifiedjs/.github/blob/main /support.md
197
250
198
- [ coc ] : https://github.com/unifiedjs/.github/blob/HEAD /code-of-conduct.md
251
+ [ coc ] : https://github.com/unifiedjs/.github/blob/main /code-of-conduct.md
199
252
200
253
[ license ] : license
201
254
202
255
[ author ] : https://wooorm.com
203
256
204
257
[ unified ] : https://github.com/unifiedjs/unified
205
-
206
- [ alex ] : https://github.com/wooorm/alex
207
-
208
- [ retext ] : https://github.com/retextjs/retext/blob/HEAD/doc/plugins.md#list-of-plugins
0 commit comments