ESLint no-undef rule: many of functions in another file
The question is about.. how to tell eslint not to show error if the function is in another file?
Example:
--- core.js --- some core code without utils definitions
function draw() {
const color = getRandomColor();
canvasClear();
drawNode();
drawLevel();
drawLine();
drawCaption();
}
--- draw-utils.js --- function declarations
function getRandomColor() {...};
function canvasClear() {...};
function drawNode() {...};
function drawLevel() {...};
function drawLine() {...};
function drawCaption() {...};
Of course there are many of eslint 'no-undef' errors, because there is no all of this functions's declarations. The second file is also full of 'no-unused-vars'.
Is there a way to tell them about themselves? Without 'globals' section in .eslint.json
javascript eslint
|
show 1 more comment
The question is about.. how to tell eslint not to show error if the function is in another file?
Example:
--- core.js --- some core code without utils definitions
function draw() {
const color = getRandomColor();
canvasClear();
drawNode();
drawLevel();
drawLine();
drawCaption();
}
--- draw-utils.js --- function declarations
function getRandomColor() {...};
function canvasClear() {...};
function drawNode() {...};
function drawLevel() {...};
function drawLine() {...};
function drawCaption() {...};
Of course there are many of eslint 'no-undef' errors, because there is no all of this functions's declarations. The second file is also full of 'no-unused-vars'.
Is there a way to tell them about themselves? Without 'globals' section in .eslint.json
javascript eslint
It's generally a good idea to use some kind of module system rather than relying on stuff being in the global scope.
– Jared Smith
Nov 16 '18 at 12:09
Of course modules are great, but if understand correct, there is no modules native support in browsers.. so I need to use module bundlers like webpack to get one source-bundle.js But the problem I've tried to solve is to separate one file to several files. And eslint annoys me.
– Nick_Rimer
Nov 16 '18 at 14:12
Your information is out of date. Native modules are supported in all browsers with > 7% global market share. Have been for a bit now. And eslint is configurable for that very reason.
– Jared Smith
Nov 16 '18 at 14:33
@JaredSmith mmm.. I'll think about it.. i've tried modules in last google chrome about 2 weeks ago and just got unworking project :) need for more tests
– Nick_Rimer
Nov 16 '18 at 15:03
I'm not trying to paint a rosier picture than exists. I've been using native modules, in production, for over a year (I don't have to support oddball browsers often, 80% of my projects are internal and not public facing). The only problem is third-party integration: most libraries are, if you're lucky, written for webpack (not compatible with current native implementations) or if you're not lucky common js. Very few libraries play nice with native modules.
– Jared Smith
Nov 16 '18 at 15:18
|
show 1 more comment
The question is about.. how to tell eslint not to show error if the function is in another file?
Example:
--- core.js --- some core code without utils definitions
function draw() {
const color = getRandomColor();
canvasClear();
drawNode();
drawLevel();
drawLine();
drawCaption();
}
--- draw-utils.js --- function declarations
function getRandomColor() {...};
function canvasClear() {...};
function drawNode() {...};
function drawLevel() {...};
function drawLine() {...};
function drawCaption() {...};
Of course there are many of eslint 'no-undef' errors, because there is no all of this functions's declarations. The second file is also full of 'no-unused-vars'.
Is there a way to tell them about themselves? Without 'globals' section in .eslint.json
javascript eslint
The question is about.. how to tell eslint not to show error if the function is in another file?
Example:
--- core.js --- some core code without utils definitions
function draw() {
const color = getRandomColor();
canvasClear();
drawNode();
drawLevel();
drawLine();
drawCaption();
}
--- draw-utils.js --- function declarations
function getRandomColor() {...};
function canvasClear() {...};
function drawNode() {...};
function drawLevel() {...};
function drawLine() {...};
function drawCaption() {...};
Of course there are many of eslint 'no-undef' errors, because there is no all of this functions's declarations. The second file is also full of 'no-unused-vars'.
Is there a way to tell them about themselves? Without 'globals' section in .eslint.json
javascript eslint
javascript eslint
asked Nov 16 '18 at 12:02
Nick_RimerNick_Rimer
164
164
It's generally a good idea to use some kind of module system rather than relying on stuff being in the global scope.
– Jared Smith
Nov 16 '18 at 12:09
Of course modules are great, but if understand correct, there is no modules native support in browsers.. so I need to use module bundlers like webpack to get one source-bundle.js But the problem I've tried to solve is to separate one file to several files. And eslint annoys me.
– Nick_Rimer
Nov 16 '18 at 14:12
Your information is out of date. Native modules are supported in all browsers with > 7% global market share. Have been for a bit now. And eslint is configurable for that very reason.
– Jared Smith
Nov 16 '18 at 14:33
@JaredSmith mmm.. I'll think about it.. i've tried modules in last google chrome about 2 weeks ago and just got unworking project :) need for more tests
– Nick_Rimer
Nov 16 '18 at 15:03
I'm not trying to paint a rosier picture than exists. I've been using native modules, in production, for over a year (I don't have to support oddball browsers often, 80% of my projects are internal and not public facing). The only problem is third-party integration: most libraries are, if you're lucky, written for webpack (not compatible with current native implementations) or if you're not lucky common js. Very few libraries play nice with native modules.
– Jared Smith
Nov 16 '18 at 15:18
|
show 1 more comment
It's generally a good idea to use some kind of module system rather than relying on stuff being in the global scope.
– Jared Smith
Nov 16 '18 at 12:09
Of course modules are great, but if understand correct, there is no modules native support in browsers.. so I need to use module bundlers like webpack to get one source-bundle.js But the problem I've tried to solve is to separate one file to several files. And eslint annoys me.
– Nick_Rimer
Nov 16 '18 at 14:12
Your information is out of date. Native modules are supported in all browsers with > 7% global market share. Have been for a bit now. And eslint is configurable for that very reason.
– Jared Smith
Nov 16 '18 at 14:33
@JaredSmith mmm.. I'll think about it.. i've tried modules in last google chrome about 2 weeks ago and just got unworking project :) need for more tests
– Nick_Rimer
Nov 16 '18 at 15:03
I'm not trying to paint a rosier picture than exists. I've been using native modules, in production, for over a year (I don't have to support oddball browsers often, 80% of my projects are internal and not public facing). The only problem is third-party integration: most libraries are, if you're lucky, written for webpack (not compatible with current native implementations) or if you're not lucky common js. Very few libraries play nice with native modules.
– Jared Smith
Nov 16 '18 at 15:18
It's generally a good idea to use some kind of module system rather than relying on stuff being in the global scope.
– Jared Smith
Nov 16 '18 at 12:09
It's generally a good idea to use some kind of module system rather than relying on stuff being in the global scope.
– Jared Smith
Nov 16 '18 at 12:09
Of course modules are great, but if understand correct, there is no modules native support in browsers.. so I need to use module bundlers like webpack to get one source-bundle.js But the problem I've tried to solve is to separate one file to several files. And eslint annoys me.
– Nick_Rimer
Nov 16 '18 at 14:12
Of course modules are great, but if understand correct, there is no modules native support in browsers.. so I need to use module bundlers like webpack to get one source-bundle.js But the problem I've tried to solve is to separate one file to several files. And eslint annoys me.
– Nick_Rimer
Nov 16 '18 at 14:12
Your information is out of date. Native modules are supported in all browsers with > 7% global market share. Have been for a bit now. And eslint is configurable for that very reason.
– Jared Smith
Nov 16 '18 at 14:33
Your information is out of date. Native modules are supported in all browsers with > 7% global market share. Have been for a bit now. And eslint is configurable for that very reason.
– Jared Smith
Nov 16 '18 at 14:33
@JaredSmith mmm.. I'll think about it.. i've tried modules in last google chrome about 2 weeks ago and just got unworking project :) need for more tests
– Nick_Rimer
Nov 16 '18 at 15:03
@JaredSmith mmm.. I'll think about it.. i've tried modules in last google chrome about 2 weeks ago and just got unworking project :) need for more tests
– Nick_Rimer
Nov 16 '18 at 15:03
I'm not trying to paint a rosier picture than exists. I've been using native modules, in production, for over a year (I don't have to support oddball browsers often, 80% of my projects are internal and not public facing). The only problem is third-party integration: most libraries are, if you're lucky, written for webpack (not compatible with current native implementations) or if you're not lucky common js. Very few libraries play nice with native modules.
– Jared Smith
Nov 16 '18 at 15:18
I'm not trying to paint a rosier picture than exists. I've been using native modules, in production, for over a year (I don't have to support oddball browsers often, 80% of my projects are internal and not public facing). The only problem is third-party integration: most libraries are, if you're lucky, written for webpack (not compatible with current native implementations) or if you're not lucky common js. Very few libraries play nice with native modules.
– Jared Smith
Nov 16 '18 at 15:18
|
show 1 more comment
1 Answer
1
active
oldest
votes
See the documentation for no-undef. Add a globals
section to the JS file itself.
/*global someFunction b:true*/
/*eslint no-undef: "error"*/
var a = someFunction();
b = 10;
So I need to contaminate my js-file head instead os .eslintrc.json contamination? It seems to be not so good idea, I think.
– Nick_Rimer
Nov 16 '18 at 14:09
@Nick_Rimer — You have to declare them somewhere, and it either has to be in the configuration for all JS files, in the configuration for this JS file, or by using a module system. The linter can't magic up the difference between a variable declared in another file and one that just has the wrong name.
– Quentin
Nov 16 '18 at 14:15
Wanna ask why there is just no functionality to list file paths to search declarations in, but of course it is a question to eslint developers, not for you..
– Nick_Rimer
Nov 16 '18 at 14:20
@Nick_Rimer whenever you find that something that seems like it should exist does not, in fact, exist, you have either found a tremendous opportunity or a hole in your understanding. Either way it's good for you.
– Jared Smith
Nov 16 '18 at 14:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337525%2feslint-no-undef-rule-many-of-functions-in-another-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
See the documentation for no-undef. Add a globals
section to the JS file itself.
/*global someFunction b:true*/
/*eslint no-undef: "error"*/
var a = someFunction();
b = 10;
So I need to contaminate my js-file head instead os .eslintrc.json contamination? It seems to be not so good idea, I think.
– Nick_Rimer
Nov 16 '18 at 14:09
@Nick_Rimer — You have to declare them somewhere, and it either has to be in the configuration for all JS files, in the configuration for this JS file, or by using a module system. The linter can't magic up the difference between a variable declared in another file and one that just has the wrong name.
– Quentin
Nov 16 '18 at 14:15
Wanna ask why there is just no functionality to list file paths to search declarations in, but of course it is a question to eslint developers, not for you..
– Nick_Rimer
Nov 16 '18 at 14:20
@Nick_Rimer whenever you find that something that seems like it should exist does not, in fact, exist, you have either found a tremendous opportunity or a hole in your understanding. Either way it's good for you.
– Jared Smith
Nov 16 '18 at 14:38
add a comment |
See the documentation for no-undef. Add a globals
section to the JS file itself.
/*global someFunction b:true*/
/*eslint no-undef: "error"*/
var a = someFunction();
b = 10;
So I need to contaminate my js-file head instead os .eslintrc.json contamination? It seems to be not so good idea, I think.
– Nick_Rimer
Nov 16 '18 at 14:09
@Nick_Rimer — You have to declare them somewhere, and it either has to be in the configuration for all JS files, in the configuration for this JS file, or by using a module system. The linter can't magic up the difference between a variable declared in another file and one that just has the wrong name.
– Quentin
Nov 16 '18 at 14:15
Wanna ask why there is just no functionality to list file paths to search declarations in, but of course it is a question to eslint developers, not for you..
– Nick_Rimer
Nov 16 '18 at 14:20
@Nick_Rimer whenever you find that something that seems like it should exist does not, in fact, exist, you have either found a tremendous opportunity or a hole in your understanding. Either way it's good for you.
– Jared Smith
Nov 16 '18 at 14:38
add a comment |
See the documentation for no-undef. Add a globals
section to the JS file itself.
/*global someFunction b:true*/
/*eslint no-undef: "error"*/
var a = someFunction();
b = 10;
See the documentation for no-undef. Add a globals
section to the JS file itself.
/*global someFunction b:true*/
/*eslint no-undef: "error"*/
var a = someFunction();
b = 10;
answered Nov 16 '18 at 12:04
QuentinQuentin
657k728951056
657k728951056
So I need to contaminate my js-file head instead os .eslintrc.json contamination? It seems to be not so good idea, I think.
– Nick_Rimer
Nov 16 '18 at 14:09
@Nick_Rimer — You have to declare them somewhere, and it either has to be in the configuration for all JS files, in the configuration for this JS file, or by using a module system. The linter can't magic up the difference between a variable declared in another file and one that just has the wrong name.
– Quentin
Nov 16 '18 at 14:15
Wanna ask why there is just no functionality to list file paths to search declarations in, but of course it is a question to eslint developers, not for you..
– Nick_Rimer
Nov 16 '18 at 14:20
@Nick_Rimer whenever you find that something that seems like it should exist does not, in fact, exist, you have either found a tremendous opportunity or a hole in your understanding. Either way it's good for you.
– Jared Smith
Nov 16 '18 at 14:38
add a comment |
So I need to contaminate my js-file head instead os .eslintrc.json contamination? It seems to be not so good idea, I think.
– Nick_Rimer
Nov 16 '18 at 14:09
@Nick_Rimer — You have to declare them somewhere, and it either has to be in the configuration for all JS files, in the configuration for this JS file, or by using a module system. The linter can't magic up the difference between a variable declared in another file and one that just has the wrong name.
– Quentin
Nov 16 '18 at 14:15
Wanna ask why there is just no functionality to list file paths to search declarations in, but of course it is a question to eslint developers, not for you..
– Nick_Rimer
Nov 16 '18 at 14:20
@Nick_Rimer whenever you find that something that seems like it should exist does not, in fact, exist, you have either found a tremendous opportunity or a hole in your understanding. Either way it's good for you.
– Jared Smith
Nov 16 '18 at 14:38
So I need to contaminate my js-file head instead os .eslintrc.json contamination? It seems to be not so good idea, I think.
– Nick_Rimer
Nov 16 '18 at 14:09
So I need to contaminate my js-file head instead os .eslintrc.json contamination? It seems to be not so good idea, I think.
– Nick_Rimer
Nov 16 '18 at 14:09
@Nick_Rimer — You have to declare them somewhere, and it either has to be in the configuration for all JS files, in the configuration for this JS file, or by using a module system. The linter can't magic up the difference between a variable declared in another file and one that just has the wrong name.
– Quentin
Nov 16 '18 at 14:15
@Nick_Rimer — You have to declare them somewhere, and it either has to be in the configuration for all JS files, in the configuration for this JS file, or by using a module system. The linter can't magic up the difference between a variable declared in another file and one that just has the wrong name.
– Quentin
Nov 16 '18 at 14:15
Wanna ask why there is just no functionality to list file paths to search declarations in, but of course it is a question to eslint developers, not for you..
– Nick_Rimer
Nov 16 '18 at 14:20
Wanna ask why there is just no functionality to list file paths to search declarations in, but of course it is a question to eslint developers, not for you..
– Nick_Rimer
Nov 16 '18 at 14:20
@Nick_Rimer whenever you find that something that seems like it should exist does not, in fact, exist, you have either found a tremendous opportunity or a hole in your understanding. Either way it's good for you.
– Jared Smith
Nov 16 '18 at 14:38
@Nick_Rimer whenever you find that something that seems like it should exist does not, in fact, exist, you have either found a tremendous opportunity or a hole in your understanding. Either way it's good for you.
– Jared Smith
Nov 16 '18 at 14:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337525%2feslint-no-undef-rule-many-of-functions-in-another-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's generally a good idea to use some kind of module system rather than relying on stuff being in the global scope.
– Jared Smith
Nov 16 '18 at 12:09
Of course modules are great, but if understand correct, there is no modules native support in browsers.. so I need to use module bundlers like webpack to get one source-bundle.js But the problem I've tried to solve is to separate one file to several files. And eslint annoys me.
– Nick_Rimer
Nov 16 '18 at 14:12
Your information is out of date. Native modules are supported in all browsers with > 7% global market share. Have been for a bit now. And eslint is configurable for that very reason.
– Jared Smith
Nov 16 '18 at 14:33
@JaredSmith mmm.. I'll think about it.. i've tried modules in last google chrome about 2 weeks ago and just got unworking project :) need for more tests
– Nick_Rimer
Nov 16 '18 at 15:03
I'm not trying to paint a rosier picture than exists. I've been using native modules, in production, for over a year (I don't have to support oddball browsers often, 80% of my projects are internal and not public facing). The only problem is third-party integration: most libraries are, if you're lucky, written for webpack (not compatible with current native implementations) or if you're not lucky common js. Very few libraries play nice with native modules.
– Jared Smith
Nov 16 '18 at 15:18