Comprehensive linting solution for JavaScript and TypeScript projects combining ESLint and Stylelint with unified interface
—
The primary interface for running linters with automatic file filtering and dual-linter coordination. This function serves as the main entry point that orchestrates both ESLint and Stylelint execution.
The main linting function that intelligently runs ESLint and/or Stylelint based on provided arguments.
/**
* Main linting function that runs ESLint and/or Stylelint based on provided arguments
* Automatically excludes inappropriate file types for each linter
* @param opts - Linter configuration options including working directory
* @param args - Linting command-line arguments and control flags
*/
export default function lint(opts: ILinterOpts, args: ILintArgs): void;Behavior:
cssinjs is true)eslintOnly and stylelintOnly flags for selective executionUsage Examples:
import lint from "@umijs/lint";
import type { ILintArgs, ILinterOpts } from "@umijs/lint";
// Basic usage - lint all files with both linters
lint(
{ cwd: process.cwd() },
{ _: ["src/**/*"] }
);
// Lint with auto-fix enabled
lint(
{ cwd: process.cwd() },
{
_: ["src/**/*"],
fix: true,
quiet: true
}
);
// Lint only TypeScript files with ESLint
lint(
{ cwd: process.cwd() },
{
_: ["src/**/*.{ts,tsx}"],
eslintOnly: true
}
);
// Lint CSS files including CSS-in-JS
lint(
{ cwd: process.cwd() },
{
_: ["src/**/*.{css,less,tsx}"],
stylelintOnly: true,
cssinjs: true
}
);The main function implements smart file filtering to prevent cross-linting:
For Stylelint:
cssinjs is false (default): Excludes all JavaScript/TypeScript filescssinjs is true: Allows JavaScript/TypeScript files for CSS-in-JS lintingFor ESLint:
Error Handling:
interface ILinterOpts {
/** Current working directory for linting operations */
cwd: string;
}
interface ILintArgs {
/** Array of file patterns/paths to lint */
_: string[];
/** Optional flag to suppress non-error output */
quiet?: boolean;
/** Optional flag to automatically fix linting issues */
fix?: boolean;
/** Optional flag to run only ESLint (skip Stylelint) */
eslintOnly?: boolean;
/** Optional flag to run only Stylelint (skip ESLint) */
stylelintOnly?: boolean;
/** Optional flag to enable CSS-in-JS linting for Stylelint */
cssinjs?: boolean;
}Install with Tessl CLI
npx tessl i tessl/npm-umijs--lint