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

Commit a9e60ca

Browse files
authored
Merge pull request #1415 from AtomLinter/find-eslint-plugins
fix: fix stackoverflow for fallbackForGlobal error
2 parents ea63d4f + 9a142ae commit a9e60ca

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

spec/worker-helpers-spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ describe('Worker Helpers', () => {
127127
})
128128
spyOn(console, 'error')
129129
Helpers.getESLintInstance(getFixturesPath('local-eslint'), config)
130-
expect(console.error).toHaveBeenCalledWith(`Global ESLint is not found, please ensure the global Node path is set correctly.
131-
If you wanted to use a local installation of Eslint, disable Global Eslint option in the linter-eslint config.`)
130+
expect(console.error).toHaveBeenCalledWith(`Global ESLint is not found, falling back to other Eslint installations...
131+
Please ensure the global Node path is set correctly.
132+
If you wanted to use a local installation of Eslint, disable Global Eslint option in the linter-eslint config.`)
132133
})
133134

134135
it('tries to find a local eslint with nested node_modules', () => {

src/worker-helpers.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ function isDirectory(dirPath) {
4747
return isDir
4848
}
4949

50-
export function findESLintDirectory(modulesDir, config, projectPath, fallback = false) {
50+
let fallbackForGlobalErrorThrown = false
51+
52+
export function findESLintDirectory(modulesDir, config, projectPath, fallbackForGlobal = false) {
5153
let eslintDir = null
5254
let locationType = null
53-
if (config.global.useGlobalEslint && !fallback) {
55+
if (config.global.useGlobalEslint && !fallbackForGlobal) {
5456
locationType = 'global'
5557
const configGlobal = cleanPath(config.global.globalNodePath)
5658
const prefixPath = configGlobal || getNodePrefixPath()
@@ -78,11 +80,15 @@ export function findESLintDirectory(modulesDir, config, projectPath, fallback =
7880
}
7981
}
8082

81-
if (config.global.useGlobalEslint) {
82-
// TODO push the error to the user
83-
console.error(`Global ESLint is not found, please ensure the global Node path is set correctly.
84-
If you wanted to use a local installation of Eslint, disable Global Eslint option in the linter-eslint config.`)
85-
findESLintDirectory(modulesDir, config, projectPath, true)
83+
if (config.global.useGlobalEslint && !fallbackForGlobal) {
84+
if (!fallbackForGlobalErrorThrown) {
85+
// Throw the error only once to prevent performance issues
86+
fallbackForGlobalErrorThrown = true
87+
console.error(`Global ESLint is not found, falling back to other Eslint installations...
88+
Please ensure the global Node path is set correctly.
89+
If you wanted to use a local installation of Eslint, disable Global Eslint option in the linter-eslint config.`)
90+
}
91+
return findESLintDirectory(modulesDir, config, projectPath, true)
8692
}
8793

8894
return {

0 commit comments

Comments
 (0)