Giter VIP home page Giter VIP logo

Comments (28)

dbaeumer avatar dbaeumer commented on August 16, 2024 1

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.

prashaantt avatar prashaantt commented on August 16, 2024

+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:

  1. Use local eslint if present, else default to global eslint.
  2. Use local .eslintrc if present, else default to global .eslintrc.

from vscode-eslint.

felixfbecker avatar felixfbecker commented on August 16, 2024

+1
Exactly what @prashaantt said, you have to install all plugins (like babel-eslint) globally if you want to use them

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

Will try to look into this for the Jab milestone.

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

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.

dbaeumer avatar dbaeumer commented on August 16, 2024

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

capture

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

However what doesn't work is having the plugin locally and eslint core globally

capture

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

However this seems to be consistent to the eslint command line. Running eslint from a shell gives me

capture

in the setup where where the plugin is installed locally and the eslint globally.

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

I tested the extends property and that works for me as well:

capture

Can someone of you who sees the problem please provide a workspace (zip, git repository) showing the problem.

from vscode-eslint.

mysticatea avatar mysticatea commented on August 16, 2024

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.

mysticatea avatar mysticatea commented on August 16, 2024

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.

dbaeumer avatar dbaeumer commented on August 16, 2024

@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.

dbaeumer avatar dbaeumer commented on August 16, 2024

@mysticatea which OS are you on. I tested all this only on Windows so far.

from vscode-eslint.

mysticatea avatar mysticatea commented on August 16, 2024

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

issue13

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.

image

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

Here is what I see:

capture

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.

mysticatea avatar mysticatea commented on August 16, 2024

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.

dbaeumer avatar dbaeumer commented on August 16, 2024

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.

mysticatea avatar mysticatea commented on August 16, 2024

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

image

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

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.

mysticatea avatar mysticatea commented on August 16, 2024

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.

dbaeumer avatar dbaeumer commented on August 16, 2024

Thanks. Then my fix will work for you. As you can see I will now resolve your local installed eslint.

from vscode-eslint.

mysticatea avatar mysticatea commented on August 16, 2024

OK, Thank you very much for the great support!

from vscode-eslint.

prashaantt avatar prashaantt commented on August 16, 2024

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.

mysticatea avatar mysticatea commented on August 16, 2024

I got it.

from

newEnv[nodePathKey] = newEnv[nodePathKey] + separator + nodePath.join(separator);

to

newEnv[nodePathKey] = nodePath.join(separator) + separator + newEnv[nodePathKey];

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

Correct :-)

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

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.

mysticatea avatar mysticatea commented on August 16, 2024

Yeah, I will do. Thank you very much again!

from vscode-eslint.

dbaeumer avatar dbaeumer commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.