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

updating global linter as fallback #1144

Closed
wants to merge 3 commits into from
Closed

updating global linter as fallback #1144

wants to merge 3 commits into from

Conversation

bcnichols3
Copy link

@bcnichols3 bcnichols3 commented Jun 20, 2018

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:

  1. if (localNodeModules && !useGlobalEslint) then locationType = 'advanced specified'; and eslintDir uses a ternary to determine relative or absolute path.
  2. else if (!useGlobalEslint) then locationType = 'local project' and eslintDir is pulled from the modules.
  3. if (!isDirectory(eslintDir)) then locationType = 'global' and eslintDir is resolved to global directory, with respect to OS.
  4. if (isDirectory(eslintDir)) then return the object
  5. else 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 error
  • it errors when no config file is found is also throwing the wrong error

@IanVS
Copy link
Member

IanVS commented Jun 21, 2018

make it so useGlobalEslint remains as an option to supersede local eslint?

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 npm link to create a global reference which points back to the source you're working on. But in both cases, I believe simply having an option to Fall back to global installation would be sufficient, because a standard local installation won't be found in either situation.

So, what do you think about changing the option entirely, from Force global installation to be used to Allow global installation to be fallen back to if a suitable local installation is not found? We're going to have a breaking release soon anyway, so this is probably the time to do it if so desired. I believe this was also the solution requested and agreed upon in the linked issue #845.

@bcnichols3
Copy link
Author

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?

@skylize
Copy link
Contributor

skylize commented Jul 13, 2018

The eslint provider for Linter
  when setting `disableWhenNoEslintConfig` is false
    it errors when no config file is found

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', () => {
Copy link
Contributor

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
Copy link
Contributor

@skylize skylize Jul 13, 2018

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",
Copy link
Contributor

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.'
Copy link
Contributor

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', () => {
Copy link
Contributor

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) {
Copy link
Contributor

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)) {
Copy link
Contributor

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.

@UziTech UziTech added the stale label Oct 27, 2021
@UziTech UziTech closed this Oct 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants