Skip to content

Commit ab26de1

Browse files
committed
Merge branch 'LPCmedia-master' into development
2 parents 27f66da + 552a534 commit ab26de1

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

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(){})

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/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',

0 commit comments

Comments
 (0)