@diplodoc/yfmlint 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +184 -33
- package/build/index.js +564 -603
- package/build/index.js.map +4 -4
- package/build/rules/helpers.d.ts +49 -0
- package/build/typings.d.ts +3 -1
- package/build/utils.d.ts +22 -0
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -1,75 +1,226 @@
|
|
|
1
1
|
[](https://www.npmjs.org/package/@diplodoc/yfmlint)
|
|
2
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
|
|
3
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
|
|
4
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
|
|
5
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
|
|
6
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
|
|
2
7
|
|
|
3
8
|
# YFM syntax linter
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
YFM (Yandex Flavored Markdown) syntax linter with custom rules for Diplodoc platform. Extends [markdownlint](https://github.com/DavidAnson/markdownlint) with YFM-specific validation rules.
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **11 custom YFM rules** (YFM001-YFM011) for validating YFM-specific syntax
|
|
15
|
+
- **Integration with markdownlint** - all standard markdownlint rules are available
|
|
16
|
+
- **Plugin support** - integrates with plugins from `@diplodoc/transform` (e.g., `term` plugin)
|
|
17
|
+
- **Configurable rule levels** - error, warn, info, or disabled
|
|
18
|
+
- **Source map support** - accurate error reporting after Liquid template processing
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
8
23
|
npm install @diplodoc/yfmlint
|
|
9
24
|
```
|
|
10
25
|
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Basic Example
|
|
29
|
+
|
|
11
30
|
```javascript
|
|
12
|
-
import {yfmlint, log} from '@diplodoc/yfmlint';
|
|
31
|
+
import {yfmlint, log, LogLevels} from '@diplodoc/yfmlint';
|
|
32
|
+
|
|
33
|
+
const content = `# Title
|
|
13
34
|
|
|
14
|
-
|
|
35
|
+
[Link to missing file](./missing.md)
|
|
36
|
+
`;
|
|
15
37
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
38
|
+
const errors = await yfmlint(content, 'example.md', {
|
|
39
|
+
lintConfig: {
|
|
40
|
+
YFM003: LogLevels.ERROR, // Unreachable link
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (errors && errors.length > 0) {
|
|
45
|
+
log(errors, console);
|
|
19
46
|
}
|
|
20
47
|
```
|
|
21
48
|
|
|
22
|
-
|
|
49
|
+
### With Plugins
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
import {yfmlint} from '@diplodoc/yfmlint';
|
|
53
|
+
import termPlugin from '@diplodoc/transform/plugins/term';
|
|
54
|
+
|
|
55
|
+
const errors = await yfmlint(content, path, {
|
|
56
|
+
plugins: [termPlugin],
|
|
57
|
+
pluginOptions: {
|
|
58
|
+
// Plugin-specific options
|
|
59
|
+
},
|
|
60
|
+
lintConfig: {
|
|
61
|
+
YFM007: true, // Term used without definition
|
|
62
|
+
YFM009: 'warn', // Term definition not at end of file
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Configuration
|
|
23
68
|
|
|
24
|
-
|
|
69
|
+
Rules can be configured with different log levels:
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const lintConfig = {
|
|
73
|
+
// Boolean: true = warn, false = disabled
|
|
74
|
+
YFM001: true,
|
|
75
|
+
YFM002: false,
|
|
76
|
+
|
|
77
|
+
// String: log level name
|
|
78
|
+
YFM003: 'error',
|
|
79
|
+
YFM004: 'warn',
|
|
80
|
+
YFM005: 'info',
|
|
81
|
+
|
|
82
|
+
// Object: full configuration
|
|
83
|
+
YFM001: {
|
|
84
|
+
level: 'warn',
|
|
85
|
+
maximum: 120, // Custom parameter
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Documentation
|
|
91
|
+
|
|
92
|
+
For detailed information about architecture, development, and contributing, see [AGENTS.md](./AGENTS.md).
|
|
93
|
+
|
|
94
|
+
## YFM Rules
|
|
95
|
+
|
|
96
|
+
This package extends markdownlint with 11 custom rules for YFM syntax validation. All standard [markdownlint rules](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md) are also available.
|
|
25
97
|
|
|
26
98
|
### YFM001 - Inline code line length
|
|
27
99
|
|
|
28
|
-
Tags
|
|
100
|
+
**Tags:** `line_length`
|
|
101
|
+
**Aliases:** `inline-code-length`
|
|
102
|
+
**Parameters:** `maximum` (default: 100)
|
|
29
103
|
|
|
30
|
-
|
|
104
|
+
Validates that inline code spans don't exceed the maximum length. Useful for preventing overly long inline code that breaks formatting.
|
|
31
105
|
|
|
32
|
-
|
|
106
|
+
**Example:**
|
|
33
107
|
|
|
34
|
-
|
|
35
|
-
|
|
108
|
+
```markdown
|
|
109
|
+
`this is a very long inline code that exceeds the maximum length and will trigger YFM001`
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### YFM002 - No header found for link
|
|
36
113
|
|
|
37
|
-
|
|
114
|
+
**Tags:** `links`
|
|
115
|
+
**Aliases:** `no-header-found-for-link`
|
|
38
116
|
|
|
39
|
-
|
|
117
|
+
Validates that links to headers (anchors) reference existing headers in the target file.
|
|
40
118
|
|
|
41
|
-
|
|
119
|
+
**Example:**
|
|
42
120
|
|
|
43
|
-
|
|
121
|
+
```markdown
|
|
122
|
+
[Link to non-existent header](./file.md#nonexistent)
|
|
123
|
+
```
|
|
44
124
|
|
|
45
|
-
### YFM003 -
|
|
125
|
+
### YFM003 - Unreachable link
|
|
46
126
|
|
|
47
|
-
Tags
|
|
127
|
+
**Tags:** `links`
|
|
128
|
+
**Aliases:** `unreachable-link`
|
|
48
129
|
|
|
49
|
-
|
|
130
|
+
Validates that linked files exist and are accessible. Checks for:
|
|
50
131
|
|
|
51
|
-
|
|
132
|
+
- File not found
|
|
133
|
+
- File missing in table of contents
|
|
134
|
+
- Both conditions
|
|
52
135
|
|
|
53
|
-
|
|
136
|
+
**Example:**
|
|
54
137
|
|
|
55
|
-
|
|
138
|
+
```markdown
|
|
139
|
+
[Link to missing file](./missing.md)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### YFM004 - Table not closed
|
|
56
143
|
|
|
57
|
-
|
|
144
|
+
**Tags:** `table`
|
|
145
|
+
**Aliases:** `table-not-closed`
|
|
58
146
|
|
|
59
|
-
|
|
147
|
+
Validates that YFM tables are properly closed. Requires the `table` plugin from `@diplodoc/transform`.
|
|
60
148
|
|
|
61
149
|
### YFM005 - Tab list not closed
|
|
62
150
|
|
|
63
|
-
Tags
|
|
151
|
+
**Tags:** `tab`
|
|
152
|
+
**Aliases:** `tab-list-not-closed`
|
|
64
153
|
|
|
65
|
-
|
|
154
|
+
Validates that YFM tab lists are properly closed. Requires the `tabs` plugin from `@diplodoc/transform`.
|
|
66
155
|
|
|
67
|
-
|
|
156
|
+
### YFM006 - Term definition duplicated
|
|
68
157
|
|
|
69
|
-
|
|
158
|
+
**Tags:** `term`
|
|
159
|
+
**Aliases:** `term-definition-duplicated`
|
|
160
|
+
|
|
161
|
+
Validates that term definitions are not duplicated. Requires the `term` plugin from `@diplodoc/transform`.
|
|
162
|
+
|
|
163
|
+
**Example:**
|
|
164
|
+
|
|
165
|
+
```markdown
|
|
166
|
+
[term]: definition
|
|
167
|
+
|
|
168
|
+
[term]: another definition <!-- Error: duplicate definition -->
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### YFM007 - Term used without definition
|
|
172
|
+
|
|
173
|
+
**Tags:** `term`
|
|
174
|
+
**Aliases:** `term-used-without-definition`
|
|
175
|
+
|
|
176
|
+
Validates that all used terms have corresponding definitions. Requires the `term` plugin from `@diplodoc/transform`.
|
|
177
|
+
|
|
178
|
+
**Example:**
|
|
179
|
+
|
|
180
|
+
```markdown
|
|
181
|
+
This uses [term] but no definition is provided.
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### YFM008 - Term inside definition not allowed
|
|
185
|
+
|
|
186
|
+
**Tags:** `term`
|
|
187
|
+
**Aliases:** `term-inside-definition-not-allowed`
|
|
188
|
+
|
|
189
|
+
Validates that term definitions don't contain other terms. Requires the `term` plugin from `@diplodoc/transform`.
|
|
190
|
+
|
|
191
|
+
### YFM009 - Term definition not at end of file
|
|
192
|
+
|
|
193
|
+
**Tags:** `term`
|
|
194
|
+
**Aliases:** `no-term-definition-in-content`
|
|
195
|
+
|
|
196
|
+
Validates that all term definitions are placed at the end of the file. Requires the `term` plugin from `@diplodoc/transform`.
|
|
197
|
+
|
|
198
|
+
**Example:**
|
|
199
|
+
|
|
200
|
+
```markdown
|
|
201
|
+
[term]: definition
|
|
202
|
+
|
|
203
|
+
Some content here <!-- Error: content after term definitions -->
|
|
204
|
+
|
|
205
|
+
[another-term]: another definition
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### YFM010 - Unreachable autotitle anchor
|
|
209
|
+
|
|
210
|
+
**Tags:** `titles`
|
|
211
|
+
**Aliases:** `unreachable-autotitle-anchor`
|
|
212
|
+
|
|
213
|
+
Validates that links to autotitle anchors reference existing titles.
|
|
214
|
+
|
|
215
|
+
**Example:**
|
|
216
|
+
|
|
217
|
+
```markdown
|
|
218
|
+
[Link to non-existent title](#nonexistent-title)
|
|
219
|
+
```
|
|
70
220
|
|
|
71
|
-
|
|
221
|
+
### YFM011 - Max SVG size
|
|
72
222
|
|
|
73
|
-
|
|
223
|
+
**Tags:** `image_svg`
|
|
224
|
+
**Aliases:** `max-svg-size`
|
|
74
225
|
|
|
75
|
-
|
|
226
|
+
Validates that SVG images don't exceed the maximum size limit. Requires image processing plugins from `@diplodoc/transform`.
|