@@ -5,23 +5,65 @@ import { resolve, join } from 'path'
5
5
import chalk from 'chalk'
6
6
7
7
import { cliCommand } from '../bin/next'
8
+ import { ESLINT_DEFAULT_DIRS } from '../lib/constants'
8
9
import { runLintCheck } from '../lib/eslint/runLintCheck'
9
10
import { printAndExit } from '../server/lib/utils'
10
11
12
+ const eslintOptions = ( args : arg . Spec ) => ( {
13
+ overrideConfigFile : args [ '--config' ] || null ,
14
+ extensions : args [ '--ext' ] ?? [ '.js' , '.jsx' , '.ts' , '.tsx' ] ,
15
+ resolvePluginsRelativeTo : args [ '--resolve-plugins-relative-to' ] || null ,
16
+ rulePaths : args [ '--rulesdir' ] ?? [ ] ,
17
+ fix : args [ '--fix' ] ?? false ,
18
+ fixTypes : args [ '--fix-type' ] ?? null ,
19
+ ignorePath : args [ '--ignore-path' ] || null ,
20
+ ignore : ! Boolean ( args [ '--no-ignore' ] ) ,
21
+ allowInlineConfig : ! Boolean ( args [ '--no-inline-config' ] ) ,
22
+ reportUnusedDisableDirectives :
23
+ args [ '--report-unused-disable-directives' ] || null ,
24
+ cache : args [ '--cache' ] ?? false ,
25
+ cacheLocation : args [ '--cache-location' ] || '.eslintcache' ,
26
+ cacheStrategy : args [ '--cache-strategy' ] || 'metadata' ,
27
+ errorOnUnmatchedPattern : ! Boolean ( args [ '--no-error-on-unmatched-pattern' ] ) ,
28
+ } )
29
+
11
30
const nextLint : cliCommand = ( argv ) => {
12
31
const validArgs : arg . Spec = {
13
32
// Types
14
33
'--help' : Boolean ,
34
+ '--base-dir' : String ,
15
35
'--dir' : [ String ] ,
16
36
17
37
// Aliases
18
38
'-h' : '--help' ,
39
+ '-b' : '--base-dir' ,
19
40
'-d' : '--dir' ,
20
41
}
21
42
43
+ const validEslintArgs : arg . Spec = {
44
+ // Types
45
+ '--config' : String ,
46
+ '--ext' : [ String ] ,
47
+ '--resolve-plugins-relative-to' : String ,
48
+ '--rulesdir' : [ String ] ,
49
+ '--fix' : Boolean ,
50
+ '--fix-type' : [ String ] ,
51
+ '--ignore-path' : String ,
52
+ '--no-ignore' : Boolean ,
53
+ '--no-inline-config' : Boolean ,
54
+ '--report-unused-disable-directives' : String ,
55
+ '--cache' : Boolean ,
56
+ '--cache-location' : String ,
57
+ '--cache-strategy' : String ,
58
+ '--no-error-on-unmatched-pattern' : Boolean ,
59
+
60
+ // Aliases
61
+ '-c' : '--config' ,
62
+ }
63
+
22
64
let args : arg . Result < arg . Spec >
23
65
try {
24
- args = arg ( validArgs , { argv } )
66
+ args = arg ( { ... validArgs , ... validEslintArgs } , { argv } )
25
67
} catch ( error ) {
26
68
if ( error . code === 'ARG_UNKNOWN_OPTION' ) {
27
69
return printAndExit ( error . message , 1 )
@@ -37,14 +79,41 @@ const nextLint: cliCommand = (argv) => {
37
79
38
80
Usage
39
81
$ next lint <baseDir> [options]
40
-
82
+
41
83
<baseDir> represents the directory of the Next.js application.
42
84
If no directory is provided, the current directory will be used.
43
85
44
86
Options
45
- -h - list this help
46
- -d - set directory, or directories, to run ESLint (defaults to only 'pages')
47
- ` ,
87
+ Basic configuration:
88
+ -h, --help List this help
89
+ -d, --dir Array Set directory, or directories, to run ESLint - default: 'pages', 'components', and 'lib'
90
+ -c, --config path::String Use this configuration file, overriding all other config options
91
+ --ext [String] Specify JavaScript file extensions - default: .js, .jsx, .ts, .tsx
92
+ --resolve-plugins-relative-to path::String A folder where plugins should be resolved from, CWD by default
93
+
94
+ Specifying rules:
95
+ --rulesdir [path::String] Use additional rules from this directory
96
+
97
+ Fixing problems:
98
+ --fix Automatically fix problems
99
+ --fix-type Array Specify the types of fixes to apply (problem, suggestion, layout)
100
+
101
+ Ignoring files:
102
+ --ignore-path path::String Specify path of ignore file
103
+ --no-ignore Disable use of ignore files and patterns
104
+
105
+ Inline configuration comments:
106
+ --no-inline-config Prevent comments from changing config or rules
107
+ --report-unused-disable-directives Adds reported errors for unused eslint-disable directives ("error" | "warn" | "off")
108
+
109
+ Caching:
110
+ --cache Only check changed files - default: false
111
+ --cache-location path::String Path to the cache file or directory - default: .eslintcache
112
+ --cache-strategy String Strategy to use for detecting changed files - either: metadata or content - default: metadata
113
+
114
+ Miscellaneous:
115
+ --no-error-on-unmatched-pattern Prevent errors when pattern is unmatched - default: false
116
+ ` ,
48
117
0
49
118
)
50
119
}
@@ -57,7 +126,7 @@ const nextLint: cliCommand = (argv) => {
57
126
}
58
127
59
128
const dirs : string [ ] = args [ '--dir' ]
60
- const lintDirs = ( dirs ?? [ 'pages' , 'components' , 'lib' ] ) . reduce (
129
+ const lintDirs = ( dirs ?? ESLINT_DEFAULT_DIRS ) . reduce (
61
130
( res : string [ ] , d : string ) => {
62
131
const currDir = join ( baseDir , d )
63
132
if ( ! existsSync ( currDir ) ) return res
@@ -67,7 +136,7 @@ const nextLint: cliCommand = (argv) => {
67
136
[ ]
68
137
)
69
138
70
- runLintCheck ( baseDir , lintDirs )
139
+ runLintCheck ( baseDir , lintDirs , false , eslintOptions ( args ) )
71
140
. then ( ( results ) => {
72
141
if ( results ) {
73
142
console . log ( results )
0 commit comments