UNPKG

@kcws/lintstaged-config

Version:
294 lines (265 loc) 7.45 kB
/** * A programming config for lintstaged. * * @packageDocumentation */ /** * Action type, every action should implement this type. * * @public */ export declare type BaseActionFn<O extends IBaseActionOptions> = (options?: O) => string; /** * Config builder. This class should not be created manually. * Use {@link Config.builder} or {@link Config.default} instead. * * @public */ export declare class Builder<K extends string> implements IConfigBuilder { private _result; private _settings; /** * Do not use this constructor directly. * Use {@link Config.builder} or {@link Config.default} instead. */ constructor(); /** * enable debug mode when loading configuration * * @returns this object * * @public */ debugMode(): this; /** * append default actions to current builder * * @returns this object * * @public */ default(custom?: CustomDefaultConfig): Builder<K | DefaultKey>; /** * append value to list of regex or actions if needed. * If input key never created yet, * it will create with input value * * @param key - group key * @param value - config value associate with input key * @returns this object * * @public */ append<EK extends string>(key: EK, value: Partial<Exclude<IConfigValue, "actionFn">>): Builder<K | EK>; /** * add new config group to current configuration * * @param key - group key * @param value - config value associate with input key * @returns this object * * @public */ set<EK extends string>(key: EK, value: Partial<IConfigValue>): Builder<K | EK>; /** * build Config with current builder * * @returns this object * * @public */ build(): Config<K>; /** * delete group by key * * @param key - group key * @returns this object * * @public */ delete<EK extends K>(key: EK): Builder<Exclude<K, EK>>; private _fillValue; private _mergeValue; } /** * All possible command type on lintstaged configuration. * * @public */ export declare type CommandType = string | Array<string> | Promise<string | Array<string>> | Array<Promise<string | Array<string>>>; /** * Configuration object to generate list of command * needed for specify values on {@link ConfigCondition} * * @public */ export declare class Config<K extends string> implements IConfigBuilder, IConfig { /** * create config builder with empty value. * * @returns config builder * * @public */ static builder<K extends string = "">(): Builder<K>; /** * create config builder with default group predefined. * * @returns config builder */ static default(): Builder<DefaultKey>; private _config; private _settings; constructor(config: Map<K, IConfigValue>, settings: Map<string, string>); /** * length of configuration. * * @remarks * This can be check to ensure * we setting config object correctly * * @public */ get length(): number; /** * is debug mode enabled? */ private get _isDebug(); /** * {@inheritDoc IConfig.getCommands} * @override */ getCommands(condition: ConfigCondition): Promise<Array<string>>; /** * Empty implementation as Config already IConfig, * so we can just return itself. * * @returns this object * @override * * @public */ build(): this; /* Excluded from this release type: compare */ private _resolveAction; } /** * Condition to getCommand from config * * @public */ export declare type ConfigCondition = ( /** each action will have key correspond to action function */ key: string, /** files regex for execute specific action */ regex: Array<string>) => Array<string>; /** * Function that we use to export from lint-staged config file * * @public */ export declare type ConfigFn = (filenames: Array<string>) => CommandType; /* Excluded from this release type: CustomDefaultConfig */ /* Excluded from this release type: DEFAULT_YAMLLINT_CONFIGS */ /** * Default possible key * * @public */ export declare type DefaultKey = "jsts" | "json" | "sh" | "yaml"; /* Excluded from this release type: defineConfig */ /* Excluded from this release type: eslint */ /* Excluded from this release type: generic */ /** * Base action options, every action option should implement this type. * * @public */ export declare interface IBaseActionOptions { /** * list of files changed * @readonly */ files?: Array<string>; } /** * A lintstaged configuration * * @public */ export declare interface IConfig { /** * select series of command needed to execute based on input condition * * @remarks * * we will select all static and dynamic actions from * any config group that regex return non-empty array. * and execute action to get command and merge them together. * * @param condition - condition to select specify config values * @returns commands to execute on terminal * * @public */ getCommands(condition: ConfigCondition): Promise<Array<string>>; } /** * A configuration builder for lintstaged. * * @public */ export declare interface IConfigBuilder { /** * Build configuration object. */ build(): IConfig; } /** * All possible values contains in configuration mapper. * * @public */ export declare interface IConfigValue { /** * Regular Expression for matching staged files * * @remarks * This values will be passed to * {@link https://github.com/micromatch/micromatch | micromatch} to apply. */ regexs: Array<string>; /** * Action after staged file matched with regex values. * * @remarks * This values will execute as static command * without any matched files name, * if you would like to include staged file in the command. * Please use {@link IConfigValue.actionFn} instead. * You can specify both values. */ actions: CommandType; /** * Function execute with matched regex values. * * @remarks * This function will include staged files matched with provide regex, * if you would like to run simple command(s). * Please use {@link IConfigValue.actions} instead. * You can specify both values. */ actionFn: ConfigFn; } /* Excluded from this release type: IEslintOptions */ /* Excluded from this release type: IPrettierOptions */ /* Excluded from this release type: IShellcheckOptions */ /* Excluded from this release type: IYamllintOptions */ /* Excluded from this release type: OnlyAppOptions */ /* Excluded from this release type: prettier */ /* Excluded from this release type: rush */ /* Excluded from this release type: rushOn */ /* Excluded from this release type: shellcheck */ /* Excluded from this release type: _WalkCallback */ /* Excluded from this release type: yamllint */ export { }