Skip to content

Commit c60554b

Browse files
authored
Merge pull request #205 from bmish/separate-config-cols
2 parents 53fdcf3 + 9681c71 commit c60554b

10 files changed

+443
-573
lines changed

README.md

+7-19
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,11 @@ Generated content in a rule doc (everything above the marker comment) (intention
8686
```md
8787
# Disallow using foo (`test/no-foo`)
8888

89-
✅ This rule is enabled in the `recommended` config.
90-
9189
💼 This rule is enabled in the following configs: ✅ `recommended`, 🎨 `stylistic`.
9290

93-
🎨<sup>⚠️</sup> This rule _warns_ in the `stylistic` config.
91+
⚠️ This rule _warns_ in the 🎨 `stylistic` config.
9492

95-
🎨<sup>🚫</sup> This rule is _disabled_ in the `stylistic` config.
93+
🚫 This rule is _disabled_ in the 🎨 `stylistic` config.
9694

9795
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
9896

@@ -131,10 +129,10 @@ Generated rules table in `README.md` (everything between the marker comments) (i
131129
<!-- begin auto-generated rules list -->
132130

133131
💼 Configurations enabled in.\
134-
✅ Enabled in the `recommended` configuration.\
135-
✅<sup>⚠️</sup> Warns in the `recommended` configuration.\
136-
<sup>🚫</sup> Disabled in the `recommended` configuration.\
137-
🎨 Enabled in the `stylistic` configuration.\
132+
⚠️ Configurations set to warn in.\
133+
🚫 Configurations disabled in.\
134+
Set in the `recommended` configuration.\
135+
🎨 Set in the `stylistic` configuration.\
138136
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
139137
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).\
140138
💭 Requires type information.\
@@ -186,7 +184,7 @@ And how it looks:
186184
| `--rule-doc-section-include` | Required section in each rule doc. Exit with failure if missing. Option can be repeated. |
187185
| `--rule-doc-section-options` | Whether to require an "Options" or "Config" rule doc section and mention of any named options for rules with options (default: `true`). |
188186
| `--rule-doc-title-format` | The format to use for rule doc titles. Defaults to `desc-parens-prefix-name`. See choices in below [table](#--rule-doc-title-format). |
189-
| `--rule-list-columns` | Ordered, comma-separated list of columns to display in rule list. Empty columns will be hidden. Choices: `configs`, `deprecated`, `description`, `fixable`, `hasSuggestions`, `name`, `requiresTypeChecking`, `type` (off by default). Default: `name,description,configs,fixable,hasSuggestions,requiresTypeChecking,deprecated`. |
187+
| `--rule-list-columns` | Ordered, comma-separated list of columns to display in rule list. Empty columns will be hidden. Choices: `configsError`, `configsOff`, `configsWarn`, `deprecated`, `description`, `fixable`, `hasSuggestions`, `name`, `requiresTypeChecking`, `type` (off by default). Default: `name,description,configsError,configsWarn,configsOff,fixable,hasSuggestions,requiresTypeChecking,deprecated`. |
190188
| `--split-by` | Rule property to split the rules list by. A separate list and header will be created for each value. Example: `meta.type`. |
191189
| `--url-configs` | Link to documentation about the ESLint configurations exported by the plugin. |
192190

@@ -217,16 +215,6 @@ If you have a build step for your code like [Babel](https://babeljs.io/) or [Typ
217215
}
218216
```
219217

220-
### markdownlint
221-
222-
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):
223-
224-
```json
225-
{
226-
"no-inline-html": { "allowed_elements": ["br", "sup"] }
227-
}
228-
```
229-
230218
### prettier
231219

