mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Add "severity"/"error" to rule in Configuration object, add corresponding documentation, resolve some new type-checking issues.
Some checks are pending
Checkers / linkcheck (push) Waiting to run
Checkers / spellcheck (push) Waiting to run
CI / build (20, macos-latest) (push) Waiting to run
CI / build (20, ubuntu-latest) (push) Waiting to run
CI / build (20, windows-latest) (push) Waiting to run
CI / build (22, macos-latest) (push) Waiting to run
CI / build (22, ubuntu-latest) (push) Waiting to run
CI / build (22, windows-latest) (push) Waiting to run
CI / build (24, macos-latest) (push) Waiting to run
CI / build (24, ubuntu-latest) (push) Waiting to run
CI / build (24, windows-latest) (push) Waiting to run
CI / pnpm (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
TestRepos / build (latest, ubuntu-latest) (push) Waiting to run
UpdateTestRepos / update (push) Waiting to run
Some checks are pending
Checkers / linkcheck (push) Waiting to run
Checkers / spellcheck (push) Waiting to run
CI / build (20, macos-latest) (push) Waiting to run
CI / build (20, ubuntu-latest) (push) Waiting to run
CI / build (20, windows-latest) (push) Waiting to run
CI / build (22, macos-latest) (push) Waiting to run
CI / build (22, ubuntu-latest) (push) Waiting to run
CI / build (22, windows-latest) (push) Waiting to run
CI / build (24, macos-latest) (push) Waiting to run
CI / build (24, ubuntu-latest) (push) Waiting to run
CI / build (24, windows-latest) (push) Waiting to run
CI / pnpm (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
TestRepos / build (latest, ubuntu-latest) (push) Waiting to run
UpdateTestRepos / update (push) Waiting to run
This commit is contained in:
parent
a4ae56ab94
commit
05509da984
13 changed files with 4030 additions and 688 deletions
38
README.md
38
README.md
|
@ -375,12 +375,48 @@ for all rules. Using a tag name (e.g., `whitespace`) and a setting of `false`,
|
|||
configuration object is passed or the optional `default` setting is not present,
|
||||
all rules are enabled.
|
||||
|
||||
The following syntax disables the specified rule, tag, or `default`:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"rule_name": false
|
||||
}
|
||||
```
|
||||
|
||||
The following syntax enables the specified rule, tag, or `default`:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"rule_name": true
|
||||
// OR
|
||||
"rule_name": "error"
|
||||
}
|
||||
```
|
||||
|
||||
The following syntax enables and configures the specified rule:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"rule_name": {
|
||||
"parameter": "value"
|
||||
}
|
||||
// OR
|
||||
"rule_name": {
|
||||
"parameter": "value",
|
||||
"severity": "error"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> Note that `error` and `severity` are not supported by library versions earlier
|
||||
> than `0.39.0`. However, all examples above behave the same.
|
||||
|
||||
To evaluate a configuration object, the `default` setting is applied first, then
|
||||
keys are processed in order from top to bottom. If multiple values apply to a
|
||||
rule (because of tag names or duplication), later values override earlier ones.
|
||||
Keys (including rule names, aliases, tags, or `default`) are not case-sensitive.
|
||||
|
||||
Example:
|
||||
Example using `default`, rule names, and tag names together:
|
||||
|
||||
```json
|
||||
{
|
||||
|
|
|
@ -61,8 +61,12 @@ for (const rule of rules) {
|
|||
""
|
||||
);
|
||||
const ruleData = schema.properties[name];
|
||||
const ruleProperties = ruleData.oneOf.at(-1).properties;
|
||||
if (ruleProperties) {
|
||||
const ruleProperties = Object.fromEntries(
|
||||
Object.entries(
|
||||
ruleData.oneOf.at(-1).properties
|
||||
).filter(([ key ]) => key !== "severity")
|
||||
);
|
||||
if (Object.keys(ruleProperties).length > 0) {
|
||||
section.push(
|
||||
"Parameters:",
|
||||
""
|
||||
|
|
660
lib/configuration-strict.d.ts
vendored
660
lib/configuration-strict.d.ts
vendored
File diff suppressed because it is too large
Load diff
|
@ -262,9 +262,9 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
|||
for (const key of Object.keys(config)) {
|
||||
let value = config[key];
|
||||
if (value) {
|
||||
if (!(value instanceof Object)) {
|
||||
value = {};
|
||||
}
|
||||
value = (value instanceof Object) ?
|
||||
Object.fromEntries(Object.entries(value).filter(([ k ]) => k !== "severity")) :
|
||||
{};
|
||||
} else {
|
||||
value = false;
|
||||
}
|
||||
|
|
|
@ -6,14 +6,20 @@ import yaml from "js-yaml";
|
|||
import { __dirname, importWithTypeJson } from "../test/esm-helpers.mjs";
|
||||
const configSchema = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema.json");
|
||||
|
||||
/** @type {Object<string, any>} */
|
||||
const configExample = {};
|
||||
for (const rule in configSchema.properties) {
|
||||
if (/^(?:MD\d{3}|default|extends)$/.test(rule)) {
|
||||
const properties = configSchema.properties[rule];
|
||||
configExample[rule + "-description"] = properties.description;
|
||||
configExample[rule] = properties.default;
|
||||
const subproperties = properties.oneOf?.at(-1).properties;
|
||||
if (subproperties) {
|
||||
const subproperties = Object.fromEntries(
|
||||
Object.entries(
|
||||
properties.oneOf?.at(-1).properties || []
|
||||
).filter(([ key ]) => key !== "severity")
|
||||
);
|
||||
if (Object.keys(subproperties).length > 0) {
|
||||
/** @type {Object<string, any>} */
|
||||
const ruleExample = {};
|
||||
// eslint-disable-next-line guard-for-in
|
||||
for (const property in subproperties) {
|
||||
|
@ -26,6 +32,13 @@ for (const rule in configSchema.properties) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms comments to use the specified prefix.
|
||||
*
|
||||
* @param {string} input Markdown input.
|
||||
* @param {string} commentPrefix Comment prefix.
|
||||
* @returns {string} Transformed input.
|
||||
*/
|
||||
const transformComments = (input, commentPrefix) => (
|
||||
commentPrefix +
|
||||
" Example markdownlint configuration with all properties set to their default value\n" +
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
58
test/configure-file-with-severity.md
Normal file
58
test/configure-file-with-severity.md
Normal file
|
@ -0,0 +1,58 @@
|
|||
# Configure File With Severity
|
||||
|
||||
Text * text* {MD037}
|
||||
|
||||
Text ` text` {MD038}
|
||||
|
||||
Text [ text](.) {MD039}
|
||||
|
||||
+ List item {MD004}
|
||||
|
||||
Text (text)[.] {MD011}
|
||||
|
||||
2. List item {MD029}
|
||||
|
||||
<!-- markdownlint-disable -->
|
||||
|
||||
Text * text*
|
||||
|
||||
Text ` text`
|
||||
|
||||
Text [ text](.)
|
||||
|
||||
+ List item
|
||||
|
||||
Text (text)[.]
|
||||
|
||||
2. List item
|
||||
|
||||
<!-- markdownlint-restore -->
|
||||
|
||||
Text * text* {MD037}
|
||||
|
||||
Text ` text` {MD038}
|
||||
|
||||
Text [ text](.) {MD039}
|
||||
|
||||
+ List item {MD004}
|
||||
|
||||
Text (text)[.] {MD011}
|
||||
|
||||
2. List item {MD029}
|
||||
|
||||
<!-- markdownlint-configure-file {
|
||||
"default": false,
|
||||
"MD037": "error",
|
||||
"MD038": "error",
|
||||
"MD039": "error",
|
||||
"MD004": {
|
||||
"severity": "error",
|
||||
"style": "dash"
|
||||
},
|
||||
"MD011": {
|
||||
"severity": "error"
|
||||
},
|
||||
"MD029": {
|
||||
"severity": "error"
|
||||
}
|
||||
} -->
|
|
@ -29,13 +29,14 @@ test("customRulesV0", (t) => new Promise((resolve) => {
|
|||
};
|
||||
lintAsync(options, function callback(err, actualResult) {
|
||||
t.falsy(err);
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = {
|
||||
"any-blockquote-markdown-it": [ 12 ],
|
||||
"any-blockquote-micromark": [ 12 ],
|
||||
"every-n-lines": [ 2, 4, 6, 10, 12 ],
|
||||
"first-line": [ 1 ],
|
||||
"letters-E-X": [ 3, 7 ]
|
||||
const expectedResult = {
|
||||
[customRulesMd]: {
|
||||
"any-blockquote-markdown-it": [ 12 ],
|
||||
"any-blockquote-micromark": [ 12 ],
|
||||
"every-n-lines": [ 2, 4, 6, 10, 12 ],
|
||||
"first-line": [ 1 ],
|
||||
"letters-E-X": [ 3, 7 ]
|
||||
}
|
||||
};
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
// @ts-ignore
|
||||
|
@ -103,93 +104,94 @@ test("customRulesV1", (t) => new Promise((resolve) => {
|
|||
};
|
||||
lintAsync(options, function callback(err, actualResult) {
|
||||
t.falsy(err);
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = [
|
||||
{ "lineNumber": 12,
|
||||
"ruleName": "any-blockquote-markdown-it",
|
||||
"ruleAlias": "any-blockquote-markdown-it",
|
||||
"ruleDescription": "Rule that reports an error for any blockquote",
|
||||
"ruleInformation":
|
||||
`${homepage}/blob/main/test/rules/any-blockquote.js`,
|
||||
"errorDetail": "Blockquote spans 1 line(s).",
|
||||
"errorContext": "> Blockquote",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 12,
|
||||
"ruleName": "any-blockquote-micromark",
|
||||
"ruleAlias": "any-blockquote-micromark",
|
||||
"ruleDescription": "Rule that reports an error for any blockquote",
|
||||
"ruleInformation":
|
||||
`${homepage}/blob/main/test/rules/any-blockquote.js`,
|
||||
"errorDetail": "Blockquote spans 1 line(s).",
|
||||
"errorContext": "> Blockquote",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 2,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 2",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 4,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 4",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 6,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 6",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 10,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 10",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 12,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 12",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 1,
|
||||
"ruleName": "first-line",
|
||||
"ruleAlias": "first-line",
|
||||
"ruleDescription": "Rule that reports an error for the first line",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": null,
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 3,
|
||||
"ruleName": "letters-E-X",
|
||||
"ruleAlias": "letter-E-letter-X",
|
||||
"ruleDescription":
|
||||
"Rule that reports an error for lines with the letters 'EX'",
|
||||
"ruleInformation": `${homepage}/blob/main/test/rules/letters-E-X.js`,
|
||||
"errorDetail": null,
|
||||
"errorContext": "text",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 7,
|
||||
"ruleName": "letters-E-X",
|
||||
"ruleAlias": "letter-E-letter-X",
|
||||
"ruleDescription":
|
||||
"Rule that reports an error for lines with the letters 'EX'",
|
||||
"ruleInformation": `${homepage}/blob/main/test/rules/letters-E-X.js`,
|
||||
"errorDetail": null,
|
||||
"errorContext": "text",
|
||||
"errorRange": null }
|
||||
];
|
||||
const expectedResult = {
|
||||
[customRulesMd]: [
|
||||
{ "lineNumber": 12,
|
||||
"ruleName": "any-blockquote-markdown-it",
|
||||
"ruleAlias": "any-blockquote-markdown-it",
|
||||
"ruleDescription": "Rule that reports an error for any blockquote",
|
||||
"ruleInformation":
|
||||
`${homepage}/blob/main/test/rules/any-blockquote.js`,
|
||||
"errorDetail": "Blockquote spans 1 line(s).",
|
||||
"errorContext": "> Blockquote",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 12,
|
||||
"ruleName": "any-blockquote-micromark",
|
||||
"ruleAlias": "any-blockquote-micromark",
|
||||
"ruleDescription": "Rule that reports an error for any blockquote",
|
||||
"ruleInformation":
|
||||
`${homepage}/blob/main/test/rules/any-blockquote.js`,
|
||||
"errorDetail": "Blockquote spans 1 line(s).",
|
||||
"errorContext": "> Blockquote",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 2,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 2",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 4,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 4",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 6,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 6",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 10,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 10",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 12,
|
||||
"ruleName": "every-n-lines",
|
||||
"ruleAlias": "every-n-lines",
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 12",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 1,
|
||||
"ruleName": "first-line",
|
||||
"ruleAlias": "first-line",
|
||||
"ruleDescription": "Rule that reports an error for the first line",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": null,
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 3,
|
||||
"ruleName": "letters-E-X",
|
||||
"ruleAlias": "letter-E-letter-X",
|
||||
"ruleDescription":
|
||||
"Rule that reports an error for lines with the letters 'EX'",
|
||||
"ruleInformation": `${homepage}/blob/main/test/rules/letters-E-X.js`,
|
||||
"errorDetail": null,
|
||||
"errorContext": "text",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 7,
|
||||
"ruleName": "letters-E-X",
|
||||
"ruleAlias": "letter-E-letter-X",
|
||||
"ruleDescription":
|
||||
"Rule that reports an error for lines with the letters 'EX'",
|
||||
"ruleInformation": `${homepage}/blob/main/test/rules/letters-E-X.js`,
|
||||
"errorDetail": null,
|
||||
"errorContext": "text",
|
||||
"errorRange": null }
|
||||
]
|
||||
};
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
// @ts-ignore
|
||||
const actualMessage = actualResult.toString();
|
||||
|
@ -236,83 +238,84 @@ test("customRulesV2", (t) => new Promise((resolve) => {
|
|||
};
|
||||
lintAsync(options, function callback(err, actualResult) {
|
||||
t.falsy(err);
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = [
|
||||
{ "lineNumber": 12,
|
||||
"ruleNames": [ "any-blockquote-markdown-it" ],
|
||||
"ruleDescription": "Rule that reports an error for any blockquote",
|
||||
"ruleInformation":
|
||||
`${homepage}/blob/main/test/rules/any-blockquote.js`,
|
||||
"errorDetail": "Blockquote spans 1 line(s).",
|
||||
"errorContext": "> Blockquote",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 12,
|
||||
"ruleNames": [ "any-blockquote-micromark" ],
|
||||
"ruleDescription": "Rule that reports an error for any blockquote",
|
||||
"ruleInformation":
|
||||
`${homepage}/blob/main/test/rules/any-blockquote.js`,
|
||||
"errorDetail": "Blockquote spans 1 line(s).",
|
||||
"errorContext": "> Blockquote",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 2,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 2",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 4,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 4",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 6,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 6",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 10,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 10",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 12,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 12",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 1,
|
||||
"ruleNames": [ "first-line" ],
|
||||
"ruleDescription": "Rule that reports an error for the first line",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": null,
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 3,
|
||||
"ruleNames": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
|
||||
"ruleDescription":
|
||||
"Rule that reports an error for lines with the letters 'EX'",
|
||||
"ruleInformation": `${homepage}/blob/main/test/rules/letters-E-X.js`,
|
||||
"errorDetail": null,
|
||||
"errorContext": "text",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 7,
|
||||
"ruleNames": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
|
||||
"ruleDescription":
|
||||
"Rule that reports an error for lines with the letters 'EX'",
|
||||
"ruleInformation": `${homepage}/blob/main/test/rules/letters-E-X.js`,
|
||||
"errorDetail": null,
|
||||
"errorContext": "text",
|
||||
"errorRange": null }
|
||||
];
|
||||
const expectedResult = {
|
||||
[customRulesMd]: [
|
||||
{ "lineNumber": 12,
|
||||
"ruleNames": [ "any-blockquote-markdown-it" ],
|
||||
"ruleDescription": "Rule that reports an error for any blockquote",
|
||||
"ruleInformation":
|
||||
`${homepage}/blob/main/test/rules/any-blockquote.js`,
|
||||
"errorDetail": "Blockquote spans 1 line(s).",
|
||||
"errorContext": "> Blockquote",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 12,
|
||||
"ruleNames": [ "any-blockquote-micromark" ],
|
||||
"ruleDescription": "Rule that reports an error for any blockquote",
|
||||
"ruleInformation":
|
||||
`${homepage}/blob/main/test/rules/any-blockquote.js`,
|
||||
"errorDetail": "Blockquote spans 1 line(s).",
|
||||
"errorContext": "> Blockquote",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 2,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 2",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 4,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 4",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 6,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 6",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 10,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 10",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 12,
|
||||
"ruleNames": [ "every-n-lines" ],
|
||||
"ruleDescription": "Rule that reports an error every N lines",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Line number 12",
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 1,
|
||||
"ruleNames": [ "first-line" ],
|
||||
"ruleDescription": "Rule that reports an error for the first line",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": null,
|
||||
"errorContext": null,
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 3,
|
||||
"ruleNames": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
|
||||
"ruleDescription":
|
||||
"Rule that reports an error for lines with the letters 'EX'",
|
||||
"ruleInformation": `${homepage}/blob/main/test/rules/letters-E-X.js`,
|
||||
"errorDetail": null,
|
||||
"errorContext": "text",
|
||||
"errorRange": null },
|
||||
{ "lineNumber": 7,
|
||||
"ruleNames": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
|
||||
"ruleDescription":
|
||||
"Rule that reports an error for lines with the letters 'EX'",
|
||||
"ruleInformation": `${homepage}/blob/main/test/rules/letters-E-X.js`,
|
||||
"errorDetail": null,
|
||||
"errorContext": "text",
|
||||
"errorRange": null }
|
||||
]
|
||||
};
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
// @ts-ignore
|
||||
const actualMessage = actualResult.toString();
|
||||
|
@ -366,13 +369,14 @@ test("customRulesConfig", (t) => new Promise((resolve) => {
|
|||
};
|
||||
lintAsync(options, function callback(err, actualResult) {
|
||||
t.falsy(err);
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = {
|
||||
"any-blockquote-markdown-it": [ 12 ],
|
||||
"any-blockquote-micromark": [ 12 ],
|
||||
"every-n-lines": [ 3, 6, 12 ],
|
||||
"first-line": [ 1 ],
|
||||
"letters-E-X": [ 7 ]
|
||||
const expectedResult = {
|
||||
[customRulesMd]: {
|
||||
"any-blockquote-markdown-it": [ 12 ],
|
||||
"any-blockquote-micromark": [ 12 ],
|
||||
"every-n-lines": [ 3, 6, 12 ],
|
||||
"first-line": [ 1 ],
|
||||
"letters-E-X": [ 7 ]
|
||||
}
|
||||
};
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
resolve();
|
||||
|
@ -445,6 +449,7 @@ test("customRulesBadProperty", (t) => {
|
|||
const { propertyName, propertyValues } = testCase;
|
||||
for (const propertyValue of propertyValues) {
|
||||
const badRule = { ...customRules.firstLine };
|
||||
// @ts-ignore
|
||||
badRule[propertyName] = propertyValue;
|
||||
/** @type {import("markdownlint").Options} */
|
||||
const options = {
|
||||
|
@ -1211,6 +1216,7 @@ test("customRulesOnErrorBad", (t) => {
|
|||
]) {
|
||||
const { propertyName, subPropertyName, propertyValues } = testCase;
|
||||
for (const propertyValue of propertyValues) {
|
||||
/** @type {Object<string, any>} */
|
||||
const badObject = {
|
||||
"lineNumber": 1
|
||||
};
|
||||
|
@ -1232,6 +1238,7 @@ test("customRulesOnErrorBad", (t) => {
|
|||
"tags": [ "tag" ],
|
||||
"parser": "none",
|
||||
"function": function onErrorBad(params, onError) {
|
||||
// @ts-ignore
|
||||
onError(badObject);
|
||||
}
|
||||
}
|
||||
|
@ -1283,6 +1290,7 @@ test("customRulesOnErrorInvalid", (t) => {
|
|||
]) {
|
||||
const { propertyName, subPropertyName, propertyValues } = testCase;
|
||||
for (const propertyValue of propertyValues) {
|
||||
/** @type {Object<string, any>} */
|
||||
const badObject = {
|
||||
"lineNumber": 1
|
||||
};
|
||||
|
@ -1304,6 +1312,7 @@ test("customRulesOnErrorInvalid", (t) => {
|
|||
"tags": [ "tag" ],
|
||||
"parser": "none",
|
||||
"function": function onErrorInvalid(params, onError) {
|
||||
// @ts-ignore
|
||||
onError(badObject);
|
||||
}
|
||||
}
|
||||
|
@ -1361,6 +1370,7 @@ test("customRulesOnErrorValid", (t) => {
|
|||
]) {
|
||||
const { propertyName, subPropertyName, propertyValues } = testCase;
|
||||
for (const propertyValue of propertyValues) {
|
||||
/** @type {Object<string, any>} */
|
||||
const goodObject = {
|
||||
"lineNumber": 1
|
||||
};
|
||||
|
@ -1379,6 +1389,7 @@ test("customRulesOnErrorValid", (t) => {
|
|||
"tags": [ "tag" ],
|
||||
"parser": "none",
|
||||
"function": function onErrorValid(params, onError) {
|
||||
// @ts-ignore
|
||||
onError(goodObject);
|
||||
}
|
||||
}
|
||||
|
@ -1973,13 +1984,62 @@ test("customRulesAsyncThrowsInSyncContext", (t) => {
|
|||
);
|
||||
});
|
||||
|
||||
test("customRulesParamsConfigExcludesSeverity", (t) => {
|
||||
t.plan(4);
|
||||
/** @type {import("markdownlint").Rule} */
|
||||
const ruleBase = {
|
||||
"names": [ "tbd" ],
|
||||
"description": "description",
|
||||
"tags": [ "tag" ],
|
||||
"parser": "none",
|
||||
"asynchronous": true,
|
||||
"function": ({ config }) => {
|
||||
t.is(typeof config, "object");
|
||||
t.is(typeof config.severity, "undefined");
|
||||
}
|
||||
};
|
||||
/** @type {import("markdownlint").Options} */
|
||||
const options = {
|
||||
"config": {
|
||||
"name1": {
|
||||
"severity": "error"
|
||||
},
|
||||
"name2": {
|
||||
"key": "value",
|
||||
"severity": "error"
|
||||
}
|
||||
},
|
||||
"customRules": [
|
||||
{
|
||||
...ruleBase,
|
||||
"names": [ "name1" ]
|
||||
},
|
||||
{
|
||||
...ruleBase,
|
||||
"names": [ "name2" ]
|
||||
}
|
||||
],
|
||||
"strings": {
|
||||
"string": "Unused"
|
||||
}
|
||||
};
|
||||
return lintPromise(options);
|
||||
});
|
||||
|
||||
test("customRulesParamsAreFrozen", (t) => {
|
||||
/**
|
||||
* Asserts that rule parameters are frozen.
|
||||
*
|
||||
* @param {import("markdownlint").RuleParams} params Rule parameters.
|
||||
* @returns {void}
|
||||
*/
|
||||
const assertParamsFrozen = (params) => {
|
||||
const pending = [ params ];
|
||||
let current = null;
|
||||
while ((current = pending.shift())) {
|
||||
t.true(Object.isFrozen(current) || (current === params));
|
||||
for (const name of Object.getOwnPropertyNames(current)) {
|
||||
// @ts-ignore
|
||||
const value = current[name];
|
||||
if (
|
||||
value &&
|
||||
|
|
|
@ -346,17 +346,104 @@ test("enableRulesString", getConfigTestImplementation(
|
|||
configTestExpected3511
|
||||
));
|
||||
|
||||
test("enableRulesEmptyObject", getConfigTestImplementation(
|
||||
test("enableRulesObjectEmpty", getConfigTestImplementation(
|
||||
{
|
||||
"MD041": {},
|
||||
"default": false,
|
||||
// @ts-ignore
|
||||
"no-multiple-space-atx": {},
|
||||
"extra": {}
|
||||
},
|
||||
configTestExpected3511
|
||||
));
|
||||
|
||||
test("enableRulesObjectTruthy", getConfigTestImplementation(
|
||||
{
|
||||
"MD041": {
|
||||
// @ts-ignore
|
||||
"severity": 1
|
||||
},
|
||||
"default": false,
|
||||
"no-multiple-space-atx": {
|
||||
// @ts-ignore
|
||||
"severity": 1
|
||||
},
|
||||
"extra": {
|
||||
"severity": 1
|
||||
}
|
||||
},
|
||||
configTestExpected3511
|
||||
));
|
||||
|
||||
test("enableRulesObjectFalsy", getConfigTestImplementation(
|
||||
{
|
||||
"MD041": {
|
||||
// @ts-ignore
|
||||
"severity": 0
|
||||
},
|
||||
"default": false,
|
||||
"no-multiple-space-atx": {
|
||||
// @ts-ignore
|
||||
"severity": 0
|
||||
},
|
||||
"extra": {
|
||||
"severity": 0
|
||||
}
|
||||
},
|
||||
configTestExpected3511
|
||||
));
|
||||
|
||||
test("enableRulesObjectError", getConfigTestImplementation(
|
||||
{
|
||||
"MD041": {
|
||||
"severity": "error"
|
||||
},
|
||||
"default": false,
|
||||
"no-multiple-space-atx": {
|
||||
"severity": "error"
|
||||
},
|
||||
"extra": {
|
||||
"severity": "error"
|
||||
}
|
||||
},
|
||||
configTestExpected3511
|
||||
));
|
||||
|
||||
test("enableRulesObjectWarning", getConfigTestImplementation(
|
||||
{
|
||||
"MD041": {
|
||||
// @ts-ignore
|
||||
"severity": "warning"
|
||||
},
|
||||
"default": false,
|
||||
"no-multiple-space-atx": {
|
||||
// @ts-ignore
|
||||
"severity": "warning"
|
||||
},
|
||||
"extra": {
|
||||
"severity": "warning"
|
||||
}
|
||||
},
|
||||
configTestExpected3511
|
||||
));
|
||||
|
||||
test("enableRulesObjectOff", getConfigTestImplementation(
|
||||
{
|
||||
"MD041": {
|
||||
// @ts-ignore
|
||||
"severity": "off"
|
||||
},
|
||||
"default": false,
|
||||
"no-multiple-space-atx": {
|
||||
// @ts-ignore
|
||||
"severity": "off"
|
||||
},
|
||||
"extra": {
|
||||
"severity": "off"
|
||||
}
|
||||
},
|
||||
configTestExpected3511
|
||||
));
|
||||
|
||||
test("disableTag", getConfigTestImplementation(
|
||||
{
|
||||
"default": true,
|
||||
|
@ -921,7 +1008,7 @@ test("readme", async(t) => {
|
|||
});
|
||||
|
||||
test("validateJsonUsingConfigSchemaStrict", async(t) => {
|
||||
t.plan(211);
|
||||
t.plan(212);
|
||||
// @ts-ignore
|
||||
const ajv = new Ajv(ajvOptions);
|
||||
const validateSchemaStrict = ajv.compile(configSchemaStrict);
|
||||
|
|
|
@ -11203,6 +11203,320 @@ Generated by [AVA](https://avajs.dev).
|
|||
`,
|
||||
}
|
||||
|
||||
## configure-file-with-severity.md
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
{
|
||||
errors: [
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: 'Expected: dash; Actual: plus',
|
||||
errorRange: [
|
||||
1,
|
||||
1,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 1,
|
||||
insertText: '-',
|
||||
},
|
||||
lineNumber: 9,
|
||||
ruleDescription: 'Unordered list style',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md004.md',
|
||||
ruleNames: [
|
||||
'MD004',
|
||||
'ul-style',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: 'Expected: dash; Actual: plus',
|
||||
errorRange: [
|
||||
1,
|
||||
1,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 1,
|
||||
insertText: '-',
|
||||
},
|
||||
lineNumber: 37,
|
||||
ruleDescription: 'Unordered list style',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md004.md',
|
||||
ruleNames: [
|
||||
'MD004',
|
||||
'ul-style',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: '(text)[.]',
|
||||
errorRange: [
|
||||
6,
|
||||
9,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 9,
|
||||
editColumn: 6,
|
||||
insertText: '[text](.)',
|
||||
},
|
||||
lineNumber: 11,
|
||||
ruleDescription: 'Reversed link syntax',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md011.md',
|
||||
ruleNames: [
|
||||
'MD011',
|
||||
'no-reversed-links',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: '(text)[.]',
|
||||
errorRange: [
|
||||
6,
|
||||
9,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 9,
|
||||
editColumn: 6,
|
||||
insertText: '[text](.)',
|
||||
},
|
||||
lineNumber: 39,
|
||||
ruleDescription: 'Reversed link syntax',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md011.md',
|
||||
ruleNames: [
|
||||
'MD011',
|
||||
'no-reversed-links',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: 'Expected: 1; Actual: 2; Style: 1/1/1',
|
||||
errorRange: [
|
||||
1,
|
||||
3,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 1,
|
||||
insertText: '1',
|
||||
},
|
||||
lineNumber: 13,
|
||||
ruleDescription: 'Ordered list item prefix',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md029.md',
|
||||
ruleNames: [
|
||||
'MD029',
|
||||
'ol-prefix',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: 'Expected: 1; Actual: 2; Style: 1/1/1',
|
||||
errorRange: [
|
||||
1,
|
||||
3,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 1,
|
||||
insertText: '1',
|
||||
},
|
||||
lineNumber: 41,
|
||||
ruleDescription: 'Ordered list item prefix',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md029.md',
|
||||
ruleNames: [
|
||||
'MD029',
|
||||
'ol-prefix',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: '* t',
|
||||
errorDetail: null,
|
||||
errorRange: [
|
||||
7,
|
||||
1,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 7,
|
||||
},
|
||||
lineNumber: 3,
|
||||
ruleDescription: 'Spaces inside emphasis markers',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md037.md',
|
||||
ruleNames: [
|
||||
'MD037',
|
||||
'no-space-in-emphasis',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: '* t',
|
||||
errorDetail: null,
|
||||
errorRange: [
|
||||
7,
|
||||
1,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 7,
|
||||
},
|
||||
lineNumber: 31,
|
||||
ruleDescription: 'Spaces inside emphasis markers',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md037.md',
|
||||
ruleNames: [
|
||||
'MD037',
|
||||
'no-space-in-emphasis',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: '` text`',
|
||||
errorDetail: null,
|
||||
errorRange: [
|
||||
7,
|
||||
1,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 7,
|
||||
},
|
||||
lineNumber: 5,
|
||||
ruleDescription: 'Spaces inside code span elements',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md038.md',
|
||||
ruleNames: [
|
||||
'MD038',
|
||||
'no-space-in-code',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: '` text`',
|
||||
errorDetail: null,
|
||||
errorRange: [
|
||||
7,
|
||||
1,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 7,
|
||||
},
|
||||
lineNumber: 33,
|
||||
ruleDescription: 'Spaces inside code span elements',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md038.md',
|
||||
ruleNames: [
|
||||
'MD038',
|
||||
'no-space-in-code',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: '[ text]',
|
||||
errorDetail: null,
|
||||
errorRange: [
|
||||
7,
|
||||
1,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 7,
|
||||
},
|
||||
lineNumber: 7,
|
||||
ruleDescription: 'Spaces inside link text',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
|
||||
ruleNames: [
|
||||
'MD039',
|
||||
'no-space-in-links',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
{
|
||||
errorContext: '[ text]',
|
||||
errorDetail: null,
|
||||
errorRange: [
|
||||
7,
|
||||
1,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 1,
|
||||
editColumn: 7,
|
||||
},
|
||||
lineNumber: 35,
|
||||
ruleDescription: 'Spaces inside link text',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
|
||||
ruleNames: [
|
||||
'MD039',
|
||||
'no-space-in-links',
|
||||
],
|
||||
severity: 'error',
|
||||
},
|
||||
],
|
||||
fixed: `# Configure File With Severity␊
|
||||
␊
|
||||
Text *text* {MD037}␊
|
||||
␊
|
||||
Text \`text\` {MD038}␊
|
||||
␊
|
||||
Text [text](.) {MD039}␊
|
||||
␊
|
||||
- List item {MD004}␊
|
||||
␊
|
||||
Text [text](.) {MD011}␊
|
||||
␊
|
||||
1. List item {MD029}␊
|
||||
␊
|
||||
<!-- markdownlint-disable -->␊
|
||||
␊
|
||||
Text * text*␊
|
||||
␊
|
||||
Text \` text\`␊
|
||||
␊
|
||||
Text [ text](.)␊
|
||||
␊
|
||||
+ List item␊
|
||||
␊
|
||||
Text (text)[.]␊
|
||||
␊
|
||||
2. List item␊
|
||||
␊
|
||||
<!-- markdownlint-restore -->␊
|
||||
␊
|
||||
Text *text* {MD037}␊
|
||||
␊
|
||||
Text \`text\` {MD038}␊
|
||||
␊
|
||||
Text [text](.) {MD039}␊
|
||||
␊
|
||||
- List item {MD004}␊
|
||||
␊
|
||||
Text [text](.) {MD011}␊
|
||||
␊
|
||||
1. List item {MD029}␊
|
||||
␊
|
||||
<!-- markdownlint-configure-file {␊
|
||||
"default": false,␊
|
||||
"MD037": "error",␊
|
||||
"MD038": "error",␊
|
||||
"MD039": "error",␊
|
||||
"MD004": {␊
|
||||
"severity": "error",␊
|
||||
"style": "dash"␊
|
||||
},␊
|
||||
"MD011": {␊
|
||||
"severity": "error"␊
|
||||
},␊
|
||||
"MD029": {␊
|
||||
"severity": "error"␊
|
||||
}␊
|
||||
} -->␊
|
||||
`,
|
||||
}
|
||||
|
||||
## consecutive_blank_lines.md
|
||||
|
||||
> Snapshot 1
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue