Skip to content

Commit

Permalink
Fix: crash on WebStorm (fixes #14) (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored Jul 2, 2018
1 parent b8766b6 commit 520f797
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/internal/get-linters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@
"use strict"

const path = require("path")
const needle = `${path.sep}eslint${path.sep}`
const needle = `${path.sep}node_modules${path.sep}eslint${path.sep}`

module.exports = () => {
const eslintPaths = new Set(
Object.keys(require.cache)
.filter(id => id.includes(needle))
.map(id => id.slice(0, id.indexOf(needle) + needle.length))
)
return Array.from(eslintPaths).map(eslintPath => require(eslintPath).Linter)
const linters = []

for (const eslintPath of eslintPaths) {
try {
const linter = require(eslintPath).Linter

if (linter) {
linters.push(linter)
}
} catch (error) {
if (error.code !== "MODULE_NOT_FOUND") {
throw error
}
}
}

return linters
}

0 comments on commit 520f797

Please sign in to comment.