eslint-doc-generator
Advanced tools
Comparing version 0.18.1 to 0.18.2
@@ -18,3 +18,2 @@ import type { Plugin, ConfigsToRules, ConfigEmojis, RuleSeverity, SEVERITY_TYPE } from './types.js'; | ||
* @param options.fallback - if true and no emoji is found, choose whether to fallback to a generic config emoji or a badge | ||
* @param options.noWrap - whether to add styling to ensure the superscript doesn't wrap to a separate line when used in constrained spaces | ||
* @returns the string to display for the config | ||
@@ -25,3 +24,2 @@ */ | ||
fallback?: 'badge' | 'emoji'; | ||
noWrap?: boolean; | ||
}): string | undefined; |
@@ -58,3 +58,3 @@ import { EMOJI_CONFIGS, EMOJI_CONFIG, EMOJI_CONFIG_WARN, EMOJI_CONFIG_OFF, } from './emojis.js'; | ||
} | ||
function emojiWithSuperscript(emoji, superscriptEmoji, noWrap = false) { | ||
function emojiWithSuperscript(emoji, superscriptEmoji) { | ||
if (emoji === superscriptEmoji) { | ||
@@ -64,6 +64,3 @@ // Avoid double emoji. | ||
} | ||
// Style is to ensure superscript doesn't wrap to separate line, useful in constrained spaces. | ||
return noWrap | ||
? `<span style="white-space:nowrap">${emoji}<sup>${superscriptEmoji}</sup></span>` | ||
: `${emoji}<sup>${superscriptEmoji}</sup>`; | ||
return `${emoji}<sup>${superscriptEmoji}</sup>`; | ||
} | ||
@@ -77,3 +74,2 @@ /** | ||
* @param options.fallback - if true and no emoji is found, choose whether to fallback to a generic config emoji or a badge | ||
* @param options.noWrap - whether to add styling to ensure the superscript doesn't wrap to a separate line when used in constrained spaces | ||
* @returns the string to display for the config | ||
@@ -97,5 +93,5 @@ */ | ||
case 'warn': | ||
return emojiWithSuperscript(emoji, EMOJI_CONFIG_WARN, options.noWrap); | ||
return emojiWithSuperscript(emoji, EMOJI_CONFIG_WARN); | ||
case 'off': | ||
return emojiWithSuperscript(emoji, EMOJI_CONFIG_OFF, options.noWrap); | ||
return emojiWithSuperscript(emoji, EMOJI_CONFIG_OFF); | ||
default: | ||
@@ -102,0 +98,0 @@ return emoji; |
@@ -9,3 +9,3 @@ import { BEGIN_RULE_LIST_MARKER, END_RULE_LIST_MARKER } from './markers.js'; | ||
import { relative } from 'node:path'; | ||
import { COLUMN_TYPE, SEVERITY_ERROR, SEVERITY_WARN, SEVERITY_OFF, SEVERITY_TYPE, } from './types.js'; | ||
import { COLUMN_TYPE, SEVERITY_TYPE, SEVERITY_TYPE_TO_SET } from './types.js'; | ||
import { markdownTable } from 'markdown-table'; | ||
@@ -40,37 +40,33 @@ import camelCase from 'camelcase'; | ||
} | ||
/** | ||
* Get the emojis for the configs that set a rule to a certain severity. | ||
*/ | ||
function getEmojisForConfigsSettingRuleToSeverity(ruleName, configsToRulesWithoutIgnored, pluginPrefix, configEmojis, severityType) { | ||
const severity = SEVERITY_TYPE_TO_SET[severityType]; | ||
const configsOfThisSeverity = getConfigsForRule(ruleName, configsToRulesWithoutIgnored, pluginPrefix, severity); | ||
const emojis = []; | ||
for (const configName of configsOfThisSeverity) { | ||
// Find the emoji for each config or otherwise use a badge that can be defined in markdown. | ||
const emoji = findConfigEmoji(configEmojis, configName, { | ||
severity: severityType, | ||
fallback: 'badge', | ||
}); | ||
/* istanbul ignore next -- this shouldn't happen */ | ||
if (typeof emoji !== 'string') { | ||
throw new TypeError('Emoji will always be a string thanks to fallback'); | ||
} | ||
// For emojis with a superscript, add a newline first to ensure we don't end up with a linebreak between the emoji and the superscript. | ||
emojis.push(emoji.includes('<sup>') ? `<br>${emoji}` : emoji); | ||
} | ||
return emojis; | ||
} | ||
function getConfigurationColumnValueForRule(rule, configsToRules, pluginPrefix, configEmojis, ignoreConfig) { | ||
const badges = []; | ||
const emojis = []; | ||
const configsToRulesWithoutIgnored = Object.fromEntries(Object.entries(configsToRules).filter(([configName]) => !ignoreConfig?.includes(configName))); | ||
const configsEnabled = getConfigsForRule(rule.name, configsToRulesWithoutIgnored, pluginPrefix, SEVERITY_ERROR); | ||
const configsWarn = getConfigsForRule(rule.name, configsToRulesWithoutIgnored, pluginPrefix, SEVERITY_WARN); | ||
const configsOff = getConfigsForRule(rule.name, configsToRulesWithoutIgnored, pluginPrefix, SEVERITY_OFF); | ||
// Find the emoji for each config or otherwise use a badge that can be defined in markdown. | ||
for (const configName of configsEnabled) { | ||
badges.push( | ||
// @ts-expect-error -- will always be a string thanks to fallback | ||
findConfigEmoji(configEmojis, configName, { | ||
severity: SEVERITY_TYPE.error, | ||
fallback: 'badge', | ||
noWrap: true, | ||
})); | ||
// Collect the emojis for the configs that set the rule to each severity level. | ||
emojis.push(...getEmojisForConfigsSettingRuleToSeverity(rule.name, configsToRulesWithoutIgnored, pluginPrefix, configEmojis, SEVERITY_TYPE.error), ...getEmojisForConfigsSettingRuleToSeverity(rule.name, configsToRulesWithoutIgnored, pluginPrefix, configEmojis, SEVERITY_TYPE.warn), ...getEmojisForConfigsSettingRuleToSeverity(rule.name, configsToRulesWithoutIgnored, pluginPrefix, configEmojis, SEVERITY_TYPE.off)); | ||
if (emojis.length > 0 && emojis[0].startsWith('<br>')) { | ||
emojis[0] = emojis[0].slice(4); // Avoid any leading linebreak. Linebreak only necessary after emojis and before emojis with superscripts. | ||
} | ||
for (const configName of configsWarn) { | ||
badges.push( | ||
// @ts-expect-error -- will always be a string thanks to fallback | ||
findConfigEmoji(configEmojis, configName, { | ||
severity: SEVERITY_TYPE.warn, | ||
fallback: 'badge', | ||
noWrap: true, | ||
})); | ||
} | ||
for (const configName of configsOff) { | ||
badges.push( | ||
// @ts-expect-error -- will always be a string thanks to fallback | ||
findConfigEmoji(configEmojis, configName, { | ||
severity: SEVERITY_TYPE.off, | ||
fallback: 'badge', | ||
noWrap: true, | ||
})); | ||
} | ||
return badges.join(' '); | ||
return emojis.join(' '); | ||
} | ||
@@ -77,0 +73,0 @@ function buildRuleRow(columnsEnabled, rule, configsToRules, pluginPrefix, configEmojis, ignoreConfig) { |
@@ -15,2 +15,5 @@ import type { TSESLint, JSONSchema } from '@typescript-eslint/utils'; | ||
} | ||
export declare const SEVERITY_TYPE_TO_SET: { | ||
[key in SEVERITY_TYPE]: Set<TSESLint.Linter.RuleLevel>; | ||
}; | ||
export declare type ConfigsToRules = Record<string, Rules>; | ||
@@ -17,0 +20,0 @@ export interface RuleDetails { |
@@ -11,2 +11,7 @@ // Custom types. | ||
})(SEVERITY_TYPE || (SEVERITY_TYPE = {})); | ||
export const SEVERITY_TYPE_TO_SET = { | ||
[SEVERITY_TYPE.error]: SEVERITY_ERROR, | ||
[SEVERITY_TYPE.warn]: SEVERITY_WARN, | ||
[SEVERITY_TYPE.off]: SEVERITY_OFF, | ||
}; | ||
/** | ||
@@ -13,0 +18,0 @@ * Rule doc notices. |
{ | ||
"name": "eslint-doc-generator", | ||
"version": "0.18.1", | ||
"version": "0.18.2", | ||
"description": "Automatic documentation generator for ESLint plugins and rules.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -222,7 +222,7 @@ # eslint-doc-generator | ||
The output of this tool should be compatible with [markdownlint](https://github.com/DavidAnson/markdownlint) which you might use to lint your markdown. However, if any of your ESLint configs disable your rules or set them to warn, you'll need to exempt some elements used for the emoji superscript from [no-inline-html](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md033---inline-html): | ||
The output of this tool should be compatible with [markdownlint](https://github.com/DavidAnson/markdownlint) which you might use to lint your markdown. However, if any of your ESLint configs disable your rules or set them to warn, you'll need to exempt some elements used for emoji superscripts from [no-inline-html](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md033---inline-html): | ||
```json | ||
{ | ||
"no-inline-html": { "allowed_elements": ["span", "sup"] } | ||
"no-inline-html": { "allowed_elements": ["br", "sup"] } | ||
} | ||
@@ -229,0 +229,0 @@ ``` |
90872
1597