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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -236,25 +236,41 @@ function mapAliasToRuleNames(ruleList) {
|
|||
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.
|
||||
*
|
||||
* @param {Rule[]} ruleList List of rules.
|
||||
* @param {Configuration} config Configuration object.
|
||||
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
|
||||
* names.
|
||||
* @returns {Configuration} Effective configuration.
|
||||
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule names.
|
||||
* @returns {GetEffectiveConfigResult} Effective configuration and rule severities.
|
||||
*/
|
||||
function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
||||
const defaultKey = Object.keys(config).filter(
|
||||
(key) => key.toUpperCase() === "DEFAULT"
|
||||
);
|
||||
const ruleDefault = (defaultKey.length === 0) || !!config[defaultKey[0]];
|
||||
let ruleDefaultEnable = true;
|
||||
let ruleDefaultSeverity = "error";
|
||||
Object.entries(config).every(([ key, value ]) => {
|
||||
if (key.toUpperCase() === "DEFAULT") {
|
||||
ruleDefaultEnable = !!value;
|
||||
if (value === "warning") {
|
||||
ruleDefaultSeverity = "warning";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
/** @type {Configuration} */
|
||||
const effectiveConfig = {};
|
||||
for (const rule of ruleList) {
|
||||
const ruleName = rule.names[0].toUpperCase();
|
||||
effectiveConfig[ruleName] = ruleDefault;
|
||||
const ruleSeverities = new Map();
|
||||
for (const ruleName of ruleList.map((rule) => rule.names[0].toUpperCase())) {
|
||||
effectiveConfig[ruleName] = ruleDefaultEnable;
|
||||
ruleSeverities.set(ruleName, ruleDefaultSeverity);
|
||||
}
|
||||
// for (const ruleName of deprecatedRuleNames) {
|
||||
// effectiveConfig[ruleName] = false;
|
||||
|
@ -262,18 +278,33 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
|||
for (const key of Object.keys(config)) {
|
||||
let value = config[key];
|
||||
if (value) {
|
||||
value = (value instanceof Object) ?
|
||||
Object.fromEntries(Object.entries(value).filter(([ k ]) => k !== "severity")) :
|
||||
{};
|
||||
if (value instanceof Object) {
|
||||
// @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 {
|
||||
value = false;
|
||||
}
|
||||
const keyUpper = key.toUpperCase();
|
||||
for (const ruleName of (aliasToRuleNames[keyUpper] || [])) {
|
||||
for (const ruleName of (aliasToRuleNames[key.toUpperCase()] || [])) {
|
||||
effectiveConfig[ruleName] = value;
|
||||
}
|
||||
}
|
||||
return effectiveConfig;
|
||||
return {
|
||||
effectiveConfig,
|
||||
ruleSeverities
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -397,8 +428,7 @@ function getEnabledRulesPerLineNumber(
|
|||
}
|
||||
// Handle inline comments
|
||||
handleInlineConfig([ lines.join("\n") ], configureFile);
|
||||
const effectiveConfig = getEffectiveConfig(
|
||||
ruleList, config, aliasToRuleNames);
|
||||
const { effectiveConfig } = getEffectiveConfig(ruleList, config, aliasToRuleNames);
|
||||
for (const rule of ruleList) {
|
||||
const ruleName = rule.names[0].toUpperCase();
|
||||
allRuleNames.push(ruleName);
|
||||
|
|
|
@ -30,7 +30,8 @@ const schema = {
|
|||
"description": "Default state for all rules",
|
||||
"oneOf": [
|
||||
{ "type": "boolean" },
|
||||
{ "enum": [ "error" ] }
|
||||
// "off" not (yet) supported because behavior of older versions would be to enable
|
||||
{ "enum": [ "error", "warning" ] }
|
||||
],
|
||||
"default": true
|
||||
},
|
||||
|
@ -66,7 +67,8 @@ for (const rule of rules) {
|
|||
`${rule.names.join("/")} : ${rule.description} : ${rule.information}`,
|
||||
"oneOf": [
|
||||
{ "type": "boolean" },
|
||||
{ "enum": [ "error" ] }
|
||||
// "off" not (yet) supported because behavior of older versions would be to enable
|
||||
{ "enum": [ "error", "warning" ] }
|
||||
],
|
||||
"default": true
|
||||
};
|
||||
|
@ -77,9 +79,7 @@ for (const rule of rules) {
|
|||
"severity": {
|
||||
"description": "Rule severity",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"error"
|
||||
],
|
||||
"enum": [ "error", "warning", "off" ],
|
||||
"default": "error"
|
||||
}
|
||||
}
|
||||
|
@ -656,7 +656,8 @@ for (const [ tag, tagTags ] of Object.entries(tags)) {
|
|||
"description": `${tag} : ${tagTags.join(", ")}`,
|
||||
"oneOf": [
|
||||
{ "type": "boolean" },
|
||||
{ "enum": [ "error" ] }
|
||||
// "off" not (yet) supported because behavior of older versions would be to enable
|
||||
{ "enum": [ "error", "warning" ] }
|
||||
],
|
||||
"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
|
||||
));
|
||||
|
||||
test("defaultMultipleTrue", getConfigTestImplementation(
|
||||
{
|
||||
"default": true,
|
||||
"DEFAULT": false
|
||||
},
|
||||
configTestExpected13511
|
||||
));
|
||||
|
||||
test("defaultMultipleFalse", getConfigTestImplementation(
|
||||
{
|
||||
"DEFAULT": false,
|
||||
"default": true
|
||||
},
|
||||
configTestExpected
|
||||
));
|
||||
|
||||
test("disableRules", getConfigTestImplementation(
|
||||
{
|
||||
"default": true,
|
||||
|
@ -411,12 +427,10 @@ test("enableRulesObjectError", getConfigTestImplementation(
|
|||
test("enableRulesObjectWarning", getConfigTestImplementation(
|
||||
{
|
||||
"MD041": {
|
||||
// @ts-ignore
|
||||
"severity": "warning"
|
||||
},
|
||||
"default": false,
|
||||
"no-multiple-space-atx": {
|
||||
// @ts-ignore
|
||||
"severity": "warning"
|
||||
},
|
||||
"extra": {
|
||||
|
@ -429,19 +443,17 @@ test("enableRulesObjectWarning", getConfigTestImplementation(
|
|||
test("enableRulesObjectOff", getConfigTestImplementation(
|
||||
{
|
||||
"MD041": {
|
||||
// @ts-ignore
|
||||
"severity": "off"
|
||||
},
|
||||
"default": false,
|
||||
"default": true,
|
||||
"no-multiple-space-atx": {
|
||||
// @ts-ignore
|
||||
"severity": "off"
|
||||
},
|
||||
"extra": {
|
||||
"severity": "off"
|
||||
}
|
||||
},
|
||||
configTestExpected3511
|
||||
configTestExpected1
|
||||
));
|
||||
|
||||
test("disableTag", getConfigTestImplementation(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue