Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type for configEmoji option #355

Merged
merged 1 commit into from Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/option-parsers.ts
Expand Up @@ -15,7 +15,10 @@ import type { Plugin, ConfigEmojis } from './types.js';
*/
export function parseConfigEmojiOptions(
plugin: Plugin,
configEmoji?: readonly (readonly string[])[]
configEmoji?: readonly (
| [configName: string, emoji: string]
| [configName: string]
)[]
): ConfigEmojis {
const configsSeen = new Set<string>();
const configsWithDefaultEmojiRemoved: string[] = [];
Expand Down
7 changes: 5 additions & 2 deletions lib/types.ts
Expand Up @@ -48,7 +48,7 @@ export interface RuleDetails {
}

/**
* Some configs may have an emoji defined.
* The emoji for each config that has one after option parsing and defaults have been applied.
*/
export type ConfigEmojis = readonly { config: string; emoji: string }[];

Expand Down Expand Up @@ -119,7 +119,10 @@ export type GenerateOptions = {
* Default emojis are provided for common configs.
* To remove a default emoji and rely on a badge instead, provide the config name without an emoji.
*/
readonly configEmoji?: readonly (readonly string[])[];
readonly configEmoji?: readonly (
| [configName: string, emoji: string]
| [configName: string]
)[];
/** Configs to ignore from being displayed. Often used for an `all` config. */
readonly ignoreConfig?: readonly string[];
/** Whether to ignore deprecated rules from being checked, displayed, or updated. Default: `false`. */
Expand Down
8 changes: 8 additions & 0 deletions test/lib/generate/option-config-emoji-test.ts
Expand Up @@ -102,10 +102,18 @@ describe('generate (--config-emoji)', function () {

it('throws an error', async function () {
await expect(
// @ts-expect-error -- testing invalid input (too many items)
generate('.', { configEmoji: [['foo', 'bar', 'baz']] })
).rejects.toThrow(
'Invalid configEmoji option: foo,bar,baz. Expected format: config,emoji'
);

await expect(
// @ts-expect-error -- testing invalid input (too few items)
generate('.', { configEmoji: [[]] })
).rejects.toThrow(
'Invalid configEmoji option: . Expected format: config,emoji'
);
});
});

Expand Down