New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api.markVariableAsUsed does not check Node.js scope #2089
Comments
I'm not sure I'd call this a bug with the method, it seems more a bug with how it's being used. The method searches from the current scope up to the global scope. If you're calling it in "Program", then you're saying "only search the global scope". However, in almost all cases you should not be calling Can you show me how you're using it? |
Okay, I saw your other bug and I get it now. While I'd still recommend not using |
I'm using it to mark as used the variables in the JSX code. You can see the rule here: https://github.com/yannickcr/eslint-plugin-react/blob/master/lib/rules/jsx-uses-vars.js |
That looks like it should work (since you're not in the global scope). Are you still seeing an error? |
Hmm, I'm I'm looking at this correctly, I'm not sure |
Sorry but I do not see the relation with To retake the above example: "use strict";
var eslint = require("./lib/api.js").linter;
var code = "var a = 1, b = 2;";
eslint.reset();
eslint.on("Program:exit", function() {
eslint.markVariableAsUsed("a"); // return false, the variable was not found in the scope
});
eslint.verify(code, { env: { node: true }}, "test.js", true); But if we are not in the the Node.js environment: "use strict";
var eslint = require("./lib/api.js").linter;
var code = "var a = 1, b = 2;";
eslint.reset();
eslint.on("Program:exit", function() {
eslint.markVariableAsUsed("a"); // return true, the variable was found in the scope
});
eslint.verify(code, {}, "test.js", true); When in a Node.js scope, the variable Pull request #2090 should fix this. |
What I meant was the original issue you reported had nothing to do with this. This is a separate issue. |
Working on this. |
Fix: markVariableAsUsed() should work in Node.js env (fixes #2089)
The Node.js scope is not checked by the api.markVariableAsUsed function making these variables impossible to mark as used.
The text was updated successfully, but these errors were encountered: