Skip to content

Commit 888ae3c

Browse files
authored
Rename --split-by option to --rule-list-split (#301)
1 parent aa0b21c commit 888ae3c

File tree

10 files changed

+69
-55
lines changed

10 files changed

+69
-55
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ There's also an optional path argument if you need to point the CLI to an ESLint
133133
| `--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`. |
134134
| `--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). |
135135
| `--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`, `fixableAndHasSuggestions` (off by default), `hasSuggestions`, `name`, `options` (off by default), `requiresTypeChecking`, `type` (off by default). Default: `name,description,configsError,configsWarn,configsOff,fixable,hasSuggestions,requiresTypeChecking,deprecated`. |
136-
| `--split-by` | Rule property to split the rules list by. A separate list and header will be created for each value. Example: `meta.type`. |
136+
| `--rule-list-split` | Rule property to split the rules list by. A separate list and header will be created for each value. Example: `meta.type`. |
137137
| `--url-configs` | Link to documentation about the ESLint configurations exported by the plugin. |
138138
| `--url-rule-doc` | Link to documentation for each rule. Useful when it differs from the rule doc path on disk (e.g. custom documentation site in use). Use `{name}` placeholder for the rule name. |
139139

lib/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async function loadConfigFileOptions(): Promise<GenerateOptions> {
9494
ruleDocSectionOptions: { type: 'boolean' },
9595
ruleDocTitleFormat: { type: 'string' },
9696
ruleListColumns: schemaStringArray,
97-
splitBy: { type: 'string' },
97+
ruleListSplit: { type: 'string' },
9898
urlConfigs: { type: 'string' },
9999
urlRuleDoc: { type: 'string' },
100100
};
@@ -241,7 +241,7 @@ export async function run(
241241
[]
242242
)
243243
.option(
244-
'--split-by <property>',
244+
'--rule-list-split <property>',
245245
'(optional) Rule property to split the rules list by. A separate list and header will be created for each value. Example: `meta.type`.'
246246
)
247247
.option(

lib/generator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ export async function generate(path: string, options?: GenerateOptions) {
137137
options?.ruleDocTitleFormat ??
138138
OPTION_DEFAULTS[OPTION_TYPE.RULE_DOC_TITLE_FORMAT];
139139
const ruleListColumns = parseRuleListColumnsOption(options?.ruleListColumns);
140-
const splitBy = options?.splitBy ?? OPTION_DEFAULTS[OPTION_TYPE.SPLIT_BY];
140+
const ruleListSplit =
141+
options?.ruleListSplit ?? OPTION_DEFAULTS[OPTION_TYPE.RULE_LIST_SPLIT];
141142
const urlConfigs =
142143
options?.urlConfigs ?? OPTION_DEFAULTS[OPTION_TYPE.URL_CONFIGS];
143144
const urlRuleDoc =
@@ -291,9 +292,9 @@ export async function generate(path: string, options?: GenerateOptions) {
291292
configEmojis,
292293
ignoreConfig,
293294
ruleListColumns,
295+
ruleListSplit,
294296
urlConfigs,
295-
urlRuleDoc,
296-
splitBy
297+
urlRuleDoc
297298
),
298299
resolve(pathToFile)
299300
);

lib/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const OPTION_DEFAULTS = {
6262
)
6363
.filter(([_col, enabled]) => enabled)
6464
.map(([col]) => col),
65-
[OPTION_TYPE.SPLIT_BY]: undefined,
65+
[OPTION_TYPE.RULE_LIST_SPLIT]: undefined,
6666
[OPTION_TYPE.URL_CONFIGS]: undefined,
6767
[OPTION_TYPE.URL_RULE_DOC]: undefined,
6868
} satisfies Record<OPTION_TYPE, unknown>; // Satisfies is used to ensure all options are included, but without losing type information.

lib/rule-list.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ function generateRulesListMarkdown(
213213
}
214214

215215
/**
216-
* Generate multiple rule lists given the `splitBy` property.
216+
* Generate multiple rule lists given the `ruleListSplit` property.
217217
*/
218-
function generateRulesListMarkdownWithSplitBy(
218+
function generateRulesListMarkdownWithRuleListSplit(
219219
columns: Record<COLUMN_TYPE, boolean>,
220220
details: RuleDetails[],
221221
plugin: Plugin,
@@ -226,12 +226,14 @@ function generateRulesListMarkdownWithSplitBy(
226226
pathRuleList: string,
227227
configEmojis: ConfigEmojis,
228228
ignoreConfig: string[],
229-
splitBy: string,
229+
ruleListSplit: string,
230230
headerLevel: number,
231231
urlRuleDoc?: string
232232
): string {
233233
const values = new Set(
234-
details.map((detail) => getPropertyFromRule(plugin, detail.name, splitBy))
234+
details.map((detail) =>
235+
getPropertyFromRule(plugin, detail.name, ruleListSplit)
236+
)
235237
);
236238

237239
// Common values for boolean properties.
@@ -247,15 +249,19 @@ function generateRulesListMarkdownWithSplitBy(
247249
]);
248250

249251
if (values.size === 1 && DISABLED_VALUES.has([...values.values()][0])) {
250-
throw new Error(`No rules found with --split-by property "${splitBy}".`);
252+
throw new Error(
253+
`No rules found with --rule-list-split property "${ruleListSplit}".`
254+
);
251255
}
252256

253257
const parts: string[] = [];
254258

255-
// Show any rules that don't have a value for this split-by property first, or for which the boolean property is off.
259+
// Show any rules that don't have a value for this rule-list-split property first, or for which the boolean property is off.
256260
if ([...DISABLED_VALUES.values()].some((val) => values.has(val))) {
257261
const rulesForThisValue = details.filter((detail) =>
258-
DISABLED_VALUES.has(getPropertyFromRule(plugin, detail.name, splitBy))
262+
DISABLED_VALUES.has(
263+
getPropertyFromRule(plugin, detail.name, ruleListSplit)
264+
)
259265
);
260266
parts.push(
261267
generateRulesListMarkdown(
@@ -278,21 +284,25 @@ function generateRulesListMarkdownWithSplitBy(
278284
.filter((value) => !DISABLED_VALUES.has(value))
279285
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))) {
280286
const rulesForThisValue = details.filter(
281-
(detail) => getPropertyFromRule(plugin, detail.name, splitBy) === value
287+
(detail) =>
288+
getPropertyFromRule(plugin, detail.name, ruleListSplit) === value
282289
);
283290

284-
// Turn splitBy into a title.
291+
// Turn ruleListSplit into a title.
285292
// E.g. meta.docs.requiresTypeChecking to "Requires Type Checking".
286293
// TODO: handle other types of variable casing.
287-
const splitByParts = splitBy.split('.');
288-
const splitByFinalPart = splitByParts[splitByParts.length - 1];
289-
const splitByTitle = isCamelCase(splitByFinalPart)
290-
? camelCaseStringToTitle(splitByParts[splitByParts.length - 1])
291-
: splitByFinalPart;
294+
const ruleListSplitParts = ruleListSplit.split('.');
295+
const ruleListSplitFinalPart =
296+
ruleListSplitParts[ruleListSplitParts.length - 1];
297+
const ruleListSplitTitle = isCamelCase(ruleListSplitFinalPart)
298+
? camelCaseStringToTitle(
299+
ruleListSplitParts[ruleListSplitParts.length - 1]
300+
)
301+
: ruleListSplitFinalPart;
292302

293303
parts.push(
294304
`${'#'.repeat(headerLevel)} ${
295-
ENABLED_VALUES.has(value) ? splitByTitle : value
305+
ENABLED_VALUES.has(value) ? ruleListSplitTitle : value
296306
}`,
297307
generateRulesListMarkdown(
298308
columns,
@@ -324,9 +334,9 @@ export function updateRulesList(
324334
configEmojis: ConfigEmojis,
325335
ignoreConfig: string[],
326336
ruleListColumns: COLUMN_TYPE[],
337+
ruleListSplit?: string,
327338
urlConfigs?: string,
328-
urlRuleDoc?: string,
329-
splitBy?: string
339+
urlRuleDoc?: string
330340
): string {
331341
let listStartIndex = markdown.indexOf(BEGIN_RULE_LIST_MARKER);
332342
let listEndIndex = markdown.indexOf(END_RULE_LIST_MARKER);
@@ -365,7 +375,7 @@ export function updateRulesList(
365375

366376
// Determine what header level to use for sub-lists based on the last seen header level.
367377
const preListFinalHeaderLevel = findFinalHeaderLevel(preList);
368-
const splitByHeaderLevel = preListFinalHeaderLevel
378+
const ruleListSplitHeaderLevel = preListFinalHeaderLevel
369379
? preListFinalHeaderLevel + 1
370380
: 1;
371381

@@ -391,8 +401,8 @@ export function updateRulesList(
391401
);
392402

393403
// New rule list.
394-
const list = splitBy
395-
? generateRulesListMarkdownWithSplitBy(
404+
const list = ruleListSplit
405+
? generateRulesListMarkdownWithRuleListSplit(
396406
columns,
397407
details,
398408
plugin,
@@ -403,8 +413,8 @@ export function updateRulesList(
403413
pathRuleList,
404414
configEmojis,
405415
ignoreConfig,
406-
splitBy,
407-
splitByHeaderLevel,
416+
ruleListSplit,
417+
ruleListSplitHeaderLevel,
408418
urlRuleDoc
409419
)
410420
: generateRulesListMarkdown(

lib/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export enum OPTION_TYPE {
9898
RULE_DOC_SECTION_OPTIONS = 'ruleDocSectionOptions',
9999
RULE_DOC_TITLE_FORMAT = 'ruleDocTitleFormat',
100100
RULE_LIST_COLUMNS = 'ruleListColumns',
101-
SPLIT_BY = 'splitBy',
101+
RULE_LIST_SPLIT = 'ruleListSplit',
102102
URL_CONFIGS = 'urlConfigs',
103103
URL_RULE_DOC = 'urlRuleDoc',
104104
}
@@ -161,7 +161,7 @@ export type GenerateOptions = {
161161
* A separate list and header will be created for each value.
162162
* Example: `meta.type`.
163163
*/
164-
splitBy?: string;
164+
ruleListSplit?: string;
165165
/** Link to documentation about the ESLint configurations exported by the plugin. */
166166
urlConfigs?: string;
167167
/**

test/lib/__snapshots__/cli-test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ exports[`cli all CLI options and all config files options merges correctly, with
5151
"hasSuggestions",
5252
"type",
5353
],
54-
"splitBy": "meta.docs.foo-from-cli",
54+
"ruleListSplit": "meta.docs.foo-from-cli",
5555
"urlConfigs": "https://example.com/configs-url-from-cli",
5656
"urlRuleDoc": "https://example.com/rule-doc-url-from-cli",
5757
},
@@ -95,7 +95,7 @@ exports[`cli all CLI options, no config file options is called correctly 1`] = `
9595
"ruleListColumns": [
9696
"type",
9797
],
98-
"splitBy": "meta.docs.foo-from-cli",
98+
"ruleListSplit": "meta.docs.foo-from-cli",
9999
"urlConfigs": "https://example.com/configs-url-from-cli",
100100
"urlRuleDoc": "https://example.com/rule-doc-url-from-cli",
101101
},
@@ -140,7 +140,7 @@ exports[`cli all config files options, no CLI options is called correctly 1`] =
140140
"fixable",
141141
"hasSuggestions",
142142
],
143-
"splitBy": "meta.docs.foo-from-config-file",
143+
"ruleListSplit": "meta.docs.foo-from-config-file",
144144
"urlConfigs": "https://example.com/configs-url-from-config-file",
145145
"urlRuleDoc": "https://example.com/rule-doc-url-from-config-file",
146146
},

test/lib/cli-test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const configFileOptionsAll: { [key in OPTION_TYPE]: unknown } = {
2727
ruleDocSectionOptions: false,
2828
ruleDocTitleFormat: 'desc',
2929
ruleListColumns: ['fixable', 'hasSuggestions'],
30-
splitBy: 'meta.docs.foo-from-config-file',
30+
ruleListSplit: 'meta.docs.foo-from-config-file',
3131
urlConfigs: 'https://example.com/configs-url-from-config-file',
3232
urlRuleDoc: 'https://example.com/rule-doc-url-from-config-file',
3333
};
@@ -85,7 +85,10 @@ const cliOptionsAll: { [key in OPTION_TYPE]: string[] } = {
8585

8686
[OPTION_TYPE.RULE_LIST_COLUMNS]: ['--rule-list-columns', 'type'],
8787

88-
[OPTION_TYPE.SPLIT_BY]: ['--split-by', 'meta.docs.foo-from-cli'],
88+
[OPTION_TYPE.RULE_LIST_SPLIT]: [
89+
'--rule-list-split',
90+
'meta.docs.foo-from-cli',
91+
],
8992

9093
[OPTION_TYPE.URL_CONFIGS]: [
9194
'--url-configs',

test/lib/generate/__snapshots__/option-rule-list-split-by-test.ts.snap renamed to test/lib/generate/__snapshots__/option-rule-list-split-test.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`generate (--split-by) by nested property meta.docs.category splits the list 1`] = `
3+
exports[`generate (--rule-list-split) by nested property meta.docs.category splits the list 1`] = `
44
"## Rules
55
<!-- begin auto-generated rules list -->
66
@@ -24,7 +24,7 @@ exports[`generate (--split-by) by nested property meta.docs.category splits the
2424
"
2525
`;
2626

27-
exports[`generate (--split-by) by type splits the list 1`] = `
27+
exports[`generate (--rule-list-split) by type splits the list 1`] = `
2828
"## Rules
2929
<!-- begin auto-generated rules list -->
3030
@@ -49,7 +49,7 @@ exports[`generate (--split-by) by type splits the list 1`] = `
4949
"
5050
`;
5151

52-
exports[`generate (--split-by) ignores case splits the list 1`] = `
52+
exports[`generate (--rule-list-split) ignores case splits the list 1`] = `
5353
"## Rules
5454
<!-- begin auto-generated rules list -->
5555
@@ -75,7 +75,7 @@ exports[`generate (--split-by) ignores case splits the list 1`] = `
7575
"
7676
`;
7777

78-
exports[`generate (--split-by) with boolean splits the list 1`] = `
78+
exports[`generate (--rule-list-split) with boolean splits the list 1`] = `
7979
"## Rules
8080
<!-- begin auto-generated rules list -->
8181
@@ -96,7 +96,7 @@ exports[`generate (--split-by) with boolean splits the list 1`] = `
9696
"
9797
`;
9898

99-
exports[`generate (--split-by) with no existing headers in file uses the proper sub-list header level 1`] = `
99+
exports[`generate (--rule-list-split) with no existing headers in file uses the proper sub-list header level 1`] = `
100100
"<!-- begin auto-generated rules list -->
101101
102102
| Name |
@@ -118,7 +118,7 @@ exports[`generate (--split-by) with no existing headers in file uses the proper
118118
<!-- end auto-generated rules list -->"
119119
`;
120120

121-
exports[`generate (--split-by) with one sub-list having no rules enabled by the config splits the list and still uses recommended config emoji in both lists 1`] = `
121+
exports[`generate (--rule-list-split) with one sub-list having no rules enabled by the config splits the list and still uses recommended config emoji in both lists 1`] = `
122122
"## Rules
123123
<!-- begin auto-generated rules list -->
124124
@@ -141,7 +141,7 @@ exports[`generate (--split-by) with one sub-list having no rules enabled by the
141141
"
142142
`;
143143

144-
exports[`generate (--split-by) with only a title in the rules file uses the proper sub-list header level 1`] = `
144+
exports[`generate (--rule-list-split) with only a title in the rules file uses the proper sub-list header level 1`] = `
145145
"# Rules
146146
<!-- begin auto-generated rules list -->
147147
@@ -164,7 +164,7 @@ exports[`generate (--split-by) with only a title in the rules file uses the prop
164164
<!-- end auto-generated rules list -->"
165165
`;
166166

167-
exports[`generate (--split-by) with unknown variable type splits the list but does not attempt to convert variable name to title 1`] = `
167+
exports[`generate (--rule-list-split) with unknown variable type splits the list but does not attempt to convert variable name to title 1`] = `
168168
"## Rules
169169
<!-- begin auto-generated rules list -->
170170

0 commit comments

Comments
 (0)