mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
wip
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
05509da984
commit
8021c087d4
7 changed files with 1507 additions and 753 deletions
482
lib/configuration-strict.d.ts
vendored
482
lib/configuration-strict.d.ts
vendored
File diff suppressed because it is too large
Load diff
|
@ -82,6 +82,19 @@ export function applyFixes(input: string, errors: LintError[]): string;
|
||||||
* @returns {string} SemVer string.
|
* @returns {string} SemVer string.
|
||||||
*/
|
*/
|
||||||
export function getVersion(): string;
|
export function getVersion(): string;
|
||||||
|
/**
|
||||||
|
* Result object for getEffectiveConfig.
|
||||||
|
*/
|
||||||
|
export type GetEffectiveConfigResult = {
|
||||||
|
/**
|
||||||
|
* Effective configuration.
|
||||||
|
*/
|
||||||
|
effectiveConfig: Configuration;
|
||||||
|
/**
|
||||||
|
* Rule severities
|
||||||
|
*/
|
||||||
|
ruleSeverities: Map<string, "error" | "warning" | "off">;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Result object for getEnabledRulesPerLineNumber.
|
* Result object for getEnabledRulesPerLineNumber.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -236,25 +236,41 @@ function mapAliasToRuleNames(ruleList) {
|
||||||
return aliasToRuleNames;
|
return aliasToRuleNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Result object for getEffectiveConfig.
|
||||||
|
*
|
||||||
|
* @typedef {Object} GetEffectiveConfigResult
|
||||||
|
* @property {Configuration} effectiveConfig Effective configuration.
|
||||||
|
* @property {Map<string, "error" | "warning" | "off">} ruleSeverities Rule severities
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply (and normalize) configuration object.
|
* Apply (and normalize) configuration object.
|
||||||
*
|
*
|
||||||
* @param {Rule[]} ruleList List of rules.
|
* @param {Rule[]} ruleList List of rules.
|
||||||
* @param {Configuration} config Configuration object.
|
* @param {Configuration} config Configuration object.
|
||||||
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
|
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule names.
|
||||||
* names.
|
* @returns {GetEffectiveConfigResult} Effective configuration and rule severities.
|
||||||
* @returns {Configuration} Effective configuration.
|
|
||||||
*/
|
*/
|
||||||
function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
||||||
const defaultKey = Object.keys(config).filter(
|
let ruleDefaultEnable = true;
|
||||||
(key) => key.toUpperCase() === "DEFAULT"
|
let ruleDefaultSeverity = "error";
|
||||||
);
|
Object.entries(config).every(([ key, value ]) => {
|
||||||
const ruleDefault = (defaultKey.length === 0) || !!config[defaultKey[0]];
|
if (key.toUpperCase() === "DEFAULT") {
|
||||||
|
ruleDefaultEnable = !!value;
|
||||||
|
if (value === "warning") {
|
||||||
|
ruleDefaultSeverity = "warning";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
/** @type {Configuration} */
|
/** @type {Configuration} */
|
||||||
const effectiveConfig = {};
|
const effectiveConfig = {};
|
||||||
for (const rule of ruleList) {
|
const ruleSeverities = new Map();
|
||||||
const ruleName = rule.names[0].toUpperCase();
|
for (const ruleName of ruleList.map((rule) => rule.names[0].toUpperCase())) {
|
||||||
effectiveConfig[ruleName] = ruleDefault;
|
effectiveConfig[ruleName] = ruleDefaultEnable;
|
||||||
|
ruleSeverities.set(ruleName, ruleDefaultSeverity);
|
||||||
}
|
}
|
||||||
// for (const ruleName of deprecatedRuleNames) {
|
// for (const ruleName of deprecatedRuleNames) {
|
||||||
// effectiveConfig[ruleName] = false;
|
// effectiveConfig[ruleName] = false;
|
||||||
|
@ -262,18 +278,33 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
||||||
for (const key of Object.keys(config)) {
|
for (const key of Object.keys(config)) {
|
||||||
let value = config[key];
|
let value = config[key];
|
||||||
if (value) {
|
if (value) {
|
||||||
value = (value instanceof Object) ?
|
if (value instanceof Object) {
|
||||||
Object.fromEntries(Object.entries(value).filter(([ k ]) => k !== "severity")) :
|
// @ts-ignore
|
||||||
{};
|
const severity = value.severity;
|
||||||
|
if (severity === "off") {
|
||||||
|
value = false;
|
||||||
|
} else {
|
||||||
|
if (severity === "warning") {
|
||||||
|
ruleSeverities.set(key.toUpperCase(), "warning");
|
||||||
|
} else {
|
||||||
|
ruleSeverities.set(key.toUpperCase(), "error");
|
||||||
|
}
|
||||||
|
value = Object.fromEntries(Object.entries(value).filter(([ k ]) => k !== "severity"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = {};
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
value = false;
|
value = false;
|
||||||
}
|
}
|
||||||
const keyUpper = key.toUpperCase();
|
for (const ruleName of (aliasToRuleNames[key.toUpperCase()] || [])) {
|
||||||
for (const ruleName of (aliasToRuleNames[keyUpper] || [])) {
|
|
||||||
effectiveConfig[ruleName] = value;
|
effectiveConfig[ruleName] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return effectiveConfig;
|
return {
|
||||||
|
effectiveConfig,
|
||||||
|
ruleSeverities
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -397,8 +428,7 @@ function getEnabledRulesPerLineNumber(
|
||||||
}
|
}
|
||||||
// Handle inline comments
|
// Handle inline comments
|
||||||
handleInlineConfig([ lines.join("\n") ], configureFile);
|
handleInlineConfig([ lines.join("\n") ], configureFile);
|
||||||
const effectiveConfig = getEffectiveConfig(
|
const { effectiveConfig } = getEffectiveConfig(ruleList, config, aliasToRuleNames);
|
||||||
ruleList, config, aliasToRuleNames);
|
|
||||||
for (const rule of ruleList) {
|
for (const rule of ruleList) {
|
||||||
const ruleName = rule.names[0].toUpperCase();
|
const ruleName = rule.names[0].toUpperCase();
|
||||||
allRuleNames.push(ruleName);
|
allRuleNames.push(ruleName);
|
||||||
|
|
|
@ -30,7 +30,8 @@ const schema = {
|
||||||
"description": "Default state for all rules",
|
"description": "Default state for all rules",
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
{ "type": "boolean" },
|
{ "type": "boolean" },
|
||||||
{ "enum": [ "error" ] }
|
// "off" not (yet) supported because behavior of older versions would be to enable
|
||||||
|
{ "enum": [ "error", "warning" ] }
|
||||||
],
|
],
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
|
@ -66,7 +67,8 @@ for (const rule of rules) {
|
||||||
`${rule.names.join("/")} : ${rule.description} : ${rule.information}`,
|
`${rule.names.join("/")} : ${rule.description} : ${rule.information}`,
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
{ "type": "boolean" },
|
{ "type": "boolean" },
|
||||||
{ "enum": [ "error" ] }
|
// "off" not (yet) supported because behavior of older versions would be to enable
|
||||||
|
{ "enum": [ "error", "warning" ] }
|
||||||
],
|
],
|
||||||
"default": true
|
"default": true
|
||||||
};
|
};
|
||||||
|
@ -77,9 +79,7 @@ for (const rule of rules) {
|
||||||
"severity": {
|
"severity": {
|
||||||
"description": "Rule severity",
|
"description": "Rule severity",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [ "error", "warning", "off" ],
|
||||||
"error"
|
|
||||||
],
|
|
||||||
"default": "error"
|
"default": "error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -656,7 +656,8 @@ for (const [ tag, tagTags ] of Object.entries(tags)) {
|
||||||
"description": `${tag} : ${tagTags.join(", ")}`,
|
"description": `${tag} : ${tagTags.join(", ")}`,
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
{ "type": "boolean" },
|
{ "type": "boolean" },
|
||||||
{ "enum": [ "error" ] }
|
// "off" not (yet) supported because behavior of older versions would be to enable
|
||||||
|
{ "enum": [ "error", "warning" ] }
|
||||||
],
|
],
|
||||||
"default": true
|
"default": true
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -282,6 +282,22 @@ test("defaultOff", getConfigTestImplementation(
|
||||||
configTestExpected13511
|
configTestExpected13511
|
||||||
));
|
));
|
||||||
|
|
||||||
|
test("defaultMultipleTrue", getConfigTestImplementation(
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"DEFAULT": false
|
||||||
|
},
|
||||||
|
configTestExpected13511
|
||||||
|
));
|
||||||
|
|
||||||
|
test("defaultMultipleFalse", getConfigTestImplementation(
|
||||||
|
{
|
||||||
|
"DEFAULT": false,
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
configTestExpected
|
||||||
|
));
|
||||||
|
|
||||||
test("disableRules", getConfigTestImplementation(
|
test("disableRules", getConfigTestImplementation(
|
||||||
{
|
{
|
||||||
"default": true,
|
"default": true,
|
||||||
|
@ -411,12 +427,10 @@ test("enableRulesObjectError", getConfigTestImplementation(
|
||||||
test("enableRulesObjectWarning", getConfigTestImplementation(
|
test("enableRulesObjectWarning", getConfigTestImplementation(
|
||||||
{
|
{
|
||||||
"MD041": {
|
"MD041": {
|
||||||
// @ts-ignore
|
|
||||||
"severity": "warning"
|
"severity": "warning"
|
||||||
},
|
},
|
||||||
"default": false,
|
"default": false,
|
||||||
"no-multiple-space-atx": {
|
"no-multiple-space-atx": {
|
||||||
// @ts-ignore
|
|
||||||
"severity": "warning"
|
"severity": "warning"
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
|
@ -429,19 +443,17 @@ test("enableRulesObjectWarning", getConfigTestImplementation(
|
||||||
test("enableRulesObjectOff", getConfigTestImplementation(
|
test("enableRulesObjectOff", getConfigTestImplementation(
|
||||||
{
|
{
|
||||||
"MD041": {
|
"MD041": {
|
||||||
// @ts-ignore
|
|
||||||
"severity": "off"
|
"severity": "off"
|
||||||
},
|
},
|
||||||
"default": false,
|
"default": true,
|
||||||
"no-multiple-space-atx": {
|
"no-multiple-space-atx": {
|
||||||
// @ts-ignore
|
|
||||||
"severity": "off"
|
"severity": "off"
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"severity": "off"
|
"severity": "off"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
configTestExpected3511
|
configTestExpected1
|
||||||
));
|
));
|
||||||
|
|
||||||
test("disableTag", getConfigTestImplementation(
|
test("disableTag", getConfigTestImplementation(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue