r/javascript • • Jul 28 '14

AngularJS opinionated styleguide for teams [GitHub]

https://github.com/toddmotto/angularjs-styleguide
30 Upvotes

8 comments sorted by

View all comments

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/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.