Skip to content

Commit

Permalink
Change working directory before linting
Browse files Browse the repository at this point in the history
Otherwise, ESLint runs from the root directory which results in slightly different behavior than running standard on the command line. For example, if the project directory is within a hidden directory (e.g. /home/jane/.secret/project), ESLint ignores all files. Fixes #222.

We cannot use standard’s cwd option here because standard-engine does not pass the cwd through to ESLint. See standard/standard-engine#189.
  • Loading branch information
sonicdoe committed Sep 19, 2018
1 parent e4b5abc commit 5b05e68
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/linter-js-standard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Dependencies
var path = require('path')
var linter = require('./utils/linter')
var allowUnsafeNewFunction = require('loophole').allowUnsafeNewFunction
var markdownSplitter = require('./utils/markdown-splitter')
Expand All @@ -15,7 +16,14 @@ function generateLintPromise (textEditor, filePath, fileContent, settings, lineS
lineStart: lineStart || 0
})

var workingDirectory = path.dirname(filePath)
var previousWorkingDirectory = process.cwd()

process.chdir(workingDirectory)

settings.style.lintText(fileContent, settings.opts, (err, results) => {
process.chdir(previousWorkingDirectory)

if (err) {
return reject(err)
}
Expand Down

0 comments on commit 5b05e68

Please sign in to comment.