UNPKG

@dovenv/lint

Version:
113 lines (103 loc) 4.01 kB
import { CommandUtils, Config as Config$1 } from '@dovenv/core'; import load from '@commitlint/load'; import stylelint from 'stylelint'; import * as eslintConfig from '@dovenv/eslint-config'; export { eslintConfig as dovenvEslintConfig }; import * as stylelintConfig from '@dovenv/stylelint-config'; export { stylelintConfig as dovenvStylelintConfig }; declare const CMDS: { readonly staged: "staged"; readonly stylelint: "stylelint"; readonly eslint: "eslint"; readonly commitlint: "commitlint"; 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 UserConfig = Exclude<Parameters<typeof 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 * @see https://www.npmjs.com/package/commitlint-config-gitmoji * @default false */ 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 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; [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']>; }; config: Config$1; }) => 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>; staged(): Promise<void>; custom(pattern?: string[]): Promise<void | undefined>; } /** * 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, type Config, Eslint, Lint, StagedLint, StyleLint, lintPlugin as default, lintPlugin };