Skip to content
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

no-unused-vars false positive after upgrading to v3.0.0 #6576

Closed
gustavohenke opened this issue Jul 1, 2016 · 6 comments
Closed

no-unused-vars false positive after upgrading to v3.0.0 #6576

gustavohenke opened this issue Jul 1, 2016 · 6 comments
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@gustavohenke
Copy link

What version of ESLint are you using?
3.0.0

What parser (default, Babel-ESLint, etc.) are you using?
Default.

Please show your full configuration:

{
    "root": true,
    "env": {
        "browser": true,
        "es6": true,
        "amd": true,
        "jquery": true
    },
    "globals": {
        "_": false,
        "angular": false,
        "CKEDITOR": false,
        "google": false
    },
    "parserOptions": {
        "ecmaVersion": 6
    },
    "rules": {
        // Possible errors
        "no-dupe-keys":                  2,
        "no-empty":                      1,
        "no-ex-assign":                  1,
        "no-irregular-whitespace":       2,

        // Best practices
        "curly":                       [ 2, "all" ],
        "dot-notation":                [ 2, {
            "allowKeywords": true
        }],
        "dot-location":                [ 2, "property" ],
        "eqeqeq":                      [ 2, "allow-null" ],
        "guard-for-in":                  1,
        "no-else-return":                1,
        "no-labels":                     2,
        "no-extend-native":              2,
        "no-fallthrough":                0,
        "no-lone-blocks":                1,
        "no-loop-func":                  2,
        "no-multi-spaces":               0,
        "no-multi-str":                  2,
        "no-native-reassign":            2,
        "no-param-reassign":             0,
        "no-return-assign":              0,
        "no-unused-expressions":         0,
        "radix":                         1,
        "yoda":                          2,

        // Variables
        "no-undef":                      2,
        "no-unused-vars":                2,
        "no-use-before-define":        [ 2, "nofunc" ],

        // Stylistic issues
        "array-bracket-spacing":       [ 2, "always", {
            "objectsInArrays": false
        }],
        "brace-style":                 [ 2, "1tbs", {
            "allowSingleLine": true
        }],
        "camelcase":                   [ 2, {
            "properties": "never"
        }],
        "comma-spacing":                 2,
        "comma-style":                   2,
        "computed-property-spacing":   [ 2, "always" ],
        "eol-last":                      0,
        "indent":                      [ 2, "tab", {
            "SwitchCase": 1
        }],
        "key-spacing":                   0,
        "lines-around-comment":        [ 2, {
            "allowBlockStart": true
        }],
        "max-nested-callbacks":        [ 1, 5 ],
        "new-parens":                    2,
        "newline-after-var":             0,
        "no-spaced-func":                0,
        "object-curly-spacing":        [ 2, "always" ],
        "one-var":                     [ 2, {
            "initialized":   "never"
        }],
        "quotes":                      [ 2, "double" ],
        "keyword-spacing":             [ 2, {
            "before": true,
            "after": true
        }],
        "space-in-parens":               0,
        "space-infix-ops":               2,
        "space-unary-ops":             [ 2, {
            "words": true,
            "nonwords": false
        }],
        "spaced-comment":              [ 2, "always" ],

        // Legacy
        "max-len":                     [ 2, 150 ]
    }
}

What did you do? Please include the actual source code causing the issue.

var unregisterFooWatcher;
// ...
unregisterFooWatcher = $scope.$watch( "foo", function( foo ) {
    // ...some code..
    unregisterFooWatcher();
});

What did you expect to happen?
Code linted just fine.

What actually happened?

/path/to/file.js
  29:8  error  'unregisterFooWatcher' is defined but never used  no-unused-vars

Seems to be caused by modifications of #6348 and #6535.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jul 1, 2016
@gustavohenke
Copy link
Author

To be clear, our builds started failing a few hours ago because we run npm install -g eslint (no version specified).

For now, I'll just specify version 2..

@nzakas
Copy link
Member

nzakas commented Jul 2, 2016

cc @mysticatea

@nzakas nzakas added bug ESLint is working incorrectly rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Jul 2, 2016
@mysticatea mysticatea self-assigned this Jul 2, 2016
@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jul 2, 2016
@mysticatea
Copy link
Member

Ugh, I'm sorry.
I will fix it.

@doberkofler
Copy link
Contributor

@mysticatea Is this the same false positive I found in eslint 3.0.0 ?

/*eslint no-unused-vars:2*/
let _timer;
function f() {
    _timer = setTimeout(function () {}, _timer ? 100 : 0);
}
f();

reports:

3:5  warning  '_timer' is defined but never used  no-unused-vars

@yphoenix
Copy link

yphoenix commented Jul 3, 2016

This looks like the same bug I'm seeing with:

function foo(){
    'use strict';

    var ref;

    ref = setInterval(
        function(){
            clearInterval(ref);
        }, 10);
}

As soon as I upgraded to 3.0.0

@mysticatea
Copy link
Member

@doberkofler Thank you for the repro code. I added a check to address that pattern to no-unused-vars.
@yphoenix Thank you for the repro code. Yes, it's the same bug. I added the code to tests.

nzakas pushed a commit that referenced this issue Jul 5, 2016
…6579)

* Fix: `no-unused-vars` false positive around callback (fixes #6576)

* Fix: `no-unused-vars` false positive about reuse (fixes #6576)
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

6 participants