Skip to content

Commit

Permalink
Default prettier trailing comma (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish authored Dec 7, 2024
1 parent 31de54b commit 66b4015
Show file tree
Hide file tree
Showing 34 changed files with 313 additions and 314 deletions.
2 changes: 1 addition & 1 deletion bin/eslint-doc-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ run(process.argv, (path, options) => generate(path, options)).catch(
console.error(error.message);
}
process.exitCode = 1;
}
},
);
3 changes: 1 addition & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default tseslint.config(
'error',
{
singleQuote: true,
trailingComma: 'es5', // TODO: remove this and use default
},
],

Expand Down Expand Up @@ -171,5 +170,5 @@ export default tseslint.config(
'coverage/**',
'test/fixtures/**',
],
}
},
);
68 changes: 34 additions & 34 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { CONFIG_FORMATS } from './config-format.js';
*/
function collect(
value: string,
previous: readonly string[]
previous: readonly string[],
): readonly string[] {
return [...previous, value];
}
Expand All @@ -31,7 +31,7 @@ function collect(
* */
function collectCSV(
value: string,
previous: readonly string[]
previous: readonly string[],
): readonly string[] {
return [...previous, ...value.split(',')];
}
Expand All @@ -42,7 +42,7 @@ function collectCSV(
* */
function collectCSVNested(
value: string,
previous: readonly (readonly string[])[]
previous: readonly (readonly string[])[],
): readonly (readonly string[])[] {
return [...previous, value.split(',')];
}
Expand Down Expand Up @@ -146,7 +146,7 @@ async function loadConfigFileOptions(): Promise<GenerateOptions> {
validate.errors
? ajv.errorsText(validate.errors, { dataVar: 'config file' })
: /* istanbul ignore next -- this shouldn't happen */
'Invalid config file'
'Invalid config file',
);
}

Expand Down Expand Up @@ -180,131 +180,131 @@ async function loadConfigFileOptions(): Promise<GenerateOptions> {
*/
export async function run(
argv: readonly string[],
cb: (path: string, options: GenerateOptions) => Promise<void>
cb: (path: string, options: GenerateOptions) => Promise<void>,
) {
const program = new Command();

// Documentation for options should be kept in sync with README.md and the JSDocs for the `GenerateOptions` type.
await program
.version(await getCurrentPackageVersion())
.addArgument(
new Argument('[path]', 'path to ESLint plugin root').default('.')
new Argument('[path]', 'path to ESLint plugin root').default('.'),
)
.option(
'--check [boolean]',
`(optional) Whether to check for and fail if there is a diff. Any diff will be displayed but no output will be written to files. Typically used during CI. (default: ${String(
OPTION_DEFAULTS[OPTION_TYPE.CHECK]
OPTION_DEFAULTS[OPTION_TYPE.CHECK],
)})`,
parseBoolean
parseBoolean,
)
.option(
'--config-emoji <config-emoji>',
'(optional) Custom emoji to use for a config. Format is `config-name,emoji`. Default emojis are provided for common configs. To use a text/image/icon badge instead of an emoji, supply the corresponding markdown as the emoji. Option can be repeated.',
collectCSVNested,
[]
[],
)
.addOption(
new Option(
'--config-format <config-format>',
`(optional) The format to use for the config name. (default: ${
OPTION_DEFAULTS[OPTION_TYPE.CONFIG_FORMAT]
})`
).choices(CONFIG_FORMATS)
})`,
).choices(CONFIG_FORMATS),
)
.option(
'--ignore-config <config>',
'(optional) Config to ignore from being displayed (often used for an `all` config) (option can be repeated).',
collect,
[]
[],
)
.option(
'--ignore-deprecated-rules [boolean]',
`(optional) Whether to ignore deprecated rules from being checked, displayed, or updated. (default: ${String(
OPTION_DEFAULTS[OPTION_TYPE.IGNORE_DEPRECATED_RULES]
OPTION_DEFAULTS[OPTION_TYPE.IGNORE_DEPRECATED_RULES],
)})`,
parseBoolean
parseBoolean,
)
.option(
'--init-rule-docs [boolean]',
`(optional) Whether to create rule doc files if they don't yet exist. (default: ${String(
OPTION_DEFAULTS[OPTION_TYPE.INIT_RULE_DOCS]
OPTION_DEFAULTS[OPTION_TYPE.INIT_RULE_DOCS],
)})`,
parseBoolean
parseBoolean,
)
.option(
'--path-rule-doc <path>',
`(optional) Path to markdown file for each rule doc. Use \`{name}\` placeholder for the rule name. To specify a function, use a JavaScript-based config file. (default: ${
OPTION_DEFAULTS[OPTION_TYPE.PATH_RULE_DOC]
})`
})`,
)
.option(
'--path-rule-list <path>',
`(optional) Path to markdown file where the rules table list should live. Option can be repeated. Defaults to ${String(
OPTION_DEFAULTS[OPTION_TYPE.PATH_RULE_LIST]
OPTION_DEFAULTS[OPTION_TYPE.PATH_RULE_LIST],
)} if not provided.`,
collect,
[]
[],
)
.option(
'--rule-doc-notices <notices>',
`(optional) Ordered, comma-separated list of notices to display in rule doc. Non-applicable notices will be hidden. (choices: "${Object.values(
NOTICE_TYPE
NOTICE_TYPE,
).join('", "')}") (default: ${String(
OPTION_DEFAULTS[OPTION_TYPE.RULE_DOC_NOTICES]
OPTION_DEFAULTS[OPTION_TYPE.RULE_DOC_NOTICES],
)})`,
collectCSV,
[]
[],
)
.option(
'--rule-doc-section-exclude <section>',
'(optional) Disallowed section in each rule doc (option can be repeated).',
collect,
[]
[],
)
.option(
'--rule-doc-section-include <section>',
'(optional) Required section in each rule doc (option can be repeated).',
collect,
[]
[],
)
.option(
'--rule-doc-section-options [boolean]',
`(optional) Whether to require an "Options" or "Config" rule doc section and mention of any named options for rules with options. (default: ${String(
OPTION_DEFAULTS[OPTION_TYPE.RULE_DOC_SECTION_OPTIONS]
OPTION_DEFAULTS[OPTION_TYPE.RULE_DOC_SECTION_OPTIONS],
)})`,
parseBoolean
parseBoolean,
)
.addOption(
new Option(
'--rule-doc-title-format <format>',
`(optional) The format to use for rule doc titles. (default: ${
OPTION_DEFAULTS[OPTION_TYPE.RULE_DOC_TITLE_FORMAT]
})`
).choices(RULE_DOC_TITLE_FORMATS)
})`,
).choices(RULE_DOC_TITLE_FORMATS),
)
.option(
'--rule-list-columns <columns>',
`(optional) Ordered, comma-separated list of columns to display in rule list. Empty columns will be hidden. (choices: "${Object.values(
COLUMN_TYPE
COLUMN_TYPE,
).join('", "')})" (default: ${String(
OPTION_DEFAULTS[OPTION_TYPE.RULE_LIST_COLUMNS]
OPTION_DEFAULTS[OPTION_TYPE.RULE_LIST_COLUMNS],
)})`,
collectCSV,
[]
[],
)
.option(
'--rule-list-split <property>',
'(optional) Rule property(s) to split the rules list by. A separate list and header will be created for each value. Example: `meta.type`. To specify a function, use a JavaScript-based config file.',
collectCSV,
[]
[],
)
.option(
'--url-configs <url>',
'(optional) Link to documentation about the ESLint configurations exported by the plugin.'
'(optional) Link to documentation about the ESLint configurations exported by the plugin.',
)
.option(
'--url-rule-doc <url>',
'(optional) 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. To specify a function, use a JavaScript-based config file.'
'(optional) 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. To specify a function, use a JavaScript-based config file.',
)
.action(async function (path: string, options: GenerateOptions) {
// Load config file options and merge with CLI options.
Expand Down
2 changes: 1 addition & 1 deletion lib/config-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type ConfigFormat = (typeof CONFIG_FORMATS)[number];
export function configNameToDisplay(
configName: string,
configFormat: ConfigFormat,
pluginPrefix: string
pluginPrefix: string,
) {
switch (configFormat) {
case 'name': {
Expand Down
12 changes: 6 additions & 6 deletions lib/config-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function generateConfigListMarkdown(
pluginPrefix: string,
configEmojis: ConfigEmojis,
configFormat: ConfigFormat,
ignoreConfig: readonly string[]
ignoreConfig: readonly string[],
): string {
/* istanbul ignore next -- configs are sure to exist at this point */
const configs = Object.values(plugin.configs || {});
Expand All @@ -60,13 +60,13 @@ function generateConfigListMarkdown(
`\`${configNameToDisplay(
configName,
configFormat,
pluginPrefix
pluginPrefix,
)}\``,
hasDescription ? description || '' : undefined,
].filter((col) => col !== undefined);
}),
]),
{ align: 'l' } // Left-align headers.
{ align: 'l' }, // Left-align headers.
);
}

Expand All @@ -77,7 +77,7 @@ export function updateConfigsList(
pluginPrefix: string,
configEmojis: ConfigEmojis,
configFormat: ConfigFormat,
ignoreConfig: readonly string[]
ignoreConfig: readonly string[],
): string {
const listStartIndex = markdown.indexOf(BEGIN_CONFIG_LIST_MARKER);
let listEndIndex = markdown.indexOf(END_CONFIG_LIST_MARKER);
Expand All @@ -89,7 +89,7 @@ export function updateConfigsList(

if (
Object.keys(configsToRules).filter(
(configName) => !ignoreConfig.includes(configName)
(configName) => !ignoreConfig.includes(configName),
).length === 0
) {
// No non-ignored configs found.
Expand All @@ -109,7 +109,7 @@ export function updateConfigsList(
pluginPrefix,
configEmojis,
configFormat,
ignoreConfig
ignoreConfig,
);

return `${preList}${BEGIN_CONFIG_LIST_MARKER}${EOL}${EOL}${list}${EOL}${EOL}${END_CONFIG_LIST_MARKER}${postList}`;
Expand Down
Loading

0 comments on commit 66b4015

Please sign in to comment.