Skip to content

Commit

Permalink
fix: improve type for configEmoji
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Dec 18, 2022
1 parent c495ca5 commit 6470744
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
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

0 comments on commit 6470744

Please sign in to comment.