From 7fd2ef848b89b75bfbf961d43fb65c96ba52a166 Mon Sep 17 00:00:00 2001 From: Ruslan Lopatin Date: Sat, 16 Sep 2023 13:38:03 +0700 Subject: [PATCH] Switch to ES2022 --- src/colors/chalk-color-options.spec.ts | 5 ++++- src/help/help-config.ts | 5 +++-- src/option-location.spec.ts | 2 +- src/option-syntax.spec.ts | 4 ++-- src/option-syntax.ts | 15 ++++++++------- src/options-parser.impl.ts | 8 +++++++- src/simple-options-parser.ts | 26 ++++++++++++-------------- src/supported-options.ts | 12 ++++++------ 8 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/colors/chalk-color-options.spec.ts b/src/colors/chalk-color-options.spec.ts index 55f38ce..7b29728 100644 --- a/src/colors/chalk-color-options.spec.ts +++ b/src/colors/chalk-color-options.spec.ts @@ -7,6 +7,7 @@ import { helpZOptionReader } from '../help/help-option-reader.js'; import { ZOptionError } from '../option-error.js'; import type { ZOption } from '../option.js'; import { SimpleZOptionsParser, simpleZOptionsParser } from '../simple-options-parser.js'; +import { SupportedZOptions } from '../supported-options.js'; import { type ChalkZColorConfig } from './chalk-color-config.js'; import { chalkZColorOptions } from './chalk-color-options.js'; @@ -116,7 +117,9 @@ describe('chalkZColorOptions', () => { }); it('has help', async () => { - const options = [...asArray(chalkZColorOptions())]; + const options = [ + ...asArray(chalkZColorOptions()), + ]; const display: MockedFunction<(...args: unknown[]) => void> = jest.fn(noop); options.push({ diff --git a/src/help/help-config.ts b/src/help/help-config.ts index 9ae4df3..9ed5e0b 100644 --- a/src/help/help-config.ts +++ b/src/help/help-config.ts @@ -1,5 +1,5 @@ -import type { ZOption } from '../option.js'; import type { ZOptionMeta } from '../option-meta.js'; +import type { ZOption } from '../option.js'; /** * Configuration for {@link helpZOptionReader help option reader}. @@ -22,7 +22,8 @@ export interface ZHelpConfig { /** * Compares two options meta. * - * By default sorts options by their {@link ZOptionMeta.group group} first, and then - by their keys. + * By default sorts options by their {@link @run-z/optionz!ZOptionMeta.Help#group group} first, and then - by their + * keys. * * @param key1 - First option key. * @param meta1 - First option meta. diff --git a/src/option-location.spec.ts b/src/option-location.spec.ts index da38100..5248fab 100644 --- a/src/option-location.spec.ts +++ b/src/option-location.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from '@jest/globals'; -import { ZOptionLocation } from './option-location'; +import { ZOptionLocation } from './option-location.js'; describe('ZOptionLocation', () => { describe('by', () => { diff --git a/src/option-syntax.spec.ts b/src/option-syntax.spec.ts index 4ad0132..2c23fb7 100644 --- a/src/option-syntax.spec.ts +++ b/src/option-syntax.spec.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from '@jest/globals'; -import type { ZOptionInput } from './option-input'; -import { ZOptionSyntax } from './option-syntax'; +import type { ZOptionInput } from './option-input.js'; +import { ZOptionSyntax } from './option-syntax.js'; describe('ZOptionSyntax', () => { describe('by', () => { diff --git a/src/option-syntax.ts b/src/option-syntax.ts index 701c387..d41b0e3 100644 --- a/src/option-syntax.ts +++ b/src/option-syntax.ts @@ -8,14 +8,15 @@ import { ZOptionInput } from './option-input.js'; * to be recognized by {@link ZOptionReader option readers}. * * A syntax should be {@link ZOptionsParser.Config.syntax registered} for options parser to respect it. + * + * @param args - An array of command line arguments to process. + * + * @returns A read-only array of option inputs. May be empty if the command line argument has another syntax. */ -export type ZOptionSyntax = - /** - * @param args - An array of command line arguments to process. - * - * @returns A read-only array of option inputs. May be empty if the command line argument has another syntax. - */ - (this: void, args: readonly [string, ...string[]]) => readonly ZOptionInput[]; +export type ZOptionSyntax = ( + this: void, + args: readonly [string, ...string[]], +) => readonly ZOptionInput[]; /** * @internal diff --git a/src/options-parser.impl.ts b/src/options-parser.impl.ts index 17d6dde..9ccf068 100644 --- a/src/options-parser.impl.ts +++ b/src/options-parser.impl.ts @@ -77,7 +77,13 @@ export class ZOptionsParser$ { ): Promise { const allOptions = supportedZOptionsMap( context, - asArray(this.#config.options).concat(asArray(options)), + asArray | SupportedZOptions.Provider>( + this.#config.options, + ).concat( + asArray | SupportedZOptions.Provider>( + options, + ), + ), ); const optionMeta = lazyValue(() => supportedZOptionsMeta(allOptions)); const optionClass = this.optionClass; diff --git a/src/simple-options-parser.ts b/src/simple-options-parser.ts index b4def63..787b610 100644 --- a/src/simple-options-parser.ts +++ b/src/simple-options-parser.ts @@ -1,24 +1,22 @@ -import type { ZOption } from './option.js'; import type { ZOptionSyntax } from './option-syntax.js'; +import type { ZOption } from './option.js'; import { customZOptionsParser, ZOptionsParser } from './options-parser.js'; import type { SupportedZOptions } from './supported-options.js'; /** * Simple command line options parser signature. + * + * @param args - Array of command line arguments + * @param fromIndex - An index of command line argument to start processing from. + * @param opts - Parser options. + * + * @returns A promise resolved to parse result. */ -export type SimpleZOptionsParser = - /** - * @param args - Array of command line arguments - * @param fromIndex - An index of command line argument to start processing from. - * @param opts - Parser options. - * - * @returns A promise resolved to parse result. - */ - ( - this: void, - args: readonly string[], - opts?: ZOptionsParser.Opts, - ) => Promise; +export type SimpleZOptionsParser = ( + this: void, + args: readonly string[], + opts?: ZOptionsParser.Opts, +) => Promise; export namespace SimpleZOptionsParser { /** diff --git a/src/supported-options.ts b/src/supported-options.ts index 16f74d7..2880511 100644 --- a/src/supported-options.ts +++ b/src/supported-options.ts @@ -33,36 +33,36 @@ export namespace SupportedZOptions { /** * Fallback option reader consulted when none of the readers recognized the option in. - * {@link ZOptionSyntax.longOptions `--name=VALUE` syntax}. + * {@link ZOptionSyntax:var#longOptions `--name=VALUE` syntax}. */ readonly '--*=*'?: ZOptionReader | undefined; /** * Fallback option reader consulted when none of the readers recognized the option in - * {@link ZOptionSyntax.longOptions long syntax}. + * {@link ZOptionSyntax:var#longOptions long syntax}. */ readonly '--*'?: ZOptionReader | undefined; /** * Fallback option reader consulted when none of the readers recognized the option in - * {@link ZOptionSyntax.shortOptions one-letter syntax}. + * {@link ZOptionSyntax:var#shortOptions one-letter syntax}. */ readonly '-?'?: ZOptionReader | undefined; /** * Fallback option reader consulted when none of the readers recognized the option in - * {@link ZOptionSyntax.shortOptions `-name=VALUE` syntax}. + * {@link ZOptionSyntax:var#shortOptions `-name=VALUE` syntax}. */ readonly '-*=*'?: ZOptionReader | undefined; /** * Fallback option reader consulted when none of the readers recognized the option in - * {@link ZOptionSyntax.shortOptions short syntax}. + * {@link ZOptionSyntax:var#shortOptions short syntax}. */ readonly '-*'?: ZOptionReader | undefined; /** - * Fallback option reader consulted when none of the readers the option in {@link ZOptionSyntax.any any syntax}. + * Fallback option reader consulted when none of the readers the option in {@link ZOptionSyntax:var#any any syntax}. */ readonly '*'?: ZOptionReader | undefined; }