-
Notifications
You must be signed in to change notification settings - Fork 141
Conversation
It seems to me that using a global eslint installation in place of a locally-specified one (the current behavior) is a bad idea. It can cause errors when the local config relies on plugins, which in order to use the global installation also must be installed globally. But then what if you are working on two projects, each relying on different versions of a particular plugin? Or what if your version of eslint allows particular behavior but the project's package.json specifies a version which will flag that behavior as an error? Generally, it's sucky for all the reasons that global installations of eslint are discouraged in the first place. It seems like the only really useful time that folks have said they want to have a global installation is when they're working on small scripts that aren't really part of a "project". Or perhaps when working on eslint itself, when it's useful to So, what do you think about changing the option entirely, from |
checkin in @IanVS ... I have the option being used as a fallback as requested. One test failure for some reason; can't quite reason out why! Maybe you know? |
This spec is probably expecting to use the fallback-installation of ESLint, which is no longer accessible. There are probably more tests like that, which will yell at you after you fix this one. |
}) | ||
|
||
// it('falls back to the packaged eslint when no local or global eslint is found', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a commented out test?
@@ -49,35 +49,47 @@ function isDirectory(dirPath) { | |||
} | |||
|
|||
export function findESLintDirectory(modulesDir, config, projectPath) { | |||
const { localNodeModules } = config.advanced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Destructuring improves readability of the rest of the code.
@@ -69,7 +69,7 @@ | |||
"title": "Global ESLint", | |||
"properties": { | |||
"useGlobalEslint": { | |||
"title": "Use global ESLint installation", | |||
"title": "Always use global ESLint installation", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "Enable fallback to global ESLint installation" ?
@@ -530,9 +530,9 @@ describe('The eslint provider for Linter', () => { | |||
|
|||
it('errors when no config file is found', async () => { | |||
const messages = await lint(editor) | |||
const expected = 'Error while running ESLint: No ESLint configuration found..' | |||
const expected = 'Error while running ESLint: ESLint not found, please add a local eslint to this project or ensure the global Node path is set correctly and turned on.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not bloat the specs with the entire formatted error message. Just match on a small distinctive phrase from the message. (Yeah this problem was already there, but your longer message exaggerates it.)
@@ -62,14 +62,25 @@ describe('Worker Helpers', () => { | |||
expect(foundEslint.type).toEqual('global') | |||
}) | |||
|
|||
it('falls back to the packaged eslint when no local eslint is found', () => { | |||
it('falls back to the global eslint when no local eslint is found and global is turned on', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check for other "found eslint" type specs like this one, that might not make sense anymore.
eslintDir = Path.isAbsolute(cleanPath(localNodeModules)) | ||
? Path.join(cleanPath(localNodeModules), 'eslint') | ||
: Path.join(projectPath || '', cleanPath(localNodeModules), 'eslint') | ||
} else if (!useGlobalEslint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were going to look in local first? This prevents looking in local at all (unless advanced specified) if global is enabled. 😕
} | ||
|
||
if (isDirectory(eslintDir)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDirectory
is expensive. Save the result to a variable so you can use the result twice.
reposting my comment from issue #845
My original thinking is to make it so
useGlobalEslint
remains as an option to supersede local eslint? Though that sounds like a terrible idea. I wonder if that check should be removed entirely, so as to not make it easy to jump over a local eslint — which is definitely a bad idea.Currently I have:
if (localNodeModules && !useGlobalEslint)
thenlocationType = 'advanced specified';
andeslintDir
uses a ternary to determine relative or absolute path.else if (!useGlobalEslint)
thenlocationType = 'local project'
andeslintDir
is pulled from the modules.if (!isDirectory(eslintDir))
thenlocationType = 'global'
andeslintDir
is resolved to global directory, with respect to OS.if (isDirectory(eslintDir))
thenreturn
the objectelse
then `throw new Error('ESLint not found, please add a local eslint to this project or ensure the global Node path is set correctly.')But I can change that to reflect the thinking above. I also altered worker helper tests accordingly, but two
eslint provider
tests are failing:when a file is specified in an eslintIgnore key in package.json it will not give warnings when linting the file
is throwing the wrong errorit errors when no config file is found
is also throwing the wrong error