Skip to content

Commit 8b65dc1

Browse files
Merge pull request #400 from Gillespie59/development
1.3.0
2 parents 2326c7f + 89b95f1 commit 8b65dc1

File tree

10 files changed

+125
-6
lines changed

10 files changed

+125
-6
lines changed

docs/di-order.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ The following patterns are **not** considered problems with default config;
4646
// ...
4747
});
4848

49+
The following patterns are **not** considered problems when configured `true` and `"case_sensitive"`:
50+
51+
/*eslint angular/di-order: [2,true,"case_sensitive"]*/
52+
53+
// valid
54+
angular.module("").animation("", function(Authentication, analytics) {
55+
// ...
56+
});
57+
58+
The following patterns are **not** considered problems when configured `true` and `"case_insensitive"`:
59+
60+
/*eslint angular/di-order: [2,true,"case_insensitive"]*/
61+
62+
// valid
63+
angular.module("").animation("", function(analytics, Authentication) {
64+
// ...
65+
});
66+
4967
The following patterns are considered problems when configured `true`:
5068

5169
/*eslint angular/di-order: [2,true]*/

docs/file-name.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ The following patterns are **not** considered problems with default config;
3737
// valid with filename: src/app/awesomeModule/beautifulDirective.js
3838
app.directive('beautifulDirective', function() {});
3939

40+
// valid with filename: src/app/awesomeModule/beautifulComponent.js
41+
app.component('beautifulComponent', {});
42+
4043
The following patterns are considered problems when configured `{"typeSeparator":"dot"}`:
4144

