@@ -19,6 +19,9 @@ const Cache = {
19
19
*/
20
20
const cleanPath = path => ( path ? resolveEnv ( fs . normalize ( path ) ) : '' )
21
21
22
+ /**
23
+ * @returns {string }
24
+ */
22
25
export function getNodePrefixPath ( ) {
23
26
if ( Cache . NODE_PREFIX_PATH === null ) {
24
27
const npmCommand = process . platform === 'win32' ? 'npm.cmd' : 'npm'
@@ -35,6 +38,10 @@ export function getNodePrefixPath() {
35
38
return Cache . NODE_PREFIX_PATH
36
39
}
37
40
41
+ /**
42
+ * @param {string } dirPath
43
+ * @returns {boolean }
44
+ */
38
45
function isDirectory ( dirPath ) {
39
46
let isDir
40
47
try {
@@ -47,6 +54,13 @@ function isDirectory(dirPath) {
47
54
48
55
let fallbackForGlobalErrorThrown = false
49
56
57
+ /**
58
+ * @param {string } modulesDir
59
+ * @param {object } config
60
+ * @param {string } projectPath
61
+ * @param {boolean } fallbackForGlobal
62
+ * @returns {{ path: string, type: 'local project' | 'global' | 'advanced specified' | 'bundled fallback' } }
63
+ */
50
64
export function findESLintDirectory ( modulesDir , config , projectPath , fallbackForGlobal = false ) {
51
65
let eslintDir = null
52
66
let locationType = null
@@ -95,6 +109,12 @@ export function findESLintDirectory(modulesDir, config, projectPath, fallbackFor
95
109
}
96
110
}
97
111
112
+ /**
113
+ * @param {string } modulesDir
114
+ * @param {object } config
115
+ * @param {string } projectPath
116
+ * @returns {import("eslint") }
117
+ */
98
118
export function getESLintFromDirectory ( modulesDir , config , projectPath ) {
99
119
const { path : ESLintDirectory } = findESLintDirectory ( modulesDir , config , projectPath )
100
120
try {
@@ -109,6 +129,9 @@ export function getESLintFromDirectory(modulesDir, config, projectPath) {
109
129
}
110
130
}
111
131
132
+ /**
133
+ * @param {string } modulesDir
134
+ */
112
135
export function refreshModulesPath ( modulesDir ) {
113
136
if ( Cache . LAST_MODULES_PATH !== modulesDir ) {
114
137
Cache . LAST_MODULES_PATH = modulesDir
@@ -118,12 +141,22 @@ export function refreshModulesPath(modulesDir) {
118
141
}
119
142
}
120
143
144
+ /**
145
+ * @param {string } fileDir
146
+ * @param {object } config
147
+ * @param {string } projectPath
148
+ * @returns {import("eslint") }
149
+ */
121
150
export function getESLintInstance ( fileDir , config , projectPath ) {
122
151
const modulesDir = Path . dirname ( findCached ( fileDir , 'node_modules/eslint' ) || '' )
123
152
refreshModulesPath ( modulesDir )
124
153
return getESLintFromDirectory ( modulesDir , config , projectPath )
125
154
}
126
155
156
+ /**
157
+ * @param {import("eslint") } eslint
158
+ * @param {string } filePath
159
+ */
127
160
export function getConfigForFile ( eslint , filePath ) {
128
161
const cli = new eslint . CLIEngine ( )
129
162
try {
@@ -134,6 +167,13 @@ export function getConfigForFile(eslint, filePath) {
134
167
}
135
168
}
136
169
170
+ /**
171
+ * @param {string } fileDir
172
+ * @param {string } filePath
173
+ * @param {object } config
174
+ * @param {string } projectPath
175
+ * @returns {string }
176
+ */
137
177
export function getRelativePath ( fileDir , filePath , config , projectPath ) {
138
178
const ignoreFile = config . advanced . disableEslintIgnore ? null : findCached ( fileDir , '.eslintignore' )
139
179
@@ -154,6 +194,13 @@ export function getRelativePath(fileDir, filePath, config, projectPath) {
154
194
return Path . basename ( filePath )
155
195
}
156
196
197
+ /**
198
+ * @param {string } type
199
+ * @param {string[] } rules
200
+ * @param {object } config
201
+ * @param {string } filePath
202
+ * @param {object } fileConfig
203
+ */
157
204
export function getCLIEngineOptions ( type , config , rules , filePath , fileConfig ) {
158
205
const cliEngineConfig = {
159
206
rules,
@@ -179,7 +226,7 @@ export function getCLIEngineOptions(type, config, rules, filePath, fileConfig) {
179
226
180
227
/**
181
228
* Gets the list of rules used for a lint job
182
- * @param {Object } cliEngine The CLIEngine instance used for the lint job
229
+ * @param {import("eslint").CLIEngine } cliEngine The CLIEngine instance used for the lint job
183
230
* @return {Map } A Map of the rules used, rule names as keys, rule
184
231
* properties as the contents.
185
232
*/
0 commit comments