@dovenv/lint
Version:
Lint configuration for dovenv
131 lines (120 loc) • 4.68 kB
text/typescript
import { CommandUtils, Config as Config$1 } from '@dovenv/core';
import * as _commitlint_load from '@commitlint/load';
import { Options } from 'publint';
import stylelint from 'stylelint';
declare const CMDS: {
readonly staged: "staged";
readonly stylelint: "stylelint";
readonly eslint: "eslint";
readonly commitlint: "commitlint";
readonly publint: "publint";
readonly custom: "custom";
};
declare class LintSuper<Opts = unknown> {
opts: Opts | undefined;
utils: CommandUtils;
constructor(opts: Opts | undefined, utils: CommandUtils);
protected transformHelpInfo(v: string): void;
}
type Load = typeof _commitlint_load.default;
type UserConfig = Exclude<Parameters<Load>[0], undefined>;
type CommitlintConfig = {
/**
* User config for commitlint.
*
* @see https://commitlint.js.org/reference/rules-configuration.html
*/
config?: UserConfig;
/**
* Enable gitmoji Config to commitlint
* this activates the `gitmoji` plugin.
*
* @default false
* @see https://www.npmjs.com/package/commitlint-config-gitmoji
*/
gitmoji?: boolean;
};
declare class CommitLint extends LintSuper<CommitlintConfig> {
#private;
run(userMsg?: string): Promise<void | undefined>;
}
type EslintConfig = {
flags?: string[];
};
declare class Eslint extends LintSuper<EslintConfig> {
#private;
run(flags?: string[]): Promise<void | undefined>;
}
type PubLintOpts = Options & {
title?: string;
};
type PubLintConfig = Record<string, PubLintOpts>;
declare class PubLint extends LintSuper<PubLintConfig> {
#private;
runOne(opts?: PubLintOpts): Promise<void>;
run(keys?: string[]): Promise<void>;
}
type LintStagedConfig = Record<string, string>;
declare class StagedLint extends LintSuper<LintStagedConfig> {
#private;
run(): Promise<void | undefined>;
}
type StylelintConfig = stylelint.LinterOptions;
declare class StyleLint extends LintSuper<StylelintConfig> {
#private;
run(files?: string[], fix?: boolean): Promise<void | undefined>;
}
type Config = {
/** Config for lint staged GIT files */
[CMDS.staged]?: LintStagedConfig;
/** Config for lint CSS/SCSS/LESS/SASS/PostCSS files */
[CMDS.stylelint]?: StylelintConfig;
/** Config for lint JS/TS/MD/JSON/YAML.. Files */
[CMDS.eslint]?: EslintConfig;
/** Config for lint commit messages */
[CMDS.commitlint]?: CommitlintConfig;
/** Config for publint */
[CMDS.publint]?: PubLintConfig;
/** Custom lint */
[CMDS.custom]?: {
[key in string]: (data: {
run: {
[CMDS.eslint]: (opts?: Eslint['opts']) => ReturnType<Eslint['run']>;
[CMDS.commitlint]: (opts?: CommitLint['opts']) => ReturnType<CommitLint['run']>;
[CMDS.stylelint]: (opts?: StyleLint['opts']) => ReturnType<StyleLint['run']>;
[CMDS.staged]: (opts?: StagedLint['opts']) => ReturnType<StagedLint['run']>;
[CMDS.publint]: (opts?: NonNullable<PubLint['opts']>[keyof PubLint['opts']]) => ReturnType<PubLint['runOne']>;
};
utils: LintSuper['utils'];
}) => Promise<unknown>;
};
};
/**
* Lint class with all lint functions.
*/
declare class Lint extends LintSuper<Config> {
#private;
eslint(flags: string[]): Promise<void | undefined>;
commitlint(userMsg?: string): Promise<void>;
stylelint(files?: string[], fix?: boolean): Promise<void>;
publint(keys?: string[]): Promise<void>;
staged(): Promise<void>;
custom(pattern?: string[]): Promise<void>;
}
/**
* Configures and returns a DovenvConfig object for linting tools.
*
* @param {Config} [conf] - Optional configuration object for linting.
* @returns {DovenvConfig} A configuration object with custom lint commands and descriptions.
*
* Provides linting commands for different file types and commit messages:
* - `staged`: Lints staged git files.
* - `stylelint`: Lints CSS/SCSS/LESS/SASS/PostCSS files with options to fix errors and specify files.
* - `eslint`: Lints JS/TS/MD/JSON/YAML files.
* - `commitlint`: Lints commit messages, either the last commit message or a specified message.
*
* Examples include linting CSS files, JS files, commit messages, and staged files.
*/
declare const lintPlugin: (conf?: Config) => Config$1;
export { CommitLint, Eslint, Lint, PubLint, StagedLint, StyleLint, lintPlugin as default, lintPlugin };
export type { Config };