UNPKG

1.56 kBJavaScriptView Raw
1/**
2 * limit the number of angular components per file
3 *
4 * The number of AngularJS components in one file should be limited.
5 * The default limit is one.
6 *
7 * ### Options
8 *
9 * - The acceptable number of components. (Default: 1)
10 *
11 * @styleguideReference {johnpapa} `y001` Define 1 component per file
12 * @version 0.11.0
13 * @category bestPractice
14 * @sinceAngularVersion 1.x
15 */
16'use strict';
17
18var angularRule = require('./utils/angular-rule');
19
20
21module.exports = {
22 meta: {
23 schema: [{
24 type: 'integer'
25 }]
26 },
27 create: angularRule(function(context) {
28 var limit = context.options[0] || 1;
29 var count = 0;
30 var msg = 'There may be at most {{limit}} AngularJS {{component}} per file, but found {{number}}';
31
32 function checkLimit(callee) {
33 count++;
34 if (count > limit) {
35 context.report(callee, msg, {
36 limit: limit,
37 component: limit === 1 ? 'component' : 'components',
38 number: count
39 });
40 }
41 }
42
43 return {
44 'angular?animation': checkLimit,
45 'angular?config': checkLimit,
46 'angular?controller': checkLimit,
47 'angular?directive': checkLimit,
48 'angular?factory': checkLimit,
49 'angular?filter': checkLimit,
50 'angular?provider': checkLimit,
51 'angular?run': checkLimit,
52 'angular?service': checkLimit,
53 'angular?component': checkLimit
54 };
55 })
56};