Allow question mark by default for MD026/no-trailing-punctuation (fixes #276).

This commit is contained in:
David Anson 2020-11-17 20:32:17 -08:00
parent 3827842930
commit 6c1bc8ecb5
8 changed files with 30 additions and 16 deletions

View file

@ -895,7 +895,7 @@ Tags: headings, headers
Aliases: no-trailing-punctuation Aliases: no-trailing-punctuation
Parameters: punctuation (string; default ".,;:!?。,;:!") Parameters: punctuation (string; default ".,;:!。,;:!")
Fixable: Most violations can be fixed by tooling Fixable: Most violations can be fixed by tooling
@ -914,7 +914,8 @@ To fix this, remove the trailing punctuation:
Note: The `punctuation` parameter can be used to specify what characters count Note: The `punctuation` parameter can be used to specify what characters count
as punctuation at the end of a heading. For example, you can change it to as punctuation at the end of a heading. For example, you can change it to
`".,;:!"` to allow headings that end with a question mark, such as in an FAQ. `".,;:"` to allow headings that end with an exclamation point. Question mark is
allowed by default because of how common it is in headings of FAQ-style documents.
Setting the `punctuation` parameter to `""` allows all characters - and is Setting the `punctuation` parameter to `""` allows all characters - and is
equivalent to disabling the rule. equivalent to disabling the rule.

View file

@ -35,7 +35,11 @@ const linkRe = /\[(?:[^[\]]|\[[^\]]*\])*\](?:\(\S*\))?/g;
module.exports.utf8Encoding = "utf8"; module.exports.utf8Encoding = "utf8";
// All punctuation characters (normal and full-width) // All punctuation characters (normal and full-width)
module.exports.allPunctuation = ".,;:!?。,;:!?"; const allPunctuation = ".,;:!?。,;:!?";
module.exports.allPunctuation = allPunctuation;
// All punctuation characters without question mark (normal and full-width)
module.exports.allPunctuationNoQuestion = allPunctuation.replace(/[?]/gu, "");
// Returns true iff the input is a number // Returns true iff the input is a number
module.exports.isNumber = function isNumber(obj) { module.exports.isNumber = function isNumber(obj) {

View file

@ -2,7 +2,7 @@
"use strict"; "use strict";
const { addError, allPunctuation, escapeForRegExp, forEachHeading } = const { addError, allPunctuationNoQuestion, escapeForRegExp, forEachHeading } =
require("../helpers"); require("../helpers");
module.exports = { module.exports = {
@ -11,8 +11,9 @@ module.exports = {
"tags": [ "headings", "headers" ], "tags": [ "headings", "headers" ],
"function": function MD026(params, onError) { "function": function MD026(params, onError) {
let punctuation = params.config.punctuation; let punctuation = params.config.punctuation;
punctuation = punctuation = String(
String((punctuation === undefined) ? allPunctuation : punctuation); (punctuation === undefined) ? allPunctuationNoQuestion : punctuation
);
const trailingPunctuationRe = const trailingPunctuationRe =
new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$"); new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
forEachHeading(params, (heading) => { forEachHeading(params, (heading) => {

View file

@ -222,6 +222,14 @@ rules.forEach(function forRule(rule) {
}; };
break; break;
case "MD026": case "MD026":
scheme.properties = {
"punctuation": {
"description": "Punctuation characters",
"type": "string",
"default": ".,;:!。,;:!"
}
};
break;
case "MD036": case "MD036":
scheme.properties = { scheme.properties = {
"punctuation": { "punctuation": {

View file

@ -763,7 +763,7 @@
"punctuation": { "punctuation": {
"description": "Punctuation characters", "description": "Punctuation characters",
"type": "string", "type": "string",
"default": ".,;:!?。,;:!" "default": ".,;:!。,;:!"
} }
}, },
"additionalProperties": false "additionalProperties": false
@ -779,7 +779,7 @@
"punctuation": { "punctuation": {
"description": "Punctuation characters", "description": "Punctuation characters",
"type": "string", "type": "string",
"default": ".,;:!?。,;:!" "default": ".,;:!。,;:!"
} }
}, },
"additionalProperties": false "additionalProperties": false

View file

@ -10,7 +10,7 @@
## Heading {MD026} ! ## Heading {MD026} !
## Heading {MD026} ? ## Heading?
## Heading/Full-Width {MD026} 。 ## Heading/Full-Width {MD026} 。
@ -22,11 +22,11 @@
## Heading/Full-Width {MD026} ## Heading/Full-Width {MD026}
## Heading/Full-Width {MD026} ## Heading/Full-Width
<!-- markdownlint-disable heading-style --> <!-- markdownlint-disable heading-style -->
## Heading {MD026} alternate ? ## ## Heading {MD026} alternate ! ##
Heading {MD026} alternate too ? Heading {MD026} alternate too !
------------------------------- -------------------------------

View file

@ -1,6 +1,6 @@
{ {
"default": true, "default": true,
"MD026": { "MD026": {
"punctuation": ".,;:!]" "punctuation": ".,;:?]"
} }
} }

View file

@ -2,15 +2,15 @@
## Heading 2 {MD026}, ## Heading 2 {MD026},
## Heading 3 {MD026}! ## Heading 3!
## Heading 4 {MD026}: ## Heading 4 {MD026}:
## Heading 5 {MD026}; ## Heading 5 {MD026};
## Heading 6? ## Heading 6 {MD026}?
## Heading 7 {MD026}] ## Heading 7 {MD026}]
The rule has been customized to allow question marks while disallowing The rule has been customized to allow exclamation point while disallowing
everything else. everything else.