0
# Main Linting Interface
1
2
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.
3
4
## Capabilities
5
6
### Default Export Function
7
8
The main linting function that intelligently runs ESLint and/or Stylelint based on provided arguments.
9
10
```typescript { .api }
11
/**
12
* Main linting function that runs ESLint and/or Stylelint based on provided arguments
13
* Automatically excludes inappropriate file types for each linter
14
* @param opts - Linter configuration options including working directory
15
* @param args - Linting command-line arguments and control flags
16
*/
17
export default function lint(opts: ILinterOpts, args: ILintArgs): void;
18
```
19
20
**Behavior:**
21
- Runs both ESLint and Stylelint by default
22
- Automatically excludes JavaScript/TypeScript files from Stylelint (unless `cssinjs` is true)
23
- Automatically excludes CSS/style files from ESLint
24
- Respects `eslintOnly` and `stylelintOnly` flags for selective execution
25
- Manages child process exit codes properly
26
27
**Usage Examples:**
28
29
```typescript
30
import lint from "@umijs/lint";
31
import type { ILintArgs, ILinterOpts } from "@umijs/lint";
32
33
// Basic usage - lint all files with both linters
34
lint(
35
{ cwd: process.cwd() },
36
{ _: ["src/**/*"] }
37
);
38
39
// Lint with auto-fix enabled
40
lint(
41
{ cwd: process.cwd() },
42
{
43
_: ["src/**/*"],
44
fix: true,
45
quiet: true
46
}
47
);
48
49
// Lint only TypeScript files with ESLint
50
lint(
51
{ cwd: process.cwd() },
52
{
53
_: ["src/**/*.{ts,tsx}"],
54
eslintOnly: true
55
}
56
);
57
58
// Lint CSS files including CSS-in-JS
59
lint(
60
{ cwd: process.cwd() },
61
{
62
_: ["src/**/*.{css,less,tsx}"],
63
stylelintOnly: true,
64
cssinjs: true
65
}
66
);
67
```
68
69
### Intelligent File Filtering
70
71
The main function implements smart file filtering to prevent cross-linting:
72
73
**For Stylelint:**
74
- When `cssinjs` is false (default): Excludes all JavaScript/TypeScript files
75
- When `cssinjs` is true: Allows JavaScript/TypeScript files for CSS-in-JS linting
76
- Always includes CSS, Less, Sass, SCSS, and Stylus files
77
78
**For ESLint:**
79
- Always excludes CSS/style files to prevent parsing errors
80
- Includes JavaScript, JSX, TypeScript, and TSX files
81
82
**Error Handling:**
83
- Child process exit codes are properly propagated
84
- Linter binary resolution failures throw descriptive errors
85
- Process execution errors are handled gracefully
86
87
## Types
88
89
```typescript { .api }
90
interface ILinterOpts {
91
/** Current working directory for linting operations */
92
cwd: string;
93
}
94
95
interface ILintArgs {
96
/** Array of file patterns/paths to lint */
97
_: string[];
98
/** Optional flag to suppress non-error output */
99
quiet?: boolean;
100
/** Optional flag to automatically fix linting issues */
101
fix?: boolean;
102
/** Optional flag to run only ESLint (skip Stylelint) */
103
eslintOnly?: boolean;
104
/** Optional flag to run only Stylelint (skip ESLint) */
105
stylelintOnly?: boolean;
106
/** Optional flag to enable CSS-in-JS linting for Stylelint */
107
cssinjs?: boolean;
108
}
109
```