Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/file-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ app.factory('myUtils', function() {});
// example - valid: true, filename: "src/app/awesomeModule/beautifulDirective.js"
app.directive('beautifulDirective', function() {});

// example - valid: true, filename: "src/app/awesomeModule/beautifulComponent.js"
app.component('beautifulComponent', {});

// example - valid: false, filename: "src/app/filters.js", errorMessage: "Filename must be \"usefulFilter.js\""
app.filter('usefulFilter', function() {});

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

// example - valid: true, options: [{"typeSeparator":"dot", "ignorePrefix": "ui."}], filename: "src/app/userUtils.service.js"
angular.factory('ui.UserUtils', uiUserUtils)

// example - valid: true, options: [{"typeSeparator":"dot", "ignorePrefix": "ui."}], filename: "src/app/utils.module.js"
angular.module('ui.utils', function(){})
7 changes: 5 additions & 2 deletions rules/file-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ module.exports = (function() {
factory: 'service',
provider: 'service',
value: 'service',
constant: 'constant'
constant: 'constant',
component: 'component'
};

var filenameUtil = {
Expand All @@ -57,7 +58,9 @@ module.exports = (function() {
return name;
},
removePrefix: function(name, options) {
if (new RegExp('^' + options.ignorePrefix + '[A-Z]').test(name)) {
var regName = '^' + options.ignorePrefix.replace(/[\.]/g, '\\$&');
regName += options.ignorePrefix.indexOf('\.') === -1 ? '[A-Z]' : '[a-zA-z]';
if (new RegExp(regName).test(name)) {
return this.firstToLower(name.slice(options.ignorePrefix.length));
}
return name;
Expand Down
41 changes: 41 additions & 0 deletions test/file-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ eslintTester.run('file-name', rule, {
// basic directive
filename: 'beautifulDirective.js',
code: 'app.directive("beautifulDirective", function() {});'
}, {
// basic component
filename: 'beautifulComponent.js',
code: 'app.component("beautifulComponent", {});'
}, {
// typeSeparator dot with filter
filename: 'src/app/myFilter.filter.js',
Expand Down Expand Up @@ -136,6 +140,33 @@ eslintTester.run('file-name', rule, {
ignoreTypeSuffix: true,
ignorePrefix: 'xp'
}]
}, {
// ignorePrefix xp with regex
filename: 'src/app/asset.service.js',
code: 'angular.factory("xp.AssetService", xpAssetService)',
options: [{
typeSeparator: 'dot',
ignoreTypeSuffix: true,
ignorePrefix: 'xp.'
}]
}, {
// ignorePrefix xp in module name
filename: 'src/app/core.module.js',
code: 'angular.module("xp.core", function(){})',
options: [{
typeSeparator: 'dot',
ignoreTypeSuffix: true,
ignorePrefix: 'xp.'
}]
}, {
// ignorePrefix xp in main module name
filename: 'src/app/xp.module.js',
code: 'angular.module("xp", function(){})',
options: [{
typeSeparator: 'dot',
ignoreTypeSuffix: true,
ignorePrefix: 'xp.'
}]
}, {
// ignorePrefix st with typeSeparator dash
filename: 'src/app/appUtils-service.js',
Expand Down Expand Up @@ -224,6 +255,16 @@ eslintTester.run('file-name', rule, {
ignorePrefix: 'xp'
}],
errors: [{message: 'Filename must be "asset.service.js"'}]
}, {
// ignorePrefix xp.
filename: 'src/app/xpAsset.service.js',
code: 'angular.factory("xp.AssetService", xpAssetService)',
options: [{
typeSeparator: 'dot',
ignoreTypeSuffix: true,
ignorePrefix: 'xp.'
}],
errors: [{message: 'Filename must be "asset.service.js"'}]
}, {
// alphanumeric nameStyle dash and typeSeparator dash with service
filename: 'src/app/app2utils-service.js',
Expand Down