Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Fix exception for "Fix File" on Windows #354

Merged
merged 3 commits into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Upcoming

* Fix file exception on Windows resolution (#353)

### v5.2.5

* Fix file import resolution (#340)
Expand Down
22 changes: 18 additions & 4 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
process.title = 'linter-eslint helper'

const CP = require('childprocess-promise')
const execFileSync = require('child_process').execFileSync
const Path = require('path')

const resolveEnv = require('resolve-env')
Expand Down Expand Up @@ -84,21 +83,36 @@ Communication.on('JOB', function(job) {

Communication.on('FIX', function(fixJob) {
const params = fixJob.Message
const eslintDir = findEslintDir(params)
const modulesPath = find(params.fileDir, 'node_modules')
const configFile = determineConfigFile(params)
const eslintBinPath = Path.normalize(Path.join(eslintDir, 'bin', 'eslint.js'))

if (modulesPath) {
process.env.NODE_PATH = modulesPath
} else process.env.NODE_PATH = ''
require('module').Module._initPaths()

// Determine which eslint instance to use
const eslintNewPath = findEslintDir(params)
if (eslintNewPath !== eslintPath) {
eslint = getEslintCli(eslintNewPath)
eslintPath = eslintNewPath
}

const argv = [
process.execPath,
eslintPath,
params.filePath,
'--fix'
]

if (configFile !== null) {
argv.push('--config', resolveEnv(configFile))
}

fixJob.Response = new Promise(function(resolve, reject) {
try {
execFileSync(eslintBinPath, argv, {cwd: params.fileDir})
process.argv = argv
eslint.execute(process.argv)
} catch (err) {
reject('Linter-ESLint: Fix Attempt Completed, Linting Errors Remain')
}
Expand Down