Skip to content

Commit 9a37f4e

Browse files
committed
Merge pull request #172 from Gillespie59/development
0.6.1
2 parents 5e6ee82 + 9029432 commit 9a37f4e

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

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": "0.6.0",
3+
"version": "0.6.1",
44
"description": "ESLint rules for AngularJS projects",
55
"main": "index.js",
66
"repository": {

rules/ng_deferred.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = function(context) {
66

77
'MemberExpression': function(node) {
88
if(node.object.type === 'Identifier' && node.object.name === '$q'){
9-
if(node.property.type === 'Identifier' && node.property.name === 'deferred'){
9+
if(node.property.type === 'Identifier' && node.property.name === 'defer'){
1010
context.report(node, 'You should not create a new promise with this syntax. Use the $q(function(resolve, reject){}) syntax.', {});
1111
}
1212

rules/ng_di_order.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ module.exports = function(context) {
1212
'provider',
1313
'service'
1414
];
15+
var setupCalls = [
16+
'config',
17+
'run'
18+
];
1519

16-
function checkOrder(node, fn) {
20+
function checkOrder(fn) {
1721
var args = fn.params.map(function(arg) {
1822
return arg.name;
1923
});
2024
var sortedArgs = args.slice().sort();
2125
sortedArgs.some(function(value, index) {
2226
if(args.indexOf(value) !== index) {
23-
context.report(node, 'Injected values should be sorted alphabetically');
27+
context.report(fn, 'Injected values should be sorted alphabetically');
2428
return true;
2529
}
2630
});
@@ -31,18 +35,22 @@ module.exports = function(context) {
3135
'AssignmentExpression': function(node) {
3236
// The $get function of a provider.
3337
if(node.left.type === 'MemberExpression' && node.left.property.name === '$get') {
34-
return checkOrder(node, node.right);
38+
return checkOrder(node.right);
3539
}
3640
},
3741

3842
'CallExpression': function(node) {
3943
// An Angular component definition.
40-
if(utils.isAngularComponent(node) && node.callee.type === 'MemberExpression' && angularNamedObjectList.indexOf(node.callee.property.name) >= 0){
41-
return checkOrder(node, node.arguments[1]);
44+
if(utils.isAngularComponent(node) && node.callee.type === 'MemberExpression' && node.arguments[1].type === 'FunctionExpression' && angularNamedObjectList.indexOf(node.callee.property.name) >= 0){
45+
return checkOrder(node.arguments[1]);
46+
}
47+
// Config and run functions.
48+
if(node.callee.type === 'MemberExpression' && node.arguments.length > 0 && setupCalls.indexOf(node.callee.property.name) !== -1 && node.arguments[0].type === 'FunctionExpression') {
49+
return checkOrder(node.arguments[0]);
4250
}
4351
// Injected values in unittests.
4452
if(node.callee.type === 'Identifier' && node.callee.name === 'inject') {
45-
return checkOrder(node, node.arguments[0]);
53+
return checkOrder(node.arguments[0]);
4654
}
4755
}
4856
};

test/ng_deferred.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ var rule = require('../rules/ng_deferred'),
1212
var eslintTester = new RuleTester();
1313
eslintTester.run('ng_deferred', rule, {
1414
valid: [
15-
'$qs(function(){});'
15+
'$q(function(){});'
1616
],
1717
invalid: [
18-
{ code: 'var deferred = $q.deferred;', errors: [{ message: 'You should not create a new promise with this syntax. Use the $q(function(resolve, reject){}) syntax.'}] }
18+
{ code: 'var deferred = $q.defer();', errors: [{ message: 'You should not create a new promise with this syntax. Use the $q(function(resolve, reject){}) syntax.'}] }
1919
]
2020
});

test/ng_di_order.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ eslintTester.run('ng_di_order', rule, {
1515
'app.controller("", function($http, $q){});',
1616
'app.directive("", function($http, $q){});',
1717
'app.factory("", function($http, $q){});',
18+
'app.factory("", fsctoryName);',
1819
'app.filter("", function($http, $q){});',
1920
'app.provider("", function($http, $q){});',
2021
'app.service("", function($http, $q){});',
22+
'app.config(function($httpProvider, $routeProvider){});',
23+
'app.run(function($http, $q){});',
2124
'inject(function($http, $q){});',
2225
'it(inject(function($http, $q){}));',
2326
'this.$get = function($http, $q){};',
@@ -40,6 +43,12 @@ eslintTester.run('ng_di_order', rule, {
4043
}, {
4144
code: 'app.service("", function($q, $http){});',
4245
errors: [{message: 'Injected values should be sorted alphabetically'}]
46+
}, {
47+
code: 'app.config(function($routeProvider, $httpProvider){});',
48+
errors: [{message: 'Injected values should be sorted alphabetically'}]
49+
}, {
50+
code: 'app.run(function($q, $http){});',
51+
errors: [{message: 'Injected values should be sorted alphabetically'}]
4352
}, {
4453
code: 'inject(function($q, $http){});',
4554
errors: [{message: 'Injected values should be sorted alphabetically'}]

0 commit comments

Comments
 (0)