232220
If you use [prettier](https://prettier.io/) to format your markdown, you may need to adjust your scripts to run prettier formatting after running this tool:

lib/configs.ts

+45-32
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,61 @@
11
import {
22
EMOJI_CONFIGS,
3-
EMOJI_CONFIG,
4-
EMOJI_CONFIG_WARN,
5-
EMOJI_CONFIG_OFF,
3+
EMOJI_CONFIG_ERROR,
4+
RESERVED_EMOJIS,
65
} from './emojis.js';
6+
import { SEVERITY_TYPE_TO_SET } from './types.js';
77
import type {
88
Plugin,
99
ConfigsToRules,
1010
ConfigEmojis,
11-
RuleSeverity,
1211
SEVERITY_TYPE,
1312
} from './types.js';
1413

14+
export function getConfigsThatSetARule(
15+
plugin: Plugin,
16+
configsToRules: ConfigsToRules,
17+
pluginPrefix: string,
18+
ignoreConfig: string[],
19+
severityType?: SEVERITY_TYPE
20+
) {
21+
/* istanbul ignore next -- this shouldn't happen */
22+
if (!plugin.rules) {
23+
throw new Error('Missing rules in plugin.');
24+
}
25+
const ruleNames = Object.keys(plugin.rules);
26+
return (
27+
Object.entries(configsToRules)
28+
.filter(([configName]) =>
29+
// Only consider configs that configure at least one of the plugin's rules.
30+
ruleNames.some((ruleName) =>
31+
getConfigsForRule(
32+
ruleName,
33+
configsToRules,
34+
pluginPrefix,
35+
severityType
36+
).includes(configName)
37+
)
38+
)
39+
// Filter out ignored configs.
40+
.filter(([configName]) => !ignoreConfig?.includes(configName))
41+
.map(([configName]) => configName)
42+
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
43+
);
44+
}
45+
1546
/**
1647
* Get config names that a given rule belongs to.
17-
* @param severity - Include configs that set the rule to this severity. Omit to allow any severity.
48+
* @param severityType - Include configs that set the rule to this severity. Omit to allow any severity.
1849
*/
1950
export function getConfigsForRule(
2051
ruleName: string,
2152
configsToRules: ConfigsToRules,
2253
pluginPrefix: string,
23-
severity?: Set<RuleSeverity>
54+
severityType?: SEVERITY_TYPE
2455
) {
56+
const severity = severityType
57+
? SEVERITY_TYPE_TO_SET[severityType]
58+
: undefined;
2559
const configNames: Array<keyof typeof configsToRules> = [];
2660

2761
for (const configName in configsToRules) {
@@ -75,10 +109,8 @@ export function parseConfigEmojiOptions(
75109
);
76110
}
77111

78-
if (Object.keys(plugin.configs)?.length > 1 && emoji === EMOJI_CONFIG) {
79-
throw new Error(
80-
`Cannot use the general configs emoji ${EMOJI_CONFIG} for an individual config when multiple configs are present.`
81-
);
112+
if (RESERVED_EMOJIS.includes(emoji)) {
113+
throw new Error(`Cannot specify reserved emoji ${EMOJI_CONFIG_ERROR}.`);
82114
}
83115

84116
return [{ config, emoji }];
@@ -98,29 +130,19 @@ export function parseConfigEmojiOptions(
98130
return configEmojis;
99131
}
100132

101-
function emojiWithSuperscript(emoji: string, superscriptEmoji: string) {
102-
if (emoji === superscriptEmoji) {
103-
// Avoid double emoji.
104-
return emoji;
105-
}
106-
return `${emoji}<sup>${superscriptEmoji}</sup>`;
107-
}
108-
109133
/**
110134
* Find the representation of a config to display.
111135
* @param configEmojis - known list of configs and corresponding emojis
112136
* @param configName - name of the config to find an emoji for
113137
* @param options
114-
* @param options.severity - if present, decorate the config's emoji for the given severity level
115-
* @param options.fallback - if true and no emoji is found, choose whether to fallback to a generic config emoji or a badge
138+
* @param options.fallback - if true and no emoji is found, choose whether to fallback to a badge.
116139
* @returns the string to display for the config
117140
*/
118141
export function findConfigEmoji(
119142
configEmojis: ConfigEmojis,
120143
configName: string,
121144
options?: {
122-
severity?: SEVERITY_TYPE;
123-
fallback?: 'badge' | 'emoji';
145+
fallback?: 'badge';
124146
}
125147
) {
126148
let emoji = configEmojis.find(
@@ -129,20 +151,11 @@ export function findConfigEmoji(
129151
if (!emoji) {
130152
if (options?.fallback === 'badge') {
131153
emoji = `![${configName}][]`;
132-
} else if (options?.fallback === 'emoji') {
133-
emoji = EMOJI_CONFIG;
134154
} else {
135155
// No fallback.
136156
return undefined; // eslint-disable-line unicorn/no-useless-undefined
137157
}
138158
}
139159

140-
switch (options?.severity) {
141-
case 'warn':
142-
return emojiWithSuperscript(emoji, EMOJI_CONFIG_WARN);
143-
case 'off':
144-
return emojiWithSuperscript(emoji, EMOJI_CONFIG_OFF);
145-
default:
146-
return emoji;
147-
}
160+
return emoji;
148161
}

lib/emojis.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { SEVERITY_TYPE } from './types.js';
2+
import { EMOJIS_TYPE } from './rule-type.js';
3+
14
// Default emojis for common configs.
25
const EMOJI_A11Y = '♿';
36
const EMOJI_ERROR = '❗';
47
const EMOJI_STYLE = '🎨';
58
const EMOJI_TYPESCRIPT = '⌨️';
6-
const EMOJI_WARNING = '⚠️';
9+
const EMOJI_WARNING = '🚸';
710
export const EMOJI_CONFIGS = {
811
a11y: EMOJI_A11Y,
912
accessibility: EMOJI_A11Y,
@@ -24,9 +27,16 @@ export const EMOJI_CONFIGS = {
2427
};
2528

2629
// General configs.
27-
export const EMOJI_CONFIG = '💼';
30+
export const EMOJI_CONFIG_ERROR = '💼';
2831
export const EMOJI_CONFIG_WARN = '⚠️';
2932
export const EMOJI_CONFIG_OFF = '🚫';
33+
export const EMOJI_CONFIG_FROM_SEVERITY: {
34+
[key in SEVERITY_TYPE]: string;
35+
} = {
36+
[SEVERITY_TYPE.error]: EMOJI_CONFIG_ERROR,
37+
[SEVERITY_TYPE.warn]: EMOJI_CONFIG_WARN,
38+
[SEVERITY_TYPE.off]: EMOJI_CONFIG_OFF,
39+
};
3040

3141
// Fixers.
3242
export const EMOJI_FIXABLE = '🔧';
@@ -41,3 +51,14 @@ export const EMOJI_TYPE = '🗂️';
4151

4252
// Deprecated.
4353
export const EMOJI_DEPRECATED = '❌';
54+
55+
export const RESERVED_EMOJIS = [
56+
...Object.values(EMOJI_CONFIG_FROM_SEVERITY),
57+
...Object.values(EMOJIS_TYPE),
58+
59+
EMOJI_FIXABLE,
60+
EMOJI_HAS_SUGGESTIONS,
61+
EMOJI_REQUIRES_TYPE_CHECKING,
62+
EMOJI_TYPE,
63+
EMOJI_DEPRECATED,
64+
];

0 commit comments

Comments
 (0)