eslint-plugin-markdown-preferences 0.1.1 → 0.3.0
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 +2 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +185 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,6 +91,8 @@ The rules with the following star ⭐ are included in the configs.
|
|
|
91
91
|
| Rule ID | Description | Fixable | RECOMMENDED |
|
|
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
|
+
| [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. | 🔧 | |
|
|
94
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. | 🔧 | |
|
|
95
97
|
|
|
96
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.0";
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region src/index.d.ts
|
|
25
25
|
declare const configs: {
|
package/lib/index.js
CHANGED
|
@@ -69,6 +69,180 @@ var hard_linebreak_style_default = createRule("hard-linebreak-style", {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/rules/no-text-backslash-linebreak.ts
|
|
74
|
+
var no_text_backslash_linebreak_default = createRule("no-text-backslash-linebreak", {
|
|
75
|
+
meta: {
|
|
76
|
+
type: "suggestion",
|
|
77
|
+
docs: {
|
|
78
|
+
description: "disallow text backslash at the end of a line.",
|
|
79
|
+
categories: ["recommended"]
|
|
80
|
+
},
|
|
81
|
+
fixable: void 0,
|
|
82
|
+
hasSuggestions: true,
|
|
83
|
+
schema: [],
|
|
84
|
+
messages: {
|
|
85
|
+
textBackslashWithLinebreak: "Text backslash at the end of a line is not allowed.",
|
|
86
|
+
removeBackslash: "Remove the backslash."
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
create(context) {
|
|
90
|
+
const sourceCode = context.sourceCode;
|
|
91
|
+
return { text(node) {
|
|
92
|
+
if (!node.value.endsWith("\\")) return;
|
|
93
|
+
const range = sourceCode.getRange(node);
|
|
94
|
+
for (let i = range[1]; i < sourceCode.text.length; i++) {
|
|
95
|
+
const c = sourceCode.text[i];
|
|
96
|
+
if (c.trim() !== "") return;
|
|
97
|
+
if (c === "\n") break;
|
|
98
|
+
}
|
|
99
|
+
const loc = sourceCode.getLoc(node);
|
|
100
|
+
const beforeLines = sourceCode.text.slice(range[0], range[1] - 1).split(/\n/u);
|
|
101
|
+
const line = loc.start.line + beforeLines.length - 1;
|
|
102
|
+
const column = (beforeLines.length === 1 ? loc.start.column : 1) + (beforeLines.at(-1) || "").length;
|
|
103
|
+
context.report({
|
|
104
|
+
node,
|
|
105
|
+
loc: {
|
|
106
|
+
start: {
|
|
107
|
+
line,
|
|
108
|
+
column
|
|
109
|
+
},
|
|
110
|
+
end: {
|
|
111
|
+
line,
|
|
112
|
+
column: column + 1
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
messageId: "textBackslashWithLinebreak",
|
|
116
|
+
suggest: [{
|
|
117
|
+
messageId: "removeBackslash",
|
|
118
|
+
fix: (fixer) => {
|
|
119
|
+
return fixer.removeRange([range[1] - 1, range[1]]);
|
|
120
|
+
}
|
|
121
|
+
}]
|
|
122
|
+
});
|
|
123
|
+
} };
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/rules/no-trailing-spaces.ts
|
|
129
|
+
const htmlComment = /<!--.*?-->/gsu;
|
|
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
|
+
|
|
72
246
|
//#endregion
|
|
73
247
|
//#region src/rules/prefer-linked-words.ts
|
|
74
248
|
const RE_PUNCTUATOR = /^[\s,:]*$/u;
|
|
@@ -169,7 +343,12 @@ var prefer_linked_words_default = createRule("prefer-linked-words", {
|
|
|
169
343
|
|
|
170
344
|
//#endregion
|
|
171
345
|
//#region src/utils/rules.ts
|
|
172
|
-
const rules$1 = [
|
|
346
|
+
const rules$1 = [
|
|
347
|
+
hard_linebreak_style_default,
|
|
348
|
+
no_text_backslash_linebreak_default,
|
|
349
|
+
no_trailing_spaces_default,
|
|
350
|
+
prefer_linked_words_default
|
|
351
|
+
];
|
|
173
352
|
|
|
174
353
|
//#endregion
|
|
175
354
|
//#region src/configs/recommended.ts
|
|
@@ -190,7 +369,10 @@ const plugins = {
|
|
|
190
369
|
return src_default;
|
|
191
370
|
}
|
|
192
371
|
};
|
|
193
|
-
const rules$2 = {
|
|
372
|
+
const rules$2 = {
|
|
373
|
+
"markdown-preferences/hard-linebreak-style": "error",
|
|
374
|
+
"markdown-preferences/no-text-backslash-linebreak": "error"
|
|
375
|
+
};
|
|
194
376
|
|
|
195
377
|
//#endregion
|
|
196
378
|
//#region src/meta.ts
|
|
@@ -200,7 +382,7 @@ __export(meta_exports, {
|
|
|
200
382
|
version: () => version
|
|
201
383
|
});
|
|
202
384
|
const name = "eslint-plugin-markdown-preferences";
|
|
203
|
-
const version = "0.
|
|
385
|
+
const version = "0.3.0";
|
|
204
386
|
|
|
205
387
|
//#endregion
|
|
206
388
|
//#region src/index.ts
|