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
Parameters: punctuation (string; default ".,;:!?。,;:!")
Parameters: punctuation (string; default ".,;:!。,;:!")
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
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
equivalent to disabling the rule.

View file

@ -35,7 +35,11 @@ const linkRe = /\[(?:[^[\]]|\[[^\]]*\])*\](?:\(\S*\))?/g;
module.exports.utf8Encoding = "utf8";
// 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
module.exports.isNumber = function isNumber(obj) {

View file

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

View file

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

View file

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

View file

@ -10,7 +10,7 @@
## Heading {MD026} !
## Heading {MD026} ?
## Heading?
## Heading/Full-Width {MD026} 。
@ -22,11 +22,11 @@
## Heading/Full-Width {MD026}
## Heading/Full-Width {MD026}
## Heading/Full-Width
<!-- 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,
"MD026": {
"punctuation": ".,;:!]"
"punctuation": ".,;:?]"
}
}

View file

@ -2,15 +2,15 @@
## Heading 2 {MD026},
## Heading 3 {MD026}!
## Heading 3!
## Heading 4 {MD026}:
## Heading 5 {MD026};
## Heading 6?
## Heading 6 {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.