Questions tagged [unused-variables]

Use this tag when question related to unused variables issues as warnings

179 questions
130
votes
4 answers

Mark unused parameters in Kotlin

I am defining some functions to be used as callbacks and not all of them use all their parameters. How can I mark unused parameters so that the compiler won't give me warnings about them?
TheTeaMan
  • 2,373
  • 3
  • 15
  • 13
110
votes
6 answers

Standard conventions for indicating a function argument is unused in JavaScript

Are there any standard ways of marking a function argument as unused in JavaScript, analogous to starting a method argument with an underscore in Ruby?
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
101
votes
10 answers

How can I get rid of an "unused variable" warning in Xcode?

I understand exactly why unused variable warnings occur. I don't want to suppress them in general, because they are incredibly useful in most cases. However, consider the following (contrived) code. NSError *error = nil; BOOL saved = [moc…
Gregory Higley
  • 15,923
  • 9
  • 67
  • 96
91
votes
12 answers

Unused parameter in c++11

In c++03 and earlier to disable compiler warning about unused parameter I usually use such code: #define UNUSED(expr) do { (void)(expr); } while (0) For example int main(int argc, char *argv[]) { UNUSED(argc); UNUSED(argv); return…
inkooboo
  • 2,904
  • 1
  • 19
  • 24
53
votes
5 answers

“Variable is never assigned” warning in IntelliJ IDEA can be suppressed only "partially"

Java EE + IntelliJ Idea 2016.3: I've written a class and declared a private field with a @Inject annotation. I have successfully got rid of the "unused declaration" notification from the "inspection results" window by adding javax.inject.Inject to…
rychu
  • 896
  • 1
  • 7
  • 16
47
votes
3 answers

Skip type check on unused parameters

When I compile my typescript project, I'm using the noImplicitAny option so that I won't forget to specify the types on my variables and arguments. However sometimes you have arguments that you don't use. For example: jQuery.ajaxTransport("+*",…
Yvo
  • 18,681
  • 11
  • 71
  • 90
45
votes
5 answers

Silence PyLint warning about unused variables for string interpolation

The say module brings string interpolation to Python, like this: import say def f(a): return say.fmt("The value of 'a' is {a}") However, PyLint complains that the variable 'a' is never used. This is a problem because my code uses say.fmt…
Eleno
  • 2,864
  • 3
  • 33
  • 39
44
votes
5 answers

Why do underscore prefixed variables exist?

I am learning Rust, and came across the fact that adding an underscore at the beginning of a variable name will make the compiler not warn if it is unused. I am wondering why that feature exists, since unused variables are frowned upon.
Sir Platypus
  • 543
  • 1
  • 4
  • 9
21
votes
3 answers

How to detect unused variables in Typescript?

Is there a way to detect unused variables in Typescript (something like ESLint in Javascript)?
Damjan Pavlica
  • 31,277
  • 10
  • 71
  • 76
19
votes
3 answers

Why the compiler does not issue a warning when an object std::vector is declared but never used?

#include class Object { }; int main() { Object myObject; std::vector myVector; } Compiler emits: warning: unused variable 'myObject' [-Wunused-variable] No warning for myVector. Why? Is there any way to enable this?
Jovini
  • 191
  • 4
15
votes
5 answers

Unnamed loop variable in range-based for loop?

Is there any way to not "use" the loop variable in a range-based for loop, but also avoid compiler warnings about it being unused? For context, I'm trying to do something like the following. I have "treat warnings as errors" enabled, and I'd rather…
Karu
  • 4,512
  • 4
  • 30
  • 31
14
votes
2 answers

structured bindings and range-based-for; supress unused warning in gcc

I want to traverse a map using structure bindings, ignoring the key: for (auto& [unused, val] : my_map) do_something(val); I have tried different options with gcc-7.2.0: // The warning is issued for ([[maybe_unused]] auto& [unused, val] :…
ABu
  • 10,423
  • 6
  • 52
  • 103
13
votes
3 answers

Scala tool to remove all unused code

I am writing a Scala plugin for an editor I use that would highlight all unused code paths (could be unused defs, vals, classes and implicits), and give the user an option to yank them out of the .scala file. How can I do this? To simplify the…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
12
votes
5 answers

VS code doesn't gray out unused variables

As far as I know it seems this is the setting you enter in your settings.json to enable unused variables & imports that aren't used to appear grayed out. "editor.showUnused": true, I do get an underline and if you hover I get an underline and…
Antonio Pavicevac-Ortiz
  • 7,239
  • 17
  • 68
  • 141
12
votes
4 answers

Visual Studio Code: How to detect dead typescript code?

There are tslint rules available for private method. But How can I find out if the public method is not used anywhere in the project and hence candidate for the dead code. I am using Visual studio code for Typescript.
Pramod
  • 191
  • 2
  • 2
  • 6
1
2 3
11 12