-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathindex.js
180 lines (174 loc) · 3.92 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* unified helper to help make lint rules.
*
* ## What is this?
*
* This package is a helper that makes it a bit easier to create linting rules.
*
* ## When should I use this?
*
* You can use this package when you want to make custom lint rules.
*
* ## Use
*
* ```js
* import {lintRule} from 'unified-lint-rule'
*
* const remarkLintFileExtension = lintRule(
* 'remark-lint:file-extension',
* function (tree, file, options) {
* const ext = file.extname
* const option = options || 'md'
*
* if (ext && ext.slice(1) !== option) {
* file.message('Incorrect extension: use `' + option + '`')
* }
* }
* )
*
* export default remarkLintFileExtension
* ```
*
* ## API
*
* ### `lintRule(meta, rule)`
*
* Create a plugin.
*
* ###### Parameters
*
* * `meta` ([`Meta`][api-meta] or `string`)
* — info or origin
* * `rule` ([`Rule`][api-rule])
* — rule
*
* ###### Returns
*
* Plugin ([`Plugin` from `unified`][github-unified-plugin]).
*
* ### `Label`
*
* Severity label (TypeScript type);
* `'off'`: `0`, `'on'` and `warn`: `1`, `'error'`: `2`.
*
* ###### Type
*
* ```ts
* type Label = 'error' | 'on' | 'off' | 'warn'
* ```
*
* ### `Meta`
*
* Rule metadata (TypeScript type).
*
* ###### Fields
*
* * `origin` (`string`)
* — name of the lint rule
* * `url` (`string`, optional)
* — link to documentation
*
* ### `Next`
*
* Callback passed to rules (TypeScript type).
*
* If the signature of a rule accepts a fourth argument,
* the rule may perform asynchronous operations,
* and must call it.
*
* ###### Parameters
*
* * `error` (`Error`, optional)
* — fatal error to stop linting
*
* ###### Returns
*
* Nothing (`undefined`).
*
* ### `Rule`
*
* Rule (TypeScript type).
*
* ###### Parameters
*
* * `tree` ([`Node` from `unist`][github-unist-node])
* — tree
* * `file` ([`VFile`][github-vfile])
* — file
* * `options` (`unknown`, optional)
* — parameter
*
* ###### Returns
*
* Nothing (`Promise<undefined>` or `undefined`).
*
* ### `Severity`
*
* Severity number (TypeScript type);
* `0`: `'off'`, `1`: `'on'` and `warn`, `2`: `'error'`.
*
* ###### Type
*
* ```ts
* type Severity = 0 | 1 | 2
* ```
*
* [api-label]: #label
* [api-meta]: #meta
* [api-next]: #next
* [api-rule]: #rule
* [api-severity]: #severity
* [api-lint-rule]: #lintrulemeta-rule
* [github-unist-node]: https://github.com/syntax-tree/unist#node
* [github-unified-plugin]: https://github.com/unifiedjs/unified#plugin
* [github-vfile]: https://github.com/vfile/vfile
*/
/**
* @import {TransformCallback} from 'unified'
* @import {Node} from 'unist'
* @import {VFile} from 'vfile'
*/
// To do: define somewhere else.
/**
* @typedef {import('./lib/index.js').Label} Label
* @typedef {import('./lib/index.js').Meta} Meta
* @typedef {import('./lib/index.js').Severity} Severity
*/
/**
* @callback Next
* Callback passed to rules.
*
* If the signature of a rule accepts a fourth argument,
* the rule may perform asynchronous operations,
* and must call it.
* @param {Error | undefined} [error]
* Fatal error to stop linting (optional).
* @returns {undefined}
* Nothing.
*/
/**
* @template {Node} [Tree=Node]
* Node kind (optional).
* @template {unknown} [Option=unknown]
* Parameter kind (optional).
* @callback Rule
* Rule.
* @param {Tree} tree
* Tree.
* @param {VFile} file
* File.
* @param {Option} option
* Parameter.
* @param {Next} next
* Parameter.
* @returns {Promise<undefined | void> | undefined | void}
* Nothing.
*/
/**
* @template {Node} [Tree=Node]
* Node kind (optional).
* @template {unknown} [Option=unknown]
* Parameter kind (optional).
* @typedef {(config?: [level: Label | Severity | boolean, option?: Option] | Label | Option | Severity) => ((tree: Tree, file: VFile, next: TransformCallback<Tree>) => undefined) | undefined} Plugin
*/
export {lintRule} from './lib/index.js'