Coding rules and patterns for AngularJS contributors
masterTo maintain consistency, follow these rules:
General Style
- Testing: All features or bug fixes must be accompanied by specs.
- Documentation: All public API methods must be documented using
ngdoc. - Formatting: Follow Google's JavaScript Style Guide, but wrap code at 100 characters and do not use namespaces (use anonymous closures and explicit exports instead).
- Complexity: Prefer simple objects and functions/closures over complex inheritance hierarchies.
- Minification: Use internal aliases that map to the external API to improve minification efficiency.
Provider Configuration Pattern
When adding options to a provider, follow this pattern:
- Getters/Setters: Methods should work as a getter (returns current value when called without arguments) and a setter (returns
thisfor chaining when called with an argument). - Booleans: Use the
<option>Enabled([enabled])naming scheme. - Immutability: For non-primitive options (like objects), copy properties to a new object so the configuration cannot be mutated at runtime.
Error Handling
User-facing errors should be thrown using the minErr function. This provides error IDs, templated messages, and links to detailed descriptions.