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

Provide info about annotated functions #42

Closed
mgol opened this issue Jul 14, 2014 · 5 comments
Closed

Provide info about annotated functions #42

mgol opened this issue Jul 14, 2014 · 5 comments

Comments

@mgol
Copy link

mgol commented Jul 14, 2014

This is a loose idea but I often add a service to dependencies of another one and then remove its uses but forget to remove the injection. Now, linters often have an option to report unused parameters of functions not only at the end of them, e.g. see:
http://eslint.org/docs/rules/no-unused-vars.html
with {"args": "all"} but then I'd have lots of false positives since in case of event handlers, replace functions on strings etc. we're sometimes interested in a second parameter but the first still has to be there.

Since ng-annotate already figures out which functions need to be annotated, I wonder if it was possible to pass this info along in some ways so that it'd be possible to check for unused injections in outside projects.

Or maybe ng-annotate could do this checking on its own? It rarely makes sense to inject components that aren't used in the code after all...

@jrencz
Copy link

jrencz commented Jul 14, 2014

splitting ngAnnotate into 2 separate modules might help to do the job. The first would be responsible for finding functions that should get annotated (including the ones annotated via explicit annotations which will be great!). The second would do the processing.

After the first part of the task is done a list of functions to be annotated (perhaps as parts of the AST) to do the unused injection checking. This way it'll be easy to build ESlint rule for performing such checking.

@mgol
Copy link
Author

mgol commented Jul 14, 2014

Maybe "easy" is too much said since ESLint currently doesn't accept custom AST as input but always parses with its own Esprima copy but maybe it'll gain such possibility in the nearby future.

@omsmith
Copy link
Collaborator

omsmith commented Jul 14, 2014

Haha, maybe not easy, but once you have the scanner and the output in place, I could see an nglint tool or similar being quickly put together to give those sorts of warnings which wouldn't necessarily belong within ng-annotate

@olov
Copy link
Owner

olov commented Jul 14, 2014

It would be possible for ng-annotate to turn

angular.module("MyMod").controller("MyCtrl", function($scope, $timeout) {
});

into

angular.module("MyMod").controller("MyCtrl", /*@ngInject*/ function($scope, $timeout) {
});

for all declaration forms it understands, given some switch. Then a tool such as eslint or defs can do whatever it wants with it.

FWIW, I'd also recommend exploring more generic (not coupled to Angular) approaches to linting unused function parameters. Have you considered a naming convention where any unused parameter (say in an event-handler) starts with an _, just as an example?

@olov
Copy link
Owner

olov commented Jun 8, 2016

#245

@olov olov closed this as completed Oct 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants