diff --git a/examples/file-name.js b/examples/file-name.js index 1f4e3b48..47c1a71b 100644 --- a/examples/file-name.js +++ b/examples/file-name.js @@ -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() {}); @@ -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(){}) \ No newline at end of file diff --git a/rules/file-name.js b/rules/file-name.js index d8fef504..09d3f286 100644 --- a/rules/file-name.js +++ b/rules/file-name.js @@ -35,7 +35,8 @@ module.exports = (function() { factory: 'service', provider: 'service', value: 'service', - constant: 'constant' + constant: 'constant', + component: 'component' }; var filenameUtil = { @@ -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; diff --git a/test/file-name.js b/test/file-name.js index 68e8a691..f31a7adc 100644 --- a/test/file-name.js +++ b/test/file-name.js @@ -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', @@ -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', @@ -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',