mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD029/ol-prefix to fix reported violations (fixes #949).
This commit is contained in:
parent
3532e3110a
commit
371a35f62f
9 changed files with 1019 additions and 178 deletions
|
@ -1046,6 +1046,8 @@ Parameters:
|
|||
- `style`: List style (`string`, default `one_or_ordered`, values `one` /
|
||||
`one_or_ordered` / `ordered` / `zero`)
|
||||
|
||||
Fixable: Some violations can be fixed by tooling
|
||||
|
||||
This rule is triggered for ordered lists that do not either start with '1.' or
|
||||
do not have a prefix that increases in numerical order (depending on the
|
||||
configured style). The less-common pattern of using '0.' as a first prefix or
|
||||
|
|
|
@ -9,6 +9,8 @@ Parameters:
|
|||
- `style`: List style (`string`, default `one_or_ordered`, values `one` /
|
||||
`one_or_ordered` / `ordered` / `zero`)
|
||||
|
||||
Fixable: Some violations can be fixed by tooling
|
||||
|
||||
This rule is triggered for ordered lists that do not either start with '1.' or
|
||||
do not have a prefix that increases in numerical order (depending on the
|
||||
configured style). The less-common pattern of using '0.' as a first prefix or
|
||||
|
|
|
@ -4,10 +4,10 @@ export const deprecatedRuleNames = [];
|
|||
export const fixableRuleNames = [
|
||||
"MD004", "MD005", "MD007", "MD009", "MD010", "MD011",
|
||||
"MD012", "MD014", "MD018", "MD019", "MD020", "MD021",
|
||||
"MD022", "MD023", "MD026", "MD027", "MD030", "MD031",
|
||||
"MD032", "MD034", "MD037", "MD038", "MD039", "MD044",
|
||||
"MD047", "MD049", "MD050", "MD051", "MD053", "MD054",
|
||||
"MD058"
|
||||
"MD022", "MD023", "MD026", "MD027", "MD029", "MD030",
|
||||
"MD031", "MD032", "MD034", "MD037", "MD038", "MD039",
|
||||
"MD044", "MD047", "MD049", "MD050", "MD051", "MD053",
|
||||
"MD054", "MD058"
|
||||
];
|
||||
export const homepage = "https://github.com/DavidAnson/markdownlint";
|
||||
export const version = "0.38.0";
|
||||
|
|
|
@ -11,13 +11,17 @@ const listStyleExamples = {
|
|||
};
|
||||
|
||||
/**
|
||||
* Gets the value of an ordered list item prefix token.
|
||||
* Gets the column and text of an ordered list item prefix token.
|
||||
*
|
||||
* @param {import("markdownlint").MicromarkToken} listItemPrefix List item prefix token.
|
||||
* @returns {number} List item value.
|
||||
* @returns {{column: number, value: number}} List item value column and text.
|
||||
*/
|
||||
function getOrderedListItemValue(listItemPrefix) {
|
||||
return Number(getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0].text);
|
||||
const listItemValue = getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0];
|
||||
return {
|
||||
"column": listItemValue.startColumn,
|
||||
"value": Number(listItemValue.text)
|
||||
};
|
||||
}
|
||||
|
||||
/** @type {import("markdownlint").Rule} */
|
||||
|
@ -34,11 +38,11 @@ export default {
|
|||
let incrementing = false;
|
||||
// Check for incrementing number pattern 1/2/3 or 0/1/2
|
||||
if (listItemPrefixes.length >= 2) {
|
||||
const firstValue = getOrderedListItemValue(listItemPrefixes[0]);
|
||||
const secondValue = getOrderedListItemValue(listItemPrefixes[1]);
|
||||
if ((secondValue !== 1) || (firstValue === 0)) {
|
||||
const first = getOrderedListItemValue(listItemPrefixes[0]);
|
||||
const second = getOrderedListItemValue(listItemPrefixes[1]);
|
||||
if ((second.value !== 1) || (first.value === 0)) {
|
||||
incrementing = true;
|
||||
if (firstValue === 0) {
|
||||
if (first.value === 0) {
|
||||
expected = 0;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +58,13 @@ export default {
|
|||
}
|
||||
// Validate each list item marker
|
||||
for (const listItemPrefix of listItemPrefixes) {
|
||||
const actual = getOrderedListItemValue(listItemPrefix);
|
||||
const orderedListItemValue = getOrderedListItemValue(listItemPrefix);
|
||||
const actual = orderedListItemValue.value;
|
||||
const fixInfo = {
|
||||
"editColumn": orderedListItemValue.column,
|
||||
"deleteCount": orderedListItemValue.value.toString().length,
|
||||
"insertText": expected.toString()
|
||||
};
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
listItemPrefix.startLine,
|
||||
|
@ -62,7 +72,8 @@ export default {
|
|||
actual,
|
||||
"Style: " + listStyleExamples[listStyle],
|
||||
undefined,
|
||||
[ listItemPrefix.startColumn, listItemPrefix.endColumn - listItemPrefix.startColumn ]
|
||||
[ listItemPrefix.startColumn, listItemPrefix.endColumn - listItemPrefix.startColumn ],
|
||||
fixInfo
|
||||
);
|
||||
if (listStyle === "ordered") {
|
||||
expected++;
|
||||
|
|
|
@ -912,7 +912,7 @@ test("readme", async(t) => {
|
|||
});
|
||||
|
||||
test("validateJsonUsingConfigSchemaStrict", async(t) => {
|
||||
t.plan(209);
|
||||
t.plan(211);
|
||||
// @ts-ignore
|
||||
const ajv = new Ajv(ajvOptions);
|
||||
const validateSchemaStrict = ajv.compile(configSchemaStrict);
|
||||
|
|
42
test/ordered-list-item-prefix-double-digits-ordered.md
Normal file
42
test/ordered-list-item-prefix-double-digits-ordered.md
Normal file
|
@ -0,0 +1,42 @@
|
|||
# Ordered ist Item Prefix Double Digits Ordered
|
||||
|
||||
Good list:
|
||||
|
||||
1. Item
|
||||
2. Item
|
||||
3. Item
|
||||
4. Item
|
||||
5. Item
|
||||
6. Item
|
||||
7. Item
|
||||
8. Item
|
||||
9. Item
|
||||
10. Item
|
||||
11. Item
|
||||
|
||||
Bad list 1:
|
||||
|
||||
1. Item
|
||||
10. Item {MD029}
|
||||
9. Item {MD029}
|
||||
|
||||
Bad list 2:
|
||||
|
||||
11. Item {MD029}
|
||||
10. Item {MD029}
|
||||
|
||||
Bad list 3
|
||||
|
||||
12. Item {MD029}
|
||||
1. Item {MD029}
|
||||
|
||||
Bad list 4:
|
||||
|
||||
0. Item
|
||||
10. Item {MD029}
|
||||
|
||||
<!-- markdownlint-configure-file {
|
||||
"ol-prefix": {
|
||||
"style": "ordered"
|
||||
}
|
||||
} -->
|
47
test/ordered-list-item-prefix-sublists-ordered.md
Normal file
47
test/ordered-list-item-prefix-sublists-ordered.md
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Ordered List Item Prefix Sublists Ordered
|
||||
|
||||
Good list and sublist:
|
||||
|
||||
1. Item
|
||||
2. Item
|
||||
1. Item
|
||||
2. Item
|
||||
3. Item
|
||||
|
||||
Good list and bad sublist:
|
||||
|
||||
1. Item
|
||||
2. Item
|
||||
3. Item
|
||||
4. Item
|
||||
3. Item
|
||||
|
||||
Bad list and good sublist:
|
||||
|
||||
1. Item
|
||||
4. Item {MD029}
|
||||
1. Item
|
||||
2. Item
|
||||
5. Item {MD029}
|
||||
|
||||
Bad list and bad sublist:
|
||||
|
||||
1. Item
|
||||
4. Item {MD029}
|
||||
1. Item
|
||||
3. Item {MD029}
|
||||
5. Item {MD029}
|
||||
|
||||
Bad list and bad sublist (0):
|
||||
|
||||
0. Item
|
||||
4. Item {MD029}
|
||||
1. Item
|
||||
3. Item {MD029}
|
||||
5. Item {MD029}
|
||||
|
||||
<!-- markdownlint-configure-file {
|
||||
"ol-prefix": {
|
||||
"style": "ordered"
|
||||
}
|
||||
} -->
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue