@diplodoc/yfmlint 1.3.3 → 1.3.4

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