question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`no-unused-vars` should not flag constants declared with `const`

See original GitHub issue

What version of ESLint are you using? 2.9.0

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

Please show your full configuration:

{
    "env": {
        "browser":true,
        "es6":true
    },
    "plugins": [
        "html"
    ],
    "rules": {
        "no-mixed-spaces-and-tabs":[2, true],
        "no-redeclare":2,
        "no-use-before-define":[2, "nofunc"],
        "no-unused-vars":1,
        "no-undef":2,
        "eqeqeq":2,
        "consistent-return":1,
        "radix":2,
        "console":0,
        "camelcase":0,
        "strict":0,
        "quotes":[2, "double", "avoid-escape"],
        "new-cap":0,
        "space-infix-ops":0,
        "no-console":0,
        "no-delete-var":0,
        "no-underscore-dangle":0,
        "no-multi-spaces":0,
        "dot-notation":[2, {"allowKeywords": false}],
        "space-unary-ops":1,
        "key-spacing": [1, {"beforeColon": false, "afterColon": true, "mode": "minimum"}],
        "no-empty":2,
        "brace-style": [1, "stroustrup", { "allowSingleLine": true }],
        "keyword-spacing": 2,
        "no-space-before-semi": 0,
        "space-before-function-paren": [2, "never"],
        "no-trailing-spaces": [2, { "skipBlankLines": false }],
        "prefer-const": ["error"]
    }
}

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

const EDGE_OFFSET = 15;

What did you expect to happen? No warnings since EDGE_OFFSET is a constant, not a variable.

What actually happened? Please include the actual, raw output from ESLint.

minimum.js
  1:7  warning  'EDGE_OFFSET' is defined but never used  no-unused-vars

✖ 1 problem (0 errors, 1 warning)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ilyavolodincommented, May 10, 2016

So you are arguing semantics of the name of the rule? Const is a read-only variable (not really completely true in JS, but that’s what it is in other languages).

0reactions
ghengeveldcommented, Aug 4, 2016

Of course I’m not familiar with your codebase and conventions, but nowadays it’s common to use const everywhere, not just for actual (global) constants. If I need a let (or var) I will rewrite my code to not need a let. In general I write all my code in an immutable fashion, so const is the only way to go. This means not just my contants (for example Redux action types) will use const, but also any other variables.

What I’m trying to say is, don’t hold on too tight to your ALL_CAPS convention. It generally doesn’t help readability if your code is sprinkled with all caps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-unused-vars - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unused variables, functions, and function parameters. A variable foo is considered to be used if any of...
Read more >
tslint how to disable error "someVariable is declared but its ...
Any parameter name starting with _ is exempt from the check. Use _myVariable instead of myvariable to remove this warning.
Read more >
How to fix Definition for rule typescript-eslint no-use-before ...
I am new to eslint and I cannot figure out how to solve this issue. The beginning of my imports is always underlined...
Read more >
Disallow modifying variables that are declared using const (no ...
This rule is aimed to flag modifying variables that are declared using const keyword. Examples of incorrect code for this rule: /*eslint no-const-assign:...
Read more >
How to disable "no-unused-vars" in Visual Studio Code (or at ...
I honestly do not think that an unused variable or parameter is on the same level as, say, trying to reassign a constant....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found