Comments (28)
The is actually expected: see http://eslint.org/docs/user-guide/configuring.html
Note: A globally-installed instance of ESLint can only use globally-installed ESLint plugins. A locally-installed ESLint can make use of both locally- and globally- installed ESLint plugins.
from vscode-eslint.
+1
The other unexpected (IMO) issue is that vscode-eslint
isn't picking up project-specific plugins if no local eslint
is found.
{
"extends": "hapi"
}
Here eslint-config-hapi
isn't getting picked up from my devDependencies
because I don't have eslint
in my devDependencies
, so it's using the global eslint
and then complaining that eslint-config-hapi
isn't available globally.
I would expect the following to happen:
- Use local
eslint
if present, else default to globaleslint
. - Use local
.eslintrc
if present, else default to global.eslintrc
.
from vscode-eslint.
+1
Exactly what @prashaantt said, you have to install all plugins (like babel-eslint
) globally if you want to use them
from vscode-eslint.
Will try to look into this for the Jab milestone.
from vscode-eslint.
I tested this and vscode-eslint prefers a local installed eslint over a global installed one (I only tested this for the core eslint so far). I need to test plugins. They might behave different.
from vscode-eslint.
Plugins work for me as well. In the screen shot below you see a eslint-plugin-objects in action. Both the plugin and the eslint core are installed locally
from vscode-eslint.
However what doesn't work is having the plugin locally and eslint core globally
from vscode-eslint.
However this seems to be consistent to the eslint command line. Running eslint from a shell gives me
in the setup where where the plugin is installed locally and the eslint globally.
from vscode-eslint.
I tested the extends property and that works for me as well:
Can someone of you who sees the problem please provide a workspace (zip, git repository) showing the problem.
from vscode-eslint.
I have several projects which are using eslint.
Project A is using eslint 1.10.3.
Project B is using eslint 2.0.0.
npm ecosystem's tools are designed to use together with npm-scripts.
In this case, e.g. npm run lint
.
{
"scripts": {
"lint": "eslint ."
},
"devDependencies": {
"eslint": "1.10.3"
}
}
In npm-scripts, commands such eslint
uses the local installed one which is specified by package.json.
But vscode-eslint is selecting the global installed one. So it raises errors on new rules or removed rules. It's inconvenience to me.
Plus, I'm a contributor of eslint. The repository of eslint is linting itself by own code. So I have installed the HEAD of eslint to global by npm link
for only vscode. vscode-eslint is always using it on other projects even if there is the version the project specified by package.json.
from vscode-eslint.
To make clear, this issue's intention is not related to plugins and shareable configs.
There is the version of eslint the project specifies, but vscode-eslint is not using it.
It's a problem.
from vscode-eslint.
@mysticatea vscode-eslint first tries to use the eslint version installed in the workspace folder. So if you have executed npm install and the package.json lists eslint as a dev dependency eslint should be available and be used by vscode-eslint. That is what I tested (see #13 (comment)). Can you provide me with a test case where this is not the case?
from vscode-eslint.
@mysticatea which OS are you on. I tested all this only on Windows so far.
from vscode-eslint.
Thank you for investigating.
I'm on
- Windows 7 Pro 64bit
- nodist (0.6.1)
- node (4.2.3)
- npm (3.5.0)
- VSCode Insiders (0.10.7-insiders)
- vscode-eslint (0.10.11)
I can reproduce this as I execute the following commands on cmd.exe
at an empty folder.
mkdir node_modules
echo {"rules": {"keyword-spacing": 2}} > .eslintrc
echo if(true); > test.js
npm install -g eslint@latest
npm install eslint@next
eslint -v
.\node_modules\.bin\eslint -v
code-insiders test.js
The keyword-spacing
rule has been added on eslint@next
.
I expected VSCode to show "Expected space(s) after "if" (keyword-spacing)"
.
But actually VSCode shows "Definition for rule 'keyword-spacing' was not found (keyword-spacing)"
.
This result is the same as the global installed one's.
from vscode-eslint.
Here is what I see:
The version differences are as follows:
- Windows 10
- node: v4.2.6
- npm: 2.14.12
I do use npm to help me resolve the module to load. Could you do me a favour and run the following npm command for me: npm config get prefix
from vscode-eslint.
Oh, interesting.
$ npm config get prefix
C:\Users\t-nagashima.AD\nodist\bin
And I have several environment variables which is related to this.
NODE_PATH %NODIST_PREFIX%\bin\node_modules
NODIST_PREFIX C:\Users\t-nagashima.AD\nodist
NODIST_X64 1
PATH %NODIST_PREFIX%\bin;C:\Users\t-nagashima.AD\AppData\Local\atom\bin;C:\Program Files (x86)\Microsoft VS Code Insiders\bin;C:\Program Files (x86)\Microsoft VS Code\bin;........
from vscode-eslint.
OK. Thanks. I know what the problem is :-) The NODE_PATH setting which instructs node to look there for modules. I will think what I can change.
from vscode-eslint.
Mmm, I removed the variable then try, but I look the same result...
(I removed it with GUI)
$ echo "%NODE_PATH%"
"%NODE_PATH%"
$ echo "%NODIST_PREFIX%"
"C:\Users\t-nagashima.AD\nodist"
$ code-insiders test.js
from vscode-eslint.
Can you do me a favour? Create the following two files in that workspace folder:
file.js
var child_process = require('child_process');
var path = require('path');
var nodePathKey = 'NODE_PATH';
var moduleName = 'eslint';
var nodePath = [];
function isWindows() {
return process.platform === 'win32';
}
nodePath.push(path.join(__dirname, 'node_modules'));
child_process.exec('npm config get prefix', function (error, stdout, stderr) {
if (!error) {
var globalPath = stdout.toString().replace(/[\s\r\n]+$/, '');
if (globalPath.length > 0) {
if (isWindows()) {
nodePath.push(path.join(globalPath, 'node_modules'));
} else {
nodePath.push(path.join(globalPath, 'lib', 'node_modules'));
}
}
}
var separator = isWindows() ? ';' : ':';
var env = process.env;
var newEnv = Object.create(null);
Object.keys(env).forEach(function (key) { return newEnv[key] = env[key]; });
if (newEnv[nodePathKey]) {
newEnv[nodePathKey] = nodePath.join(separator) + separator + newEnv[nodePathKey];
}
else {
newEnv[nodePathKey] = nodePath.join(separator);
}
try {
console.log('NODE_PATH: ' + newEnv[nodePathKey]);
var cp = child_process.fork(path.join(__dirname, 'resolve.js'), [], { env: newEnv, execArgv: [] });
cp.on('message', function (message) {
if (message.command === 'resolve') {
var toRequire = moduleName;
if (message.success) {
toRequire = message.result;
}
cp.send({ command: 'exit' });
console.log(toRequire);
}
});
var message = {
command: 'resolve',
args: moduleName
};
cp.send(message);
}
catch (error) {
console.log(error);
}
});
and resolve.js
'use strict';
process.on('message', function (message) {
if (message.command === 'exit') {
process.exit(0);
}
else if (message.command === 'resolve') {
try {
var result = require.resolve(message.args);
process.send({ command: 'resolve', success: true, result: result });
}
catch (err) {
process.send({ command: 'resolve', success: false });
}
}
});
Set the environment variable ATOM_SHELL_INTERNAL_RUN_AS_NODE to 1 and then execute file.js using the "Code - Insider.exe". Something like
'C:\Program Files (x86)\Microsoft VS Code Insiders\Code - Insiders.exe' file.js
What does the program print to the console I your 'original' setup.
from vscode-eslint.
I revived NODE_PATH and did it.
C:\Users\t-nagashima.AD\Documents\GitHub\sand>"C:\Program Files (x86)\Microsoft VS Code Insiders\Code - Insiders.exe" file.js
NODE_PATH: C:\Users\t-nagashima.AD\Documents\GitHub\sand\node_modules;C:\Users\t-nagashima.AD\nodist\bin\node_modules;C:\Users\t-nagashima.AD\nodist\bin\node_modules
C:\Users\t-nagashima.AD\Documents\GitHub\sand\node_modules\eslint\lib\api.js
from vscode-eslint.
Thanks. Then my fix will work for you. As you can see I will now resolve your local installed eslint.
from vscode-eslint.
OK, Thank you very much for the great support!
from vscode-eslint.
I'm sorry I haven't been able to get back to this yet, but I wanted to thank you @dbaeumer for your detailed investigations, and @mysticatea for following up.
from vscode-eslint.
I got it.
from
newEnv[nodePathKey] = newEnv[nodePathKey] + separator + nodePath.join(separator);
to
newEnv[nodePathKey] = nodePath.join(separator) + separator + newEnv[nodePathKey];
from vscode-eslint.
Correct :-)
from vscode-eslint.
You can patch your eslint installation if you want. I need to wait to update eslint to have a 0.10.7 available since I did other changes which require the latest VSCode.
from vscode-eslint.
Yeah, I will do. Thank you very much again!
from vscode-eslint.
The fix of this problem is covered by microsoft/vscode-languageserver-node#23.
@mysticatea Thanks again for helping me tracking this down.
@prashaantt if you still see problems with resolving correct configurations please open another issue.
from vscode-eslint.
Related Issues (20)
- Document behavior and defaults of useFlatConfig across ESLint v8, v9, v10 HOT 2
- [Suggestion] Mark `warn` eslint level as vscode `DiagnosticSeverity.Information` `info` level HOT 3
- `eslint.execArgv` Configuration is Not Working HOT 3
- JSON schema for useFlatConfig can be more specific HOT 1
- Should plugins still have `eslint.experimental.useFlatConfig` in their settings? HOT 1
- Support custom clickable links in eslint error tooltips HOT 1
- The extension does not show any errors anymore HOT 3
- Enfore validate list
- Error output (in flat config) causes problems not to appear in the output channel HOT 2
- Add support for ESLint feature flags HOT 4
- Restarting an extension when that extension's output is selected in the "Output" pane should not change which extension is selected in the "Output" pane. HOT 3
- ESLint with SafeQL crashes on Windows with error code 3221226505 HOT 5
- About eslint config,When user setting and workspace setting are conflict,how to override user settings config HOT 1
- ESLint is preventing my files from being saved HOT 7
- eslint autofix for multiple empty lines don't work HOT 1
- ESLint server only looks at first entry in `context.only` array sent along with `textDocument/codeAction` HOT 4
- Supervied Idenification Verification Profile HOT 2
- Setup ESLint with Deno runtime instead of node HOT 2
- eslint 一旦出现 error,输出日志显示 Error 时,代码编辑器爆红会消失 HOT 2
- Support for `typescript-eslint` v8's parser `projectService` HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-eslint.