-3

I'm currently using JSHint and JSCS (javascript code style checker) but none of them can detect this kind of unused variables:

describe('XX', function () {

  var XXunused;
  beforeEach(inject(function ($injector) {
    XXunused = $injector.get('XXunused');
  }));

  // XXunused is (as the name says) not used in any other way in this block.

});

Someone knows any tool that can flag automatically these variables?

ernestoalejo
  • 853
  • 1
  • 12
  • 23
  • Flagged (too broad), further reading http://stackoverflow.com/help/how-to-ask – gmo Sep 20 '14 at 16:53
  • But you're using it for an assignment? – Bergi Sep 20 '14 at 17:01
  • No JS lint tool could pick this up. You can only see that the variable isn't used at run time, if the call back isn't used. – ShaneQful Sep 20 '14 at 17:07
  • 1
    @gmo too broad? I'm asking specifically for a tool giving the code I want to detect... It's not an opinion or something. @Bergi, what type of assigment could this be? It's a cutted down code from my own unit tests for an angular project. @ShaneQful The beforeEach callback it's always called, it's the same problem as `var a = 5;` (unused variable) against `var a; a = 5;` (no errors) – ernestoalejo Sep 20 '14 at 17:32
  • ...testing that last two lines of code I said in this website: http://www.jshint.com/ – ernestoalejo Sep 20 '14 at 17:33
  • @gmo This is a useful question, and ernestoalejo did know exactly how to ask it. I faced the same case and I still don't know how to make it work. – ahmehri Feb 10 '16 at 11:36

1 Answers1

2

There is analytics tools called Esprima. Please take a look at the following links:

http://tobyho.com/2013/12/02/fun-with-esprima/

https://gist.github.com/Benvie/4657032

http://ariya.ofilabs.com/2012/11/polluting-and-unused-javascript-variables.html

You should be familiar with nodejs. Its very easier to use Esprima in nodejs.

sadrzadehsina
  • 1,331
  • 13
  • 26
  • If I go down the route of doing it myself I don't know yet if I want a fully analysis tool that parses javascript or something simpler that parses every line and search for uses (it's only for this case, nothing more, nothing less). Anyway it's a good suggestion, thanks! I'm going to wait a day to see if there are more comments. If not, I will accept your answer. – ernestoalejo Sep 20 '14 at 18:52