4245
/*eslint angular/file-name: [2,{"typeSeparator":"dot"}]*/
@@ -110,6 +113,16 @@ The following patterns are **not** considered problems when configured `{"typeSe
110113
// valid with filename: src/app/userUtils.service.js
111114
angular.factory('uiUserUtils', uiUserUtils)
112115

116+
The following patterns are **not** considered problems when configured `{"typeSeparator":"dot","ignorePrefix":"ui."}`:
117+
118+
/*eslint angular/file-name: [2,{"typeSeparator":"dot","ignorePrefix":"ui."}]*/
119+
120+
// valid with filename: src/app/userUtils.service.js
121+
angular.factory('ui.UserUtils', uiUserUtils)
122+
123+
// valid with filename: src/app/utils.module.js
124+
angular.module('ui.utils', function(){})
125+
113126
## Version
114127

115128
This rule was introduced in eslint-plugin-angular 0.7.0

examples/di-order.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ angular.module('myModule').factory('myService', function(CONFIG, URLs, authServi
1313
// ...
1414
});
1515

16+
// example - valid: true, options: [true, "case_sensitive"]
17+
angular.module("").animation("", function(Authentication, analytics) {
18+
// ...
19+
});
20+
21+
// example - valid: true, options: [true, "case_insensitive"]
22+
angular.module("").animation("", function(analytics, Authentication) {
23+
// ...
24+
});
25+
1626
// example - valid: false, errorMessage: "Injected values should be sorted alphabetically"
1727
angular.module('myModule').factory('myService', function($q, $http) {
1828
// ...

examples/file-name.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ app.factory('myUtils', function() {});
1111
// example - valid: true, filename: "src/app/awesomeModule/beautifulDirective.js"
1212
app.directive('beautifulDirective', function() {});
1313

14+
// example - valid: true, filename: "src/app/awesomeModule/beautifulComponent.js"
15+
app.component('beautifulComponent', {});
16+
1417
// example - valid: false, filename: "src/app/filters.js", errorMessage: "Filename must be \"usefulFilter.js\""
1518
app.filter('usefulFilter', function() {});
1619

@@ -51,3 +54,8 @@ app.directive('userProfileDirective', function() {});
5154
// example - valid: true, options: [{"typeSeparator":"dot", "ignorePrefix": "ui"}], filename: "src/app/userUtils.service.js"
5255
angular.factory('uiUserUtils', uiUserUtils)
5356

57+
// example - valid: true, options: [{"typeSeparator":"dot", "ignorePrefix": "ui."}], filename: "src/app/userUtils.service.js"
58+
angular.factory('ui.UserUtils', uiUserUtils)
59+
60+
// example - valid: true, options: [{"typeSeparator":"dot", "ignorePrefix": "ui."}], filename: "src/app/utils.module.js"
61+
angular.module('ui.utils', function(){})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-angular",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"description": "ESLint rules for AngularJS projects",
55
"main": "index.js",
66
"scripts": {

rules/di-order.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@
1111
'use strict';
1212

1313
var angularRule = require('./utils/angular-rule');
14-
14+
var caseSensitive = 'case_sensitive';
1515

1616
module.exports = angularRule(function(context) {
1717
var stripUnderscores = context.options[0] !== false;
18+
var caseSensitiveOpt = (context.options[1] || caseSensitive) === caseSensitive;
1819

1920
function checkOrder(callee, fn) {
2021
if (!fn || !fn.params) {
2122
return;
2223
}
2324
var args = fn.params.map(function(arg) {
25+
var formattedArg = arg.name;
2426
if (stripUnderscores) {
25-
return arg.name.replace(/^_(.+)_$/, '$1');
27+
formattedArg = formattedArg.replace(/^_(.+)_$/, '$1');
2628
}
27-
return arg.name;
29+
return caseSensitiveOpt ? formattedArg : formattedArg.toLowerCase();
2830
});
2931
var sortedArgs = args.slice().sort();
3032
sortedArgs.some(function(value, index) {

rules/file-name.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ module.exports = (function() {
3535
factory: 'service',
3636
provider: 'service',
3737
value: 'service',
38-
constant: 'constant'
38+
constant: 'constant',
39+
component: 'component'
3940
};
4041

4142
var filenameUtil = {
@@ -57,7 +58,9 @@ module.exports = (function() {
5758
return name;
5859
},
5960
removePrefix: function(name, options) {
60-
if (new RegExp('^' + options.ignorePrefix + '[A-Z]').test(name)) {
61+
var regName = '^' + options.ignorePrefix.replace(/[\.]/g, '\\$&');
62+
regName += options.ignorePrefix.indexOf('\.') === -1 ? '[A-Z]' : '[a-zA-z]';
63+
if (new RegExp(regName).test(name)) {
6164
return this.firstToLower(name.slice(options.ignorePrefix.length));
6265
}
6366
return name;

test/di-order.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,27 @@ eslintTester.run('di-order', rule, {
4141
{
4242
code: 'it(inject(function(_$httpBackend_, _$http_) {}));',
4343
options: [false]
44+
},
45+
{
46+
code: 'angular.module("").animation("", function(Authentication, analytics) {});',
47+
options: [true, 'case_sensitive']
48+
},
49+
{
50+
code: 'angular.module("").animation("", function(analytics, Authentication) {});',
51+
options: [true, 'case_insensitive']
4452
}
4553
].concat(commonFalsePositives),
4654
invalid: [
55+
{
56+
code: 'angular.module("").animation("", function(Authentication, analytics) {});',
57+
errors: [{message: 'Injected values should be sorted alphabetically'}],
58+
options: [true, 'case_insensitive']
59+
},
60+
{
61+
code: 'angular.module("").animation("", function(analytics, Authentication) {});',
62+
errors: [{message: 'Injected values should be sorted alphabetically'}],
63+
options: [true, 'case_sensitive']
64+
},
4765
// animation
4866
{
4967
code: 'angular.module("").animation("", function($q, $http) {});',

test/file-name.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ eslintTester.run('file-name', rule, {
3838
// basic directive
3939
filename: 'beautifulDirective.js',
4040
code: 'app.directive("beautifulDirective", function() {});'
41+
}, {
42+
// basic component
43+
filename: 'beautifulComponent.js',
44+
code: 'app.component("beautifulComponent", {});'
4145
}, {
4246
// typeSeparator dot with filter
4347
filename: 'src/app/myFilter.filter.js',
@@ -136,6 +140,33 @@ eslintTester.run('file-name', rule, {
136140
ignoreTypeSuffix: true,
137141
ignorePrefix: 'xp'
138142
}]
143+
}, {
144+
// ignorePrefix xp with regex
145+
filename: 'src/app/asset.service.js',
146+
code: 'angular.factory("xp.AssetService", xpAssetService)',
147+
options: [{
148+
typeSeparator: 'dot',
149+
ignoreTypeSuffix: true,
150+
ignorePrefix: 'xp.'
151+
}]
152+
}, {
153+
// ignorePrefix xp in module name
154+
filename: 'src/app/core.module.js',
155+
code: 'angular.module("xp.core", function(){})',
156+
options: [{
157+
typeSeparator: 'dot',
158+
ignoreTypeSuffix: true,
159+
ignorePrefix: 'xp.'
160+
}]
161+
}, {
162+
// ignorePrefix xp in main module name
163+
filename: 'src/app/xp.module.js',
164+
code: 'angular.module("xp", function(){})',
165+
options: [{
166+
typeSeparator: 'dot',
167+
ignoreTypeSuffix: true,
168+
ignorePrefix: 'xp.'
169+
}]
139170
}, {
140171
// ignorePrefix st with typeSeparator dash
141172
filename: 'src/app/appUtils-service.js',
@@ -224,6 +255,16 @@ eslintTester.run('file-name', rule, {
224255
ignorePrefix: 'xp'
225256
}],
226257
errors: [{message: 'Filename must be "asset.service.js"'}]
258+
}, {
259+
// ignorePrefix xp.
260+
filename: 'src/app/xpAsset.service.js',
261+
code: 'angular.factory("xp.AssetService", xpAssetService)',
262+
options: [{
263+
typeSeparator: 'dot',
264+
ignoreTypeSuffix: true,
265+
ignorePrefix: 'xp.'
266+
}],
267+
errors: [{message: 'Filename must be "asset.service.js"'}]
227268
}, {
228269
// alphanumeric nameStyle dash and typeSeparator dash with service
229270
filename: 'src/app/app2utils-service.js',

test/no-private-call.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ eslintTester.run('no-private-call', rule, {
3838
options: [{
3939
allow: ['$$watchers']
4040
}]
41+
},
42+
{
43+
code: 'node.$$treeLevel',
44+
options: [{
45+
allow: ['$$treeLevel']
46+
}]
4147
}
4248

4349
].concat(commonFalsePositives),

0 commit comments

Comments
 (0)