2
2
// Note: 'use babel' doesn't work in forked processes
3
3
process . title = 'linter-eslint helper'
4
4
5
- const CP = require ( 'childprocess-promise' )
6
- const execFileSync = require ( 'child_process' ) . execFileSync
7
- const Path = require ( 'path' )
5
+ import Path from 'path'
6
+ import { execFileSync } from 'child_process'
7
+ import CP from 'childprocess-promise'
8
+ import resolveEnv from 'resolve-end'
9
+ import * as Helpers from './helpers'
8
10
9
- const resolveEnv = require ( 'resolve-env' )
10
- const Helpers = require ( './es5-helpers' )
11
-
12
- const findEslintDir = Helpers . findEslintDir
13
- const find = Helpers . find
14
- const determineConfigFile = Helpers . determineConfigFile
15
- const getEslintCli = Helpers . getEslintCli
16
11
const Communication = new CP ( )
17
12
18
- // closed-over module-scope variables
19
- let eslintPath = null
20
- let eslint = null
13
+ let eslint
14
+ let lastEslintDirectory
21
15
22
- Communication . on ( 'JOB' , function ( job ) {
23
- const params = job . Message
24
- const modulesPath = find ( params . fileDir , 'node_modules' )
25
- const eslintignoreDir = Path . dirname ( find ( params . fileDir , '.eslintignore' ) )
26
- let configFile = null
16
+ Communication . on ( 'JOB' , function ( Job ) {
27
17
global . __LINTER_RESPONSE = [ ]
28
18
29
- // Check for config file and determine whether to bail out
30
- configFile = determineConfigFile ( params )
19
+ const params = Job . Message
20
+ const modulesPath = Helpers . getModulesDirectory ( params . fileDir )
21
+ const ignoreFile = Helpers . getIgnoresFile ( params . fileDir )
22
+ const configFile = Helpers . getEslintConfig ( params . fileDir )
23
+ const eslintDirectory = Helpers . getEslintDirectory ( params , modulesPath )
31
24
32
25
if ( params . canDisable && configFile === null ) {
33
- job . Response = [ ]
34
- return
26
+ return Job . Response = [ ]
27
+ }
28
+
29
+ if ( eslintDirectory !== lastEslintDirectory ) {
30
+ lastEslintDirectory = eslintDirectory
31
+ eslint = Helpers . getEslintFromDirectory ( eslintDirectory )
35
32
}
36
33
37
34
if ( modulesPath ) {
38
35
process . env . NODE_PATH = modulesPath
39
36
} else process . env . NODE_PATH = ''
40
37
require ( 'module' ) . Module . _initPaths ( )
41
38
42
- // Determine which eslint instance to use
43
- const eslintNewPath = findEslintDir ( params )
44
- if ( eslintNewPath !== eslintPath ) {
45
- eslint = getEslintCli ( eslintNewPath )
46
- eslintPath = eslintNewPath
47
- }
48
-
49
- job . Response = new Promise ( function ( resolve ) {
39
+ Job . Response = new Promise ( function ( resolve ) {
50
40
let filePath
51
- if ( eslintignoreDir ) {
52
- filePath = Path . relative ( eslintignoreDir , params . filePath )
53
- process . chdir ( eslintignoreDir )
41
+ if ( ignoreFile ) {
42
+ filePath = Path . relative ( ignoreFile , params . filePath )
43
+ process . chdir ( ignoreFile )
54
44
} else {
55
45
filePath = Path . basename ( params . filePath )
56
46
process . chdir ( params . fileDir )
57
47
}
48
+
58
49
const argv = [
59
50
process . execPath ,
60
- eslintPath ,
51
+ eslintDirectory ,
61
52
'--stdin' ,
62
53
'--format' ,
63
54
Path . join ( __dirname , 'reporter.js' )
@@ -77,6 +68,7 @@ Communication.on('JOB', function(job) {
77
68
}
78
69
argv . push ( '--stdin-filename' , filePath )
79
70
process . argv = argv
71
+
80
72
eslint . execute ( process . argv , params . contents )
81
73
resolve ( global . __LINTER_RESPONSE )
82
74
} )
0 commit comments