Looking for a package to highlight unused variables in file


#1

Hi,

It’s pretty clear, in my files, I’d like to see if any variable is currently useless (nowhere in the file). No matter how (custom font color, gutter color…).

I didn’t find anything about this with the keywords “unused variables”.

Is that a good idea?

Bests


#2

Depending on what language you’re using, I would suggest looking at one of the lint packages such as atom-lint.


#3

Hmm, this definitely seems like a good idea, but there’s a lot of issues with this:

  1. What variables are and how they are defined is totally dependent of the language.
  2. The scope of a variable needs to be known by the package that evaluate its usage. What if I have an argument that have the same name as a variable define elsewhere in the file? Did it consider using that argument inside the function count as usage of the variable defined outside the function?
  3. The package will have to be aware of the build process used to produce the final code. What if I concatenate all my js files in one, and the first contains all my top level variables? etc…

Definitely an IDE-like feature that is not as easy to implement as it sound.


#4
  • What about a “template” for each language. For instance, in Javascript, store all values prefixed by “var” and search entries in the file, but skip lines in comments, strings… I’m not an expert I know it is hard.
  • Yes hard to handle with scopes…
  • How it works in phpstorm?

#5

I already have https://github.com/AtomLinter/Linter with https://github.com/AtomLinter/linter-jshint. Any potential conflict with another linter?


#6

I don’t know, I haven’t tried installing more than one at a time :laughing: I would assume they would conflict in some way.