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

Commit

Permalink
fix: fix stackoverflow + push fallbackForGlobal error
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Mar 14, 2021
1 parent ea63d4f commit 9a142ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions spec/worker-helpers-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ describe('Worker Helpers', () => {
})
spyOn(console, 'error')
Helpers.getESLintInstance(getFixturesPath('local-eslint'), config)
expect(console.error).toHaveBeenCalledWith(`Global ESLint is not found, please ensure the global Node path is set correctly.
If you wanted to use a local installation of Eslint, disable Global Eslint option in the linter-eslint config.`)
expect(console.error).toHaveBeenCalledWith(`Global ESLint is not found, falling back to other Eslint installations...
Please ensure the global Node path is set correctly.
If you wanted to use a local installation of Eslint, disable Global Eslint option in the linter-eslint config.`)
})

it('tries to find a local eslint with nested node_modules', () => {
Expand Down
20 changes: 13 additions & 7 deletions src/worker-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ function isDirectory(dirPath) {
return isDir
}

export function findESLintDirectory(modulesDir, config, projectPath, fallback = false) {
let fallbackForGlobalErrorThrown = false

export function findESLintDirectory(modulesDir, config, projectPath, fallbackForGlobal = false) {
let eslintDir = null
let locationType = null
if (config.global.useGlobalEslint && !fallback) {
if (config.global.useGlobalEslint && !fallbackForGlobal) {
locationType = 'global'
const configGlobal = cleanPath(config.global.globalNodePath)
const prefixPath = configGlobal || getNodePrefixPath()
Expand Down Expand Up @@ -78,11 +80,15 @@ export function findESLintDirectory(modulesDir, config, projectPath, fallback =
}
}

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

return {
Expand Down

0 comments on commit 9a142ae

Please sign in to comment.