component-limit - limit the number of angular components per file

February 26, 2018 ยท View on GitHub

The number of AngularJS components in one file should be limited. The default limit is one.

  • The acceptable number of components. (Default: 1)

Rule based on Angular 1.x

Styleguide Reference

Examples

The following patterns are considered problems with default config;

/*eslint angular/component-limit: 2*/

// invalid
angular.module('myModule').controller('ControllerOne', function() {
    // ...
}).directive('directiveTwo', function() {
    // ...
}); // error: There may be at most 1 AngularJS component per file, but found 2

The following patterns are not considered problems with default config;

/*eslint angular/component-limit: 2*/

// valid
angular.module('myModule').controller('SomeController', function() {
    // ...
});

// valid
angular.module('myModule').directive('myDirective', function() {
    // ...
});

The following patterns are considered problems when configured 3:

/*eslint angular/component-limit: [2,3]*/

// invalid
angular.module('myModule').controller('ControllerOne', function() {
    // ...
}).directive('directiveTwo', function() {
    // ...
}).factory('serviceThree', function() {
    // ...
}).filter('filterFour', function() {
    // ...
}); // error: There may be at most 3 AngularJS components per file, but found 4

The following patterns are not considered problems when configured 3:

/*eslint angular/component-limit: [2,3]*/

// valid
angular.module('myModule').controller('ControllerOne', function() {
    // ...
}).directive('directiveTwo', function() {
    // ...
}).factory('serviceThree', function() {
    // ...
});

Version

This rule was introduced in eslint-plugin-angular 0.11.0