1
1
/* global emit */
2
2
3
- import Path from 'path'
3
+ import * as Path from 'path'
4
4
import { FindCache , findCached } from 'atom-linter'
5
5
import * as Helpers from './worker-helpers'
6
6
@@ -9,7 +9,23 @@ process.title = 'linter-eslint helper'
9
9
const rulesMetadata = new Map ( )
10
10
let shouldSendRules = false
11
11
12
- function lintJob ( { cliEngineOptions, contents, eslint, filePath } ) {
12
+ /**
13
+ * The return of {getCLIEngineOptions} function
14
+ * @typedef {object } CliEngineOptions
15
+ * @property {string[] } rules
16
+ * @property {boolean } ignore
17
+ * @property {boolean } fix
18
+ * @property {string[] } rulePaths
19
+ * @property {string | undefined } configFile
20
+ */
21
+
22
+ /**
23
+ * @param {CliEngineOptions } cliEngineOptions
24
+ * @param {string } contents
25
+ * @param {import("eslint") } eslint
26
+ * @param {string } filePath
27
+ */
28
+ function lintJob ( cliEngineOptions , contents , eslint , filePath ) {
13
29
const cliEngine = new eslint . CLIEngine ( cliEngineOptions )
14
30
const report = cliEngine . executeOnText ( contents , filePath )
15
31
const rules = Helpers . getRules ( cliEngine )
@@ -22,8 +38,14 @@ function lintJob({ cliEngineOptions, contents, eslint, filePath }) {
22
38
return report
23
39
}
24
40
25
- function fixJob ( { cliEngineOptions, contents, eslint, filePath } ) {
26
- const report = lintJob ( { cliEngineOptions, contents, eslint, filePath } )
41
+ /**
42
+ * @param {CliEngineOptions } cliEngineOptions
43
+ * @param {string } contents
44
+ * @param {string } filePath
45
+ * @param {import("eslint") } eslint
46
+ */
47
+ function fixJob ( cliEngineOptions , contents , eslint , filePath ) {
48
+ const report = lintJob ( cliEngineOptions , contents , eslint , filePath )
27
49
28
50
eslint . CLIEngine . outputFixes ( report )
29
51
@@ -61,7 +83,7 @@ module.exports = async () => {
61
83
62
84
let response
63
85
if ( type === 'lint' ) {
64
- const report = lintJob ( { cliEngineOptions, contents, eslint, filePath } )
86
+ const report = lintJob ( cliEngineOptions , contents , eslint , filePath )
65
87
response = {
66
88
messages : report . results . length ? report . results [ 0 ] . messages : [ ]
67
89
}
@@ -70,7 +92,7 @@ module.exports = async () => {
70
92
response . updatedRules = Array . from ( rulesMetadata )
71
93
}
72
94
} else if ( type === 'fix' ) {
73
- response = fixJob ( { cliEngineOptions, contents, eslint, filePath } )
95
+ response = fixJob ( cliEngineOptions , contents , eslint , filePath )
74
96
} else if ( type === 'debug' ) {
75
97
const modulesDir = Path . dirname ( findCached ( fileDir , 'node_modules/eslint' ) || '' )
76
98
response = Helpers . findESLintDirectory ( modulesDir , config , projectPath )
0 commit comments