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

unused function params #996

Closed
MiguelCastillo opened this Issue Apr 9, 2013 · 1 comment

Comments

Projects
None yet
1 participant
@MiguelCastillo
Copy link

MiguelCastillo commented Apr 9, 2013

It seems like this topic of unused parameters has been worked on and issues reported a bit... But I really didn't see anything that covered my particular case.

If you run the bit of code below against JSHint 1.1.0 - master

define(function (require, exports, module) {
});

Only "module" parameter will triggered an unused warning. Older versions of JSHint reported all three parameters, so it seems like this is a regression.

I do set the flag "unused": true

@MiguelCastillo

This comment has been minimized.

Copy link

MiguelCastillo commented Apr 9, 2013

Actually, unused variables seem to be causing issues as well...

define(function (require, exports, module) {
var test = {};
});

The code above will not report "test"

I ended up debugging a bit without knowing whether or not these items should really be reported as unused. I came with a couple of adjustments and things are being reported as I expect them.

            var warnable_types = {
                "var": ["var"],
                "param": ["var", "param"],
                "last-param": ["var", "last-param"],
                "strict": ["var", "param", "last-param"]
            };

            if (unused_opt) {
                if (warnable_types[type] && warnable_types[type].indexOf(type) !== -1) {
                    warningAt("W098", line, chr, name);
                }
            }

This is the old code

            var warnable_types = {
                "vars": ["var"],
                "last-param": ["var", "last-param"],
                "strict": ["var", "param", "last-param"]
            };

            if (unused_opt) {
                if (warnable_types[unused_opt] && warnable_types[unused_opt].indexOf(type) !== -1) {
                    warningAt("W098", line, chr, name);
                }
            }

I could do a pull request if you think this could be a viable solution.

@valueof valueof closed this in 75514cb May 8, 2013

jugglinmike added a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014

Fix a regression with unused:true not working properly.
1.1.0 introduced a regression where unused:true behavior was changed.
It would only warn about unused variables if the variable was the last
formal parameter. What we want instead is to ignore all unused variables
before a used one but not after. This commit fixes that.

Closes jshintGH-996.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment