Update MD027/no-multiple-space-blockquote to add a list_items parameter (fixes #1473).

This commit is contained in:
David Anson 2025-03-03 23:22:28 -08:00
parent d02090db2c
commit 435c55f72a
14 changed files with 333 additions and 14 deletions

View file

@ -13,4 +13,8 @@ To fix, remove any extraneous space:
> indentation. > indentation.
``` ```
Inferring intended list indentation within a blockquote can be challenging;
setting the `list_items` parameter to `false` disables this rule for ordered
and unordered list items.
Rationale: Consistent formatting makes it easier to understand a document. Rationale: Consistent formatting makes it easier to understand a document.

View file

@ -943,6 +943,10 @@ Tags: `blockquote`, `indentation`, `whitespace`
Aliases: `no-multiple-space-blockquote` Aliases: `no-multiple-space-blockquote`
Parameters:
- `list_items`: Include list items (`boolean`, default `true`)
Fixable: Some violations can be fixed by tooling Fixable: Some violations can be fixed by tooling
This rule is triggered when blockquotes have more than one space after the This rule is triggered when blockquotes have more than one space after the
@ -960,6 +964,10 @@ To fix, remove any extraneous space:
> indentation. > indentation.
``` ```
Inferring intended list indentation within a blockquote can be challenging;
setting the `list_items` parameter to `false` disables this rule for ordered
and unordered list items.
Rationale: Consistent formatting makes it easier to understand a document. Rationale: Consistent formatting makes it easier to understand a document.
<a name="md028"></a> <a name="md028"></a>

View file

@ -4,6 +4,10 @@ Tags: `blockquote`, `indentation`, `whitespace`
Aliases: `no-multiple-space-blockquote` Aliases: `no-multiple-space-blockquote`
Parameters:
- `list_items`: Include list items (`boolean`, default `true`)
Fixable: Some violations can be fixed by tooling Fixable: Some violations can be fixed by tooling
This rule is triggered when blockquotes have more than one space after the This rule is triggered when blockquotes have more than one space after the
@ -21,4 +25,8 @@ To fix, remove any extraneous space:
> indentation. > indentation.
``` ```
Inferring intended list indentation within a blockquote can be challenging;
setting the `list_items` parameter to `false` disables this rule for ordered
and unordered list items.
Rationale: Consistent formatting makes it easier to understand a document. Rationale: Consistent formatting makes it easier to understand a document.

View file

@ -470,11 +470,25 @@ export interface ConfigurationStrict {
/** /**
* MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md * MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md
*/ */
MD027?: boolean; MD027?:
| boolean
| {
/**
* Include list items
*/
list_items?: boolean;
};
/** /**
* MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md * MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md
*/ */
"no-multiple-space-blockquote"?: boolean; "no-multiple-space-blockquote"?:
| boolean
| {
/**
* Include list items
*/
list_items?: boolean;
};
/** /**
* MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md * MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md
*/ */

View file

@ -1,8 +1,12 @@
// @ts-check // @ts-check
import { addErrorContext } from "../helpers/helpers.cjs"; import { addErrorContext } from "../helpers/helpers.cjs";
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs"; import { filterByTypesCached } from "./cache.mjs";
/** @type {import("../helpers/micromark-helpers.cjs").TokenType[]} */
const listTypes = [ "listOrdered", "listUnordered" ];
/** @type {import("markdownlint").Rule} */ /** @type {import("markdownlint").Rule} */
export default { export default {
"names": [ "MD027", "no-multiple-space-blockquote" ], "names": [ "MD027", "no-multiple-space-blockquote" ],
@ -10,6 +14,8 @@ export default {
"tags": [ "blockquote", "whitespace", "indentation" ], "tags": [ "blockquote", "whitespace", "indentation" ],
"parser": "micromark", "parser": "micromark",
"function": function MD027(params, onError) { "function": function MD027(params, onError) {
const listItems = params.config.list_items;
const includeListItems = (listItems === undefined) ? true : !!listItems;
const { tokens } = params.parsers.micromark; const { tokens } = params.parsers.micromark;
for (const token of filterByTypesCached([ "linePrefix" ])) { for (const token of filterByTypesCached([ "linePrefix" ])) {
const parent = token.parent; const parent = token.parent;
@ -17,7 +23,11 @@ export default {
const siblings = parent?.children || tokens; const siblings = parent?.children || tokens;
if ( if (
!codeIndented && !codeIndented &&
(siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix") (siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix") &&
(includeListItems || (
!listTypes.includes(siblings[siblings.indexOf(token) + 1]?.type) &&
!getParentOfType(token, listTypes)
))
) { ) {
const { startColumn, startLine, text } = token; const { startColumn, startLine, text } = token;
const { length } = text; const { length } = text;

View file

@ -131,7 +131,10 @@
}, },
// MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md // MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md
"MD027": true, "MD027": {
// Include list items
"list_items": true
},
// MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md // MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md
"MD028": true, "MD028": true,

View file

@ -119,7 +119,9 @@ MD026:
punctuation: ".,;:!。,;:!" punctuation: ".,;:!。,;:!"
# MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md # MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md
MD027: true MD027:
# Include list items
list_items: true
# MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md # MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md
MD028: true MD028: true

View file

@ -273,6 +273,15 @@ for (const rule of rules) {
} }
}; };
break; break;
case "MD027":
scheme.properties = {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
};
break;
case "MD029": case "MD029":
scheme.properties = { scheme.properties = {
"style": { "style": {

View file

@ -723,13 +723,35 @@
}, },
"MD027": { "MD027": {
"description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md", "description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md",
"type": "boolean", "type": [
"default": true "boolean",
"object"
],
"default": true,
"properties": {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
}, },
"no-multiple-space-blockquote": { "no-multiple-space-blockquote": {
"description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md", "description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md",
"type": "boolean", "type": [
"default": true "boolean",
"object"
],
"default": true,
"properties": {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
}, },
"MD028": { "MD028": {
"description": "MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md", "description": "MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md",

View file

@ -723,13 +723,35 @@
}, },
"MD027": { "MD027": {
"description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md", "description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md",
"type": "boolean", "type": [
"default": true "boolean",
"object"
],
"default": true,
"properties": {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
}, },
"no-multiple-space-blockquote": { "no-multiple-space-blockquote": {
"description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md", "description": "MD027/no-multiple-space-blockquote : Multiple spaces after blockquote symbol : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md027.md",
"type": "boolean", "type": [
"default": true "boolean",
"object"
],
"default": true,
"properties": {
"list_items": {
"description": "Include list items",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
}, },
"MD028": { "MD028": {
"description": "MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md", "description": "MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md",

View file

@ -0,0 +1,104 @@
# Lists in Blockquote Start Indented
Text
+ Item
+ Item
more
item
+ Item
+ Item
+ Item
more
item
+ Item
+ Item
+ Item
+ Item
+ Item
Text
Code
Text
<!-- markdownlint-disable ul-indent -->
> Text
>
> + Item
> + Item
> more
> item
> + Item
> + Item
> + Item
> more
> item
> + Item
> + Item
> + Item
> + Item
> + Item
>
> Text
>
> Code
<!-- markdownlint-restore -->
Text
1. Item
1. Item
more
item
1. Item
1. Item
1. Item
more
item
1. Item
1. Item
1. Item
1. Item
1. Item
Text
Code
Text
> Text
>
> 1. Item
> 1. Item
> more
> item
> 1. Item
> 1. Item
> 1. Item
> more
> item
> 1. Item
> 1. Item
> 1. Item
> 1. Item
> 1. Item
>
> Text
>
> Code
Text
<!-- markdownlint-configure-file {
"no-multiple-space-blockquote": {
"list_items": false
},
"ul-indent": {
"start_indented": true
}
} -->

View file

@ -907,7 +907,7 @@ test("readme", async(t) => {
}); });
test("validateJsonUsingConfigSchemaStrict", async(t) => { test("validateJsonUsingConfigSchemaStrict", async(t) => {
t.plan(186); t.plan(187);
// @ts-ignore // @ts-ignore
const ajv = new Ajv(ajvOptions); const ajv = new Ajv(ajvOptions);
const validateSchemaStrict = ajv.compile(configSchemaStrict); const validateSchemaStrict = ajv.compile(configSchemaStrict);

View file

@ -34651,6 +34651,119 @@ Generated by [AVA](https://avajs.dev).
`, `,
} }
## lists-in-blockquote-start-indented-no-list-items.md
> Snapshot 1
{
errors: [],
fixed: `# Lists in Blockquote Start Indented␊
Text␊
+ Item␊
+ Item␊
more␊
item␊
+ Item␊
+ Item␊
+ Item␊
more␊
item␊
+ Item␊
+ Item␊
+ Item␊
+ Item␊
+ Item␊
Text␊
Code␊
Text␊
<!-- markdownlint-disable ul-indent -->
> Text␊
>␊
> + Item␊
> + Item␊
> more␊
> item␊
> + Item␊
> + Item␊
> + Item␊
> more␊
> item␊
> + Item␊
> + Item␊
> + Item␊
> + Item␊
> + Item␊
>␊
> Text␊
>␊
> Code␊
<!-- markdownlint-restore -->
Text␊
1. Item␊
1. Item␊
more␊
item␊
1. Item␊
1. Item␊
1. Item␊
more␊
item␊
1. Item␊
1. Item␊
1. Item␊
1. Item␊
1. Item␊
Text␊
Code␊
Text␊
> Text␊
>␊
> 1. Item␊
> 1. Item␊
> more␊
> item␊
> 1. Item␊
> 1. Item␊
> 1. Item␊
> more␊
> item␊
> 1. Item␊
> 1. Item␊
> 1. Item␊
> 1. Item␊
> 1. Item␊
>␊
> Text␊
>␊
> Code␊
Text␊
<!-- markdownlint-configure-file {␊
"no-multiple-space-blockquote": {␊
"list_items": false␊
},␊
"ul-indent": {␊
"start_indented": true␊
}␊
} -->␊
`,
}
## lists-in-blockquote-start-indented.md ## lists-in-blockquote-start-indented.md
> Snapshot 1 > Snapshot 1