eslint-plugin-markdown-preferences 0.2.0 → 0.3.1
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 +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +121 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,6 +92,7 @@ The rules with the following star ⭐ are included in the configs.
|
|
|
92
92
|
|:--------|:------------|:-------:|:-----------:|
|
|
93
93
|
| [markdown-preferences/hard-linebreak-style](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/hard-linebreak-style.html) | enforce consistent hard linebreak style. | 🔧 | ⭐ |
|
|
94
94
|
| [markdown-preferences/no-text-backslash-linebreak](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-text-backslash-linebreak.html) | disallow text backslash at the end of a line. | | ⭐ |
|
|
95
|
+
| [markdown-preferences/no-trailing-spaces](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-trailing-spaces.html) | trailing whitespace at the end of lines in Markdown files. | 🔧 | |
|
|
95
96
|
| [markdown-preferences/prefer-linked-words](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/prefer-linked-words.html) | enforce the specified word to be a link. | 🔧 | |
|
|
96
97
|
|
|
97
98
|
<!--RULES_TABLE_END-->
|
package/lib/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare namespace meta_d_exports {
|
|
|
19
19
|
export { name, version };
|
|
20
20
|
}
|
|
21
21
|
declare const name: "eslint-plugin-markdown-preferences";
|
|
22
|
-
declare const version: "0.
|
|
22
|
+
declare const version: "0.3.1";
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region src/index.d.ts
|
|
25
25
|
declare const configs: {
|
package/lib/index.js
CHANGED
|
@@ -124,6 +124,125 @@ var no_text_backslash_linebreak_default = createRule("no-text-backslash-linebrea
|
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/rules/no-trailing-spaces.ts
|
|
129
|
+
const htmlComment = /<!--.*?-->/su;
|
|
130
|
+
var no_trailing_spaces_default = createRule("no-trailing-spaces", {
|
|
131
|
+
meta: {
|
|
132
|
+
type: "layout",
|
|
133
|
+
docs: {
|
|
134
|
+
description: "trailing whitespace at the end of lines in Markdown files.",
|
|
135
|
+
categories: []
|
|
136
|
+
},
|
|
137
|
+
fixable: "whitespace",
|
|
138
|
+
hasSuggestions: false,
|
|
139
|
+
schema: [{
|
|
140
|
+
type: "object",
|
|
141
|
+
properties: {
|
|
142
|
+
skipBlankLines: {
|
|
143
|
+
type: "boolean",
|
|
144
|
+
default: false
|
|
145
|
+
},
|
|
146
|
+
ignoreComments: {
|
|
147
|
+
type: "boolean",
|
|
148
|
+
default: false
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
additionalProperties: false
|
|
152
|
+
}],
|
|
153
|
+
messages: { trailingSpace: "Trailing spaces not allowed." }
|
|
154
|
+
},
|
|
155
|
+
create(context) {
|
|
156
|
+
const sourceCode = context.sourceCode;
|
|
157
|
+
const options = context.options[0] || {};
|
|
158
|
+
const skipBlankLines = options.skipBlankLines || false;
|
|
159
|
+
const ignoreComments = options.ignoreComments || false;
|
|
160
|
+
const comments = [];
|
|
161
|
+
const ignoreNodes = [];
|
|
162
|
+
/**
|
|
163
|
+
* Report the error message
|
|
164
|
+
* @param node node to report
|
|
165
|
+
* @param location range information
|
|
166
|
+
* @param fixRange Range based on the whole program
|
|
167
|
+
* @returns {void}
|
|
168
|
+
*/
|
|
169
|
+
function report(location, fixRange) {
|
|
170
|
+
context.report({
|
|
171
|
+
loc: location,
|
|
172
|
+
messageId: "trailingSpace",
|
|
173
|
+
fix(fixer) {
|
|
174
|
+
return fixer.removeRange(fixRange);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Given a list of comment nodes, return the line numbers for those comments.
|
|
180
|
+
* @returns {Set<number>} A set of line numbers containing comments.
|
|
181
|
+
*/
|
|
182
|
+
function getCommentLineNumbers() {
|
|
183
|
+
const lines = /* @__PURE__ */ new Set();
|
|
184
|
+
comments.forEach((comment) => {
|
|
185
|
+
const loc = sourceCode.getLoc(comment);
|
|
186
|
+
const endLine = loc.end.line - 1;
|
|
187
|
+
for (let i = loc.start.line; i <= endLine; i++) lines.add(i);
|
|
188
|
+
});
|
|
189
|
+
return lines;
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
html(node) {
|
|
193
|
+
if (htmlComment.test(node.value)) comments.push(node);
|
|
194
|
+
},
|
|
195
|
+
"break, code, inlineCode, text, yaml, toml, json"(node) {
|
|
196
|
+
ignoreNodes.push(node);
|
|
197
|
+
},
|
|
198
|
+
"root:exit"() {
|
|
199
|
+
const re = /[^\S\n\r]+$/u;
|
|
200
|
+
const skipMatch = /^[^\S\n\r]*$/u;
|
|
201
|
+
const lines = sourceCode.lines;
|
|
202
|
+
const linebreaks = sourceCode.text.match(/\r?\n/gu);
|
|
203
|
+
const commentLineNumbers = getCommentLineNumbers();
|
|
204
|
+
let totalLength = 0;
|
|
205
|
+
for (let i = 0, ii = lines.length; i < ii; i++) {
|
|
206
|
+
const lineNumber = i + 1;
|
|
207
|
+
const linebreakLength = linebreaks && linebreaks[i] ? linebreaks[i].length : 1;
|
|
208
|
+
const lineLength = lines[i].length + linebreakLength;
|
|
209
|
+
const matches = re.exec(lines[i]);
|
|
210
|
+
if (!matches) {
|
|
211
|
+
totalLength += lineLength;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const location = {
|
|
215
|
+
start: {
|
|
216
|
+
line: lineNumber,
|
|
217
|
+
column: matches.index + 1
|
|
218
|
+
},
|
|
219
|
+
end: {
|
|
220
|
+
line: lineNumber,
|
|
221
|
+
column: lineLength + 1 - linebreakLength
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const rangeStart = totalLength + location.start.column - 1;
|
|
225
|
+
const rangeEnd = totalLength + location.end.column - 1;
|
|
226
|
+
if (ignoreNodes.some((node) => {
|
|
227
|
+
const range = sourceCode.getRange(node);
|
|
228
|
+
return range[0] <= rangeStart && rangeEnd <= range[1];
|
|
229
|
+
})) {
|
|
230
|
+
totalLength += lineLength;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (skipBlankLines && skipMatch.test(lines[i])) {
|
|
234
|
+
totalLength += lineLength;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const fixRange = [rangeStart, rangeEnd];
|
|
238
|
+
if (!ignoreComments || !commentLineNumbers.has(lineNumber)) report(location, fixRange);
|
|
239
|
+
totalLength += lineLength;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
127
246
|
//#endregion
|
|
128
247
|
//#region src/rules/prefer-linked-words.ts
|
|
129
248
|
const RE_PUNCTUATOR = /^[\s,:]*$/u;
|
|
@@ -227,6 +346,7 @@ var prefer_linked_words_default = createRule("prefer-linked-words", {
|
|
|
227
346
|
const rules$1 = [
|
|
228
347
|
hard_linebreak_style_default,
|
|
229
348
|
no_text_backslash_linebreak_default,
|
|
349
|
+
no_trailing_spaces_default,
|
|
230
350
|
prefer_linked_words_default
|
|
231
351
|
];
|
|
232
352
|
|
|
@@ -262,7 +382,7 @@ __export(meta_exports, {
|
|
|
262
382
|
version: () => version
|
|
263
383
|
});
|
|
264
384
|
const name = "eslint-plugin-markdown-preferences";
|
|
265
|
-
const version = "0.
|
|
385
|
+
const version = "0.3.1";
|
|
266
386
|
|
|
267
387
|
//#endregion
|
|
268
388
|
//#region src/index.ts
|