@@ -19,6 +19,9 @@ const Cache = {
1919 */
2020const cleanPath = path => ( path ? resolveEnv ( fs . normalize ( path ) ) : '' )
2121
22+ /**
23+ * @returns {string }
24+ */
2225export function getNodePrefixPath ( ) {
2326 if ( Cache . NODE_PREFIX_PATH === null ) {
2427 const npmCommand = process . platform === 'win32' ? 'npm.cmd' : 'npm'
@@ -35,6 +38,10 @@ export function getNodePrefixPath() {
3538 return Cache . NODE_PREFIX_PATH
3639}
3740
41+ /**
42+ * @param {string } dirPath
43+ * @returns {boolean }
44+ */
3845function isDirectory ( dirPath ) {
3946 let isDir
4047 try {
@@ -47,6 +54,13 @@ function isDirectory(dirPath) {
4754
4855let fallbackForGlobalErrorThrown = false
4956
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+ */
5064export function findESLintDirectory ( modulesDir , config , projectPath , fallbackForGlobal = false ) {
5165 let eslintDir = null
5266 let locationType = null
@@ -95,6 +109,12 @@ export function findESLintDirectory(modulesDir, config, projectPath, fallbackFor
95109 }
96110}
97111
112+ /**
113+ * @param {string } modulesDir
114+ * @param {object } config
115+ * @param {string } projectPath
116+ * @returns {import("eslint") }
117+ */
98118export function getESLintFromDirectory ( modulesDir , config , projectPath ) {
99119 const { path : ESLintDirectory } = findESLintDirectory ( modulesDir , config , projectPath )
100120 try {
@@ -109,6 +129,9 @@ export function getESLintFromDirectory(modulesDir, config, projectPath) {
109129 }
110130}
111131
132+ /**
133+ * @param {string } modulesDir
134+ */
112135export function refreshModulesPath ( modulesDir ) {
113136 if ( Cache . LAST_MODULES_PATH !== modulesDir ) {
114137 Cache . LAST_MODULES_PATH = modulesDir
@@ -118,12 +141,22 @@ export function refreshModulesPath(modulesDir) {
118141 }
119142}
120143
144+ /**
145+ * @param {string } fileDir
146+ * @param {object } config
147+ * @param {string } projectPath
148+ * @returns {import("eslint") }
149+ */
121150export function getESLintInstance ( fileDir , config , projectPath ) {
122151 const modulesDir = Path . dirname ( findCached ( fileDir , 'node_modules/eslint' ) || '' )
123152 refreshModulesPath ( modulesDir )
124153 return getESLintFromDirectory ( modulesDir , config , projectPath )
125154}
126155
156+ /**
157+ * @param {import("eslint") } eslint
158+ * @param {string } filePath
159+ */
127160export function getConfigForFile ( eslint , filePath ) {
128161 const cli = new eslint . CLIEngine ( )
129162 try {
@@ -134,6 +167,13 @@ export function getConfigForFile(eslint, filePath) {
134167 }
135168}
136169
170+ /**
171+ * @param {string } fileDir
172+ * @param {string } filePath
173+ * @param {object } config
174+ * @param {string } projectPath
175+ * @returns {string }
176+ */
137177export function getRelativePath ( fileDir , filePath , config , projectPath ) {
138178 const ignoreFile = config . advanced . disableEslintIgnore ? null : findCached ( fileDir , '.eslintignore' )
139179
@@ -154,6 +194,13 @@ export function getRelativePath(fileDir, filePath, config, projectPath) {
154194 return Path . basename ( filePath )
155195}
156196
197+ /**
198+ * @param {string } type
199+ * @param {string[] } rules
200+ * @param {object } config
201+ * @param {string } filePath
202+ * @param {object } fileConfig
203+ */
157204export function getCLIEngineOptions ( type , config , rules , filePath , fileConfig ) {
158205 const cliEngineConfig = {
159206 rules,
@@ -179,7 +226,7 @@ export function getCLIEngineOptions(type, config, rules, filePath, fileConfig) {
179226
180227/**
181228 * 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
183230 * @return {Map } A Map of the rules used, rule names as keys, rule
184231 * properties as the contents.
185232 */
0 commit comments