Skip to content

Commit

Permalink
Merge pull request #400 from Gillespie59/development
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
EmmanuelDemey committed Jun 27, 2016
2 parents 2326c7f + 89b95f1 commit 8b65dc1
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 6 deletions.
18 changes: 18 additions & 0 deletions docs/di-order.md
Expand Up @@ -46,6 +46,24 @@ The following patterns are **not** considered problems with default config;
// ...
});

The following patterns are **not** considered problems when configured `true` and `"case_sensitive"`:

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

// valid
angular.module("").animation("", function(Authentication, analytics) {
// ...
});

The following patterns are **not** considered problems when configured `true` and `"case_insensitive"`:

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

// valid
angular.module("").animation("", function(analytics, Authentication) {
// ...
});

The following patterns are considered problems when configured `true`:

/*eslint angular/di-order: [2,true]*/
Expand Down
13 changes: 13 additions & 0 deletions docs/file-name.md
Expand Up @@ -37,6 +37,9 @@ The following patterns are **not** considered problems with default config;
// valid with filename: src/app/awesomeModule/beautifulDirective.js
app.directive('beautifulDirective', function() {});

// valid with filename: src/app/awesomeModule/beautifulComponent.js
app.component('beautifulComponent', {});

The following patterns are considered problems when configured `{"typeSeparator":"dot"}`:

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

The following patterns are **not** considered problems when configured `{"typeSeparator":"dot","ignorePrefix":"ui."}`:

/*eslint angular/file-name: [2,{"typeSeparator":"dot","ignorePrefix":"ui."}]*/

// valid with filename: src/app/userUtils.service.js
angular.factory('ui.UserUtils', uiUserUtils)

// valid with filename: src/app/utils.module.js
angular.module('ui.utils', function(){})

## Version

This rule was introduced in eslint-plugin-angular 0.7.0
Expand Down
10 changes: 10 additions & 0 deletions examples/di-order.js
Expand Up @@ -13,6 +13,16 @@ angular.module('myModule').factory('myService', function(CONFIG, URLs, authServi
// ...
});

// example - valid: true, options: [true, "case_sensitive"]
angular.module("").animation("", function(Authentication, analytics) {
// ...
});

// example - valid: true, options: [true, "case_insensitive"]
angular.module("").animation("", function(analytics, Authentication) {
// ...
});

// example - valid: false, errorMessage: "Injected values should be sorted alphabetically"
angular.module('myModule').factory('myService', function($q, $http) {
// ...
Expand Down
8 changes: 8 additions & 0 deletions examples/file-name.js
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(){})
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-angular",
"version": "1.2.2",
"version": "1.3.0",
"description": "ESLint rules for AngularJS projects",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 5 additions & 3 deletions rules/di-order.js
Expand Up @@ -11,20 +11,22 @@
'use strict';

var angularRule = require('./utils/angular-rule');

var caseSensitive = 'case_sensitive';

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

function checkOrder(callee, fn) {
if (!fn || !fn.params) {
return;
}
var args = fn.params.map(function(arg) {
var formattedArg = arg.name;
if (stripUnderscores) {
return arg.name.replace(/^_(.+)_$/, '$1');
formattedArg = formattedArg.replace(/^_(.+)_$/, '$1');
}
return arg.name;
return caseSensitiveOpt ? formattedArg : formattedArg.toLowerCase();
});
var sortedArgs = args.slice().sort();
sortedArgs.some(function(value, index) {
Expand Down
7 changes: 5 additions & 2 deletions rules/file-name.js
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
18 changes: 18 additions & 0 deletions test/di-order.js
Expand Up @@ -41,9 +41,27 @@ eslintTester.run('di-order', rule, {
{
code: 'it(inject(function(_$httpBackend_, _$http_) {}));',
options: [false]
},
{
code: 'angular.module("").animation("", function(Authentication, analytics) {});',
options: [true, 'case_sensitive']
},
{
code: 'angular.module("").animation("", function(analytics, Authentication) {});',
options: [true, 'case_insensitive']
}
].concat(commonFalsePositives),
invalid: [
{
code: 'angular.module("").animation("", function(Authentication, analytics) {});',
errors: [{message: 'Injected values should be sorted alphabetically'}],
options: [true, 'case_insensitive']
},
{
code: 'angular.module("").animation("", function(analytics, Authentication) {});',
errors: [{message: 'Injected values should be sorted alphabetically'}],
options: [true, 'case_sensitive']
},
// animation
{
code: 'angular.module("").animation("", function($q, $http) {});',
Expand Down
41 changes: 41 additions & 0 deletions test/file-name.js
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
6 changes: 6 additions & 0 deletions test/no-private-call.js
Expand Up @@ -38,6 +38,12 @@ eslintTester.run('no-private-call', rule, {
options: [{
allow: ['$$watchers']
}]
},
{
code: 'node.$$treeLevel',
options: [{
allow: ['$$treeLevel']
}]
}

].concat(commonFalsePositives),
Expand Down

0 comments on commit 8b65dc1

Please sign in to comment.