question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not always run eslint from the project's root directory

See original GitHub issue

First off, thanks for all the great work you’ve been doing so far! 👍

I just ran into an issue:

I’m working on a project with a structure like this:

project
|- server-app
|- web-app-1
|- web-app-2

when I open vscode for a web-app via code /path/tp/project/web-app-1 vscode-eslint works as expected.

If I open the whole project via code /path/tp/project however I get plenty of linting errors on files that worked before. Errors look like:

Resolve error: ENOENT: no such file or directory, open /path/tp/project/package.json'  import/no-unresolved

and indeed, there’s no package.json in the project root. It’s in /path/tp/project/web-app-1/package.json

The output is the very same as if I did

cd /path/tp/project
node web-app-1/node_modules/eslint/bin/eslint.js web-app-1/src/path/to/file

So I assume vscode-eslint calls eslint from the project root, rather than from the web-app’s root which causes issues with e.g. eslint-plugin-import.

Is there a way to fix this? Maybe by looking for the root package.json for each .js file and calling eslint from its directory?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:22 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
dbaeumercommented, Feb 13, 2017

I couldn’t get it to work either. I did the following enhancement. The workingDirectories take an object literal as well which allows you to tell ESLint to change the process.cwd as well. Changing this has to be used with care and is therefore off by default. A config looks like this:

{
	"eslint.workingDirectories": [
		{ 
			"directory": "web-app", 
			"changeProcessCWD": true
		}
	]
}
1reaction
danielberndtcommented, Feb 2, 2017

Thanks for the quick reply, @dbaeumer!

From my perspective the simplest approach seems to be to spin up one server per web-app. This would probably also make it quite straight forward to support various eslint versions and rules that might be present in each of the different web-apps.

And rather than guessing where to locate the web-apps, I personally would be fine with an option within the settings:

eslint.roots: ["."] //default
eslint.roots: ["./web-app-1". "./web-app-2"] // for the use case explained above

As a bonus the servers could be spun up lazily. I.e. if you’re not touching any file within web-app-2 its server is not started.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration Files - ESLint - Pluggable JavaScript Linter
By default, ESLint looks for configuration files in all parent folders up to the root directory. This can be useful if you want...
Read more >
Disable eslint rules for folder - Stack Overflow
To ignore some folder from eslint rules we could create the file .eslintignore in root directory and add there the path to the...
Read more >
Why and how to use ESLint in your project - IBM Developer
Ensure you have a .gitignore file (so derived files do not get linted, only original source files). If you don't have one, you...
Read more >
Basic Features: ESLint - Next.js
If you do not want ESLint to run during next build , refer to the ... in a project where Next.js isn't installed...
Read more >
true` in ESLint configuration when setting a working directory
As I understand, root: true flag is affects ESLint tool logic but doesn't ... in example project (from my comment above) I can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found