It appears the Batarang plugin for Chrome has just updated. A new feature Angular Hint
is added and gave me a bunch of warnings today. And there is an instruction that says:
Name controllers according to best practices (9551)
Controller names should start with an uppercase character and end with the suffix Controller. For example: UserController.
Consider renaming homeController to HomeController.
Haven't we Angular developers always use camel-cased names for JavaScript object? Anyone can tell us why Batarang prefers the pascal case instead?
And more questions:
Batarang suggests this, as controller functions are actually constructor functions, and constructor functions begin - by convention - with an uppercase character in JavaScript.
This is different from other artefacts, such as filters or services. They are written using a lowercase character, as they are not treated as constructors.
For controllers, it actually makes a lot of sense, as you may want to have multiple instances of a single controller within one single website.
In JavaScript, it's actually best practice to lowercase everything, except constructors: This way the developer knows when to use new
with a function and when not to use it. The underlying problem is that technically there's no difference between a function and a constructor in JavaScript. Both are just functions, they just deal differently with the this
keyword (and this is what new
influences under the hoods).
For the "best practices" part… I'd go with the Angular documentation on how to define controllers. There it says that it's a constructor (although, to be true, it's quite hidden).
As for how to turn it off… no, I'm sorry, I don't know whether this is actually possible (and if so, I don't know how to). On the other hand, I would recommend to ask yourself if you really want to do it differently, if there IS a common best practice.