Discussion  - 
AngularJS  "code smells"?

I'm jotting down some ideas for improving the WebStorm AngularJS plugin. I figured I might as well include some static code analysis that would suggest improvements.

Does anyone who has experience doing code reviews, etc on AngularJS project have a list of "things to watch out for" or "best practices" they've established. Just trying to get a grasp on some pitfalls that guys who are a new to AngularJS might be falling into.
Miško Hevery's profile photoChris Bates-Keegan's profile photoPawel Kozlowski's profile photoJohn Lindquist's profile photo
John, great to see you on here. I spent last Saturday watching your Angular Youtube videos and learned so much!
Events over $watches.  If I see a lot of events being $broadcast, it smells.
Also, not registering controllers.  Not a stink, but definitely a whiff of sourness out of a wine bottle.
+Mike McElroy Registering controllers would be an interesting Quick Fix.

I'm not sure it's possible to "know" enough about the code to determine $broadcast vs. $watch without understanding what the developer is trying to accomplish.
True, but you're talking about smells, and to me that's not necessarily something that's wrong, per se, but something that raises alarm bells while you're developing.
+Mike McElroy right, I wasn't saying it's not a smell. I'm just talking out loud about how code analysis would handle it.
You might like the AngularJS Livestream from our meetup tonight... the topic is in fact "Best Practices". :) Tune in at 6:45pm PT on youtube.com/angularjs...
+John Lindquist DOM manipulations in a controller would be top on my list. You could probably see if people are grabbing $event.target. Other thing - I see from questions on SO that people are using tons of jQuery in controllers (even calling $.ajax instead of $http) so maybe worth checking as well.
+Naomi Black I'll definitely catch the recording. Make sure to do sound checks :)

+Pawel Kozlowski Good call. Probably won't be able to provide a "quick fix", but at least give them tips on how to improve.
I don't know if a static analysis would be able to determine this but because of the (excellent) decoupling afforded by directives I've been caught out more than once with my-(tag|attribute)-name in the HTML vs my(Tag|Attribute)Name in the directive naming. I've made this mistake more than once and taken a little while to figure out the problem.
Add a comment...