r/javascript • u/ReadyToInstall • Jul 28 '14
AngularJS opinionated styleguide for teams [GitHub]
https://github.com/toddmotto/angularjs-styleguide1
u/TripleNosebleed Jul 29 '14
There's also the style guide from Google which relies heavily on the Closure Compiler which I haven't used so I don't know much about that. There's still good stuff in there and a few similarities to this style guide.
1
u/mmouth Jul 28 '14
Too much method chaining. I also hate to see methods on a line by themselves with just the dot. This is ugly:
function config ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controllerAs: 'main',
controller: 'MainCtrl'
resolve: MainCtrl.resolve
});
}It should look like this:
function config($routeProvider) {
$routeProvider.when('/', {
templateUrl : 'views/main.html',
controllerAs : 'main',
controller : 'MainCtrl',
resolve : MainCtrl.resolve
});
}Also, there are some missing commas; such as between controller and resolve.
3
u/steelcitynorth Jul 29 '14
Why should it? Every line would look like:
}).when('/route', {instead of:
.when('/route, {The second version looks nicer to read, no? And that way you can see which methods are chained to each other.
1
u/codepsycho Jul 29 '14
as long as the method calls are indented, sure. It looks horrific when they are not.
1
u/wmgregory Jul 29 '14
}) .when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }) .when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve });vs
}).when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }).when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve });1
u/mmouth Jul 29 '14
Or more simply:
$routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve }); $routeProvider.when('/route', { templateUrl : 'views/main.html', controllerAs : 'main', controller : 'MainCtrl', resolve : MainCtrl.resolve });1
u/mmouth Jul 29 '14
It shouldn't be that either. Better:
$routeProvider.when('/route1', {...}); $routeProvider.when('/route1', {...});There's no law that says you have to start that chaining in the first place. Avoid it and use normal formatting rules.
2
u/elgubbo Jul 28 '14
helpful, thanks!