Update MD049/emphasis-style and MD050/strong-style to properly detect violations at the beginning and end of a line (fixes #1132).

This commit is contained in:
David Anson 2024-02-19 15:41:10 -08:00
parent f26df4743c
commit 64b9032b51
13 changed files with 436 additions and 18 deletions

View file

@ -6032,7 +6032,7 @@ module.exports = {
const { addError, emphasisOrStrongStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
const { filterByPredicate, tokenIfType } = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs");
const intrawordRe = /\w/;
const intrawordRe = /^\w$/;
const impl =
(params, onError, type, asterisk, underline, style = "consistent") => {

View file

@ -16,4 +16,7 @@ To fix this issue, use the configured emphasis style throughout the document:
The configured emphasis style can be a specific symbol to use ("asterisk",
"underscore"), or can require that usage be consistent within the document.
Note: Emphasis within a word is restricted to "asterisk" in order to avoid
unwanted emphasis for words containing internal underscores like_this_one.
Rationale: Consistent formatting makes it easier to understand a document.

View file

@ -16,4 +16,7 @@ To fix this issue, use the configured strong style throughout the document:
The configured strong style can be a specific symbol to use ("asterisk",
"underscore"), or can require that usage be consistent within the document.
Note: Emphasis within a word is restricted to "asterisk" in order to avoid
unwanted emphasis for words containing internal underscores like_this_one.
Rationale: Consistent formatting makes it easier to understand a document.

View file

@ -2035,6 +2035,9 @@ To fix this issue, use the configured emphasis style throughout the document:
The configured emphasis style can be a specific symbol to use ("asterisk",
"underscore"), or can require that usage be consistent within the document.
Note: Emphasis within a word is restricted to "asterisk" in order to avoid
unwanted emphasis for words containing internal underscores like_this_one.
Rationale: Consistent formatting makes it easier to understand a document.
<a name="md050"></a>
@ -2070,6 +2073,9 @@ To fix this issue, use the configured strong style throughout the document:
The configured strong style can be a specific symbol to use ("asterisk",
"underscore"), or can require that usage be consistent within the document.
Note: Emphasis within a word is restricted to "asterisk" in order to avoid
unwanted emphasis for words containing internal underscores like_this_one.
Rationale: Consistent formatting makes it easier to understand a document.
<a name="md051"></a>

View file

@ -29,4 +29,7 @@ To fix this issue, use the configured emphasis style throughout the document:
The configured emphasis style can be a specific symbol to use ("asterisk",
"underscore"), or can require that usage be consistent within the document.
Note: Emphasis within a word is restricted to "asterisk" in order to avoid
unwanted emphasis for words containing internal underscores like_this_one.
Rationale: Consistent formatting makes it easier to understand a document.

View file

@ -29,4 +29,7 @@ To fix this issue, use the configured strong style throughout the document:
The configured strong style can be a specific symbol to use ("asterisk",
"underscore"), or can require that usage be consistent within the document.
Note: Emphasis within a word is restricted to "asterisk" in order to avoid
unwanted emphasis for words containing internal underscores like_this_one.
Rationale: Consistent formatting makes it easier to understand a document.

View file

@ -5,7 +5,7 @@
const { addError, emphasisOrStrongStyleFor } = require("../helpers");
const { filterByPredicate, tokenIfType } = require("../helpers/micromark.cjs");
const intrawordRe = /\w/;
const intrawordRe = /^\w$/;
const impl =
(params, onError, type, asterisk, underline, style = "consistent") => {

View file

@ -1,8 +1,18 @@
# Emphasis style asterisk
*This* is fine
This *is* fine
This is *fine*
This is _not_ {MD049}
_This_ is not
This _is_ not
This is _not_
{MD049:-2} {MD049:-4} {MD049:-6}
Internal emphasis is preserved:
apple*banana*cherry, apple*banana*, *banana*cherry

View file

@ -1,8 +1,18 @@
# Emphasis style underscore
_This_ is fine
This _is_ fine
This is _fine_
This is *not* {MD049}
*This* is not
This *is* not
This is *not*
{MD049:-2} {MD049:-4} {MD049:-6}
Internal emphasis is preserved:
apple*banana*cherry, apple*banana*, *banana*cherry

View file

@ -11028,6 +11028,66 @@ Generated by [AVA](https://avajs.dev).
{
errors: [
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
errorRange: [
1,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 1,
insertText: '*',
},
lineNumber: 9,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
'MD049',
'emphasis-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
errorRange: [
6,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 6,
insertText: '*',
},
lineNumber: 9,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
'MD049',
'emphasis-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
errorRange: [
6,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 6,
insertText: '*',
},
lineNumber: 11,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
'MD049',
'emphasis-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
@ -11040,7 +11100,27 @@ Generated by [AVA](https://avajs.dev).
editColumn: 9,
insertText: '*',
},
lineNumber: 5,
lineNumber: 11,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
'MD049',
'emphasis-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
errorRange: [
9,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 9,
insertText: '*',
},
lineNumber: 13,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
@ -11060,7 +11140,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 13,
insertText: '*',
},
lineNumber: 5,
lineNumber: 13,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
@ -11071,9 +11151,19 @@ Generated by [AVA](https://avajs.dev).
],
fixed: `# Emphasis style asterisk␊
*This* is fine␊
This *is* fine␊
This is *fine*
This is *not* {MD049}␊
*This* is not␊
This *is* not␊
This is *not*
{MD049:-2} {MD049:-4} {MD049:-6}␊
Internal emphasis is preserved:␊
apple*banana*cherry, apple*banana*, *banana*cherry␊
@ -11094,6 +11184,66 @@ Generated by [AVA](https://avajs.dev).
{
errors: [
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
errorRange: [
1,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 1,
insertText: '_',
},
lineNumber: 9,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
'MD049',
'emphasis-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
errorRange: [
6,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 6,
insertText: '_',
},
lineNumber: 9,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
'MD049',
'emphasis-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
errorRange: [
6,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 6,
insertText: '_',
},
lineNumber: 11,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
'MD049',
'emphasis-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
@ -11106,7 +11256,27 @@ Generated by [AVA](https://avajs.dev).
editColumn: 9,
insertText: '_',
},
lineNumber: 5,
lineNumber: 11,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
'MD049',
'emphasis-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
errorRange: [
9,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 9,
insertText: '_',
},
lineNumber: 13,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
@ -11126,7 +11296,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 13,
insertText: '_',
},
lineNumber: 5,
lineNumber: 13,
ruleDescription: 'Emphasis style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md049.md',
ruleNames: [
@ -11137,9 +11307,19 @@ Generated by [AVA](https://avajs.dev).
],
fixed: `# Emphasis style underscore␊
_This_ is fine␊
This _is_ fine␊
This is _fine_
This is _not_ {MD049}␊
_This_ is not␊
This _is_ not␊
This is _not_
{MD049:-2} {MD049:-4} {MD049:-6}␊
Internal emphasis is preserved:␊
apple*banana*cherry, apple*banana*, *banana*cherry␊
@ -50912,6 +51092,86 @@ Generated by [AVA](https://avajs.dev).
{
errors: [
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
errorRange: [
1,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 1,
insertText: '**',
},
lineNumber: 9,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
'MD050',
'strong-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
errorRange: [
7,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 7,
insertText: '**',
},
lineNumber: 9,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
'MD050',
'strong-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
errorRange: [
6,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 6,
insertText: '**',
},
lineNumber: 11,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
'MD050',
'strong-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
errorRange: [
10,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 10,
insertText: '**',
},
lineNumber: 11,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
'MD050',
'strong-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: asterisk; Actual: underscore',
@ -50924,7 +51184,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 9,
insertText: '**',
},
lineNumber: 5,
lineNumber: 13,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
@ -50944,7 +51204,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 14,
insertText: '**',
},
lineNumber: 5,
lineNumber: 13,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
@ -50955,9 +51215,19 @@ Generated by [AVA](https://avajs.dev).
],
fixed: `# Strong style asterisk␊
**This** is fine␊
This **is** fine␊
This is **fine**
This is **not** {MD050}␊
**This** is not␊
This **is** not␊
This is **not**
{MD050:-2} {MD050:-4} {MD050:-6}␊
Internal emphasis is preserved:␊
apple**banana**cherry, apple**banana**, **banana**cherry␊
@ -50977,6 +51247,86 @@ Generated by [AVA](https://avajs.dev).
{
errors: [
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
errorRange: [
1,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 1,
insertText: '__',
},
lineNumber: 9,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
'MD050',
'strong-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
errorRange: [
7,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 7,
insertText: '__',
},
lineNumber: 9,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
'MD050',
'strong-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
errorRange: [
6,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 6,
insertText: '__',
},
lineNumber: 11,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
'MD050',
'strong-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
errorRange: [
10,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 10,
insertText: '__',
},
lineNumber: 11,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
'MD050',
'strong-style',
],
},
{
errorContext: null,
errorDetail: 'Expected: underscore; Actual: asterisk',
@ -50989,7 +51339,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 9,
insertText: '__',
},
lineNumber: 5,
lineNumber: 13,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
@ -51009,7 +51359,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 14,
insertText: '__',
},
lineNumber: 5,
lineNumber: 13,
ruleDescription: 'Strong style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md050.md',
ruleNames: [
@ -51020,9 +51370,19 @@ Generated by [AVA](https://avajs.dev).
],
fixed: `# Strong style underscore␊
__This__ is fine␊
This __is__ fine␊
This is __fine__
This is __not__ {MD050}␊
__This__ is not␊
This __is__ not␊
This is __not__
{MD050:-2} {MD050:-4} {MD050:-6}␊
Internal emphasis is preserved:␊
apple**banana**cherry, apple**banana**, **banana**cherry␊

View file

@ -1,8 +1,18 @@
# Strong style asterisk
**This** is fine
This **is** fine
This is **fine**
This is __not__ {MD050}
__This__ is not
This __is__ not
This is __not__
{MD050:-2} {MD050:-4} {MD050:-6}
Internal emphasis is preserved:
apple**banana**cherry, apple**banana**, **banana**cherry

View file

@ -1,8 +1,18 @@
# Strong style underscore
__This__ is fine
This __is__ fine
This is __fine__
This is **not** {MD050}
**This** is not
This **is** not
This is **not**
{MD050:-2} {MD050:-4} {MD050:-6}
Internal emphasis is preserved:
apple**banana**cherry, apple**banana**, **banana**cherry