-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
reporting 'unused variable' for a globally defined function #659
Comments
The solution to this might be similar to a solution that works for the issue I just posted, #660. |
Yes, this is a real problem but I don't have any good solution in mind. Suggestions are welcomed. |
@antonkovalyov, can you take another look at the suggestions I have in #660? I have an ulterior motive in that I think #660 is still relevant even though jshint already ignores unused function arguments followed by used ones, but a couple of the solutions might be practical for both issues. In particular, an /*exported foo*/
function foo() {
...
} |
I had a look at #660. While similar I do believe these are different; though I agree with @antonkovalyov comments on that topic, keeping the function declarations the same is important. For this issue though I am liking the idea of the |
Not sure how I closed that, sorry. |
How would the global scope ever know about
Because it's not used, nor "exported" |
Can we have an option to ignore unused functions but not other kinds of unused variables? This is especially useful for those of us writing large js libraries, and having to put a zillion |
@huwendy I second that motion. |
@huwendy @JaredCubilla do either of you have an idea of what this might look like, if not the existing |
Is there an option for "exported" in the jshintrc? Or does it always have to be per file? |
If this were allowed in global options, it would be ambiguous. |
Makes sense 👍 |
@rwaldron Eg |
@huwendy like this: |
@rwaldron |
Yes, you're right—I read that but misinterpreted it, thanks for clarifying. |
Sometimes, especially in the browser world, people "export" variables by leaving them global and then concatenating files together. But JSHint doesn't know about that and complains about unused variables. This patch (initially started by @circusbred in jshintGH-726) introduces a new directive, /*exported varA, varB,.. */ that can be used to tell JSHint that variables varA and varB are intentionally global and will be used in other files even if they are unused in the current one. Closes jshintGH-726. Closes jshintGH-659.
Just a thought, while I'm waiting for jslint and other derivatives to catch up and get As to those wanting to make a distinction between unused functions and other types of unused variables, that is mostly useless in my opinion - first because modules might want to export non-function values, and second because even function values may be defined with a |
If the above is the entire contents of a file then I get a JSHint warning
How would I go about allowing this to occur without disabling the unused rule. Such that
reports unused variable 'bar' but not unused variable 'foo'?
The function in question is used by other files just not within the current file.
The text was updated successfully, but these errors were encountered: