diff --git a/docs/no-services.md b/docs/no-services.md index 6855fb1c..fcc45dac 100644 --- a/docs/no-services.md +++ b/docs/no-services.md @@ -34,45 +34,45 @@ The following patterns are **not** considered problems with default config; // ... }); -The following patterns are considered problems when configured `["$http","$q"]`: +The following patterns are considered problems when configured `["http","q"]`: - /*eslint angular/no-services: [2,["$http","$q"]]*/ + /*eslint angular/no-services: [2,["http","q"]]*/ // invalid app.directive('helloWorld', function($q) { // ... }); // error: REST API calls should be implemented in a specific service ($q in directive) -The following patterns are **not** considered problems when configured `["$http","$q"]`: +The following patterns are **not** considered problems when configured `["http","q"]`: - /*eslint angular/no-services: [2,["$http","$q"]]*/ + /*eslint angular/no-services: [2,["http","q"]]*/ // valid app.directive('helloWorld', function($resource) { // ... }); -The following patterns are considered problems when configured `["$http","$q"]` and `["directive"]`: +The following patterns are considered problems when configured `["http","q"]` and `["directive"]`: - /*eslint angular/no-services: [2,["$http","$q"],["directive"]]*/ + /*eslint angular/no-services: [2,["http","q"],["directive"]]*/ // invalid app.directive('MyController', function($http) { // ... }); // error: REST API calls should be implemented in a specific service ($http in directive) -The following patterns are **not** considered problems when configured `["$http","$q"]` and `["directive"]`: +The following patterns are **not** considered problems when configured `["http","q"]` and `["directive"]`: - /*eslint angular/no-services: [2,["$http","$q"],["directive"]]*/ + /*eslint angular/no-services: [2,["http","q"],["directive"]]*/ // valid app.controller('MyController', function($http) { // ... }); -The following patterns are considered problems when configured `{"directive":["$http","$q"],"controller":["$resource"]}`: +The following patterns are considered problems when configured `{"directive":["http","q"],"controller":["resource"]}`: - /*eslint angular/no-services: [2,{"directive":["$http","$q"],"controller":["$resource"]}]*/ + /*eslint angular/no-services: [2,{"directive":["http","q"],"controller":["resource"]}]*/ // invalid app.controller('MyController', function($resource, $log) { @@ -84,9 +84,9 @@ The following patterns are considered problems when configured `{"directive":["$ // ... }); // error: REST API calls should be implemented in a specific service ($http in directive) -The following patterns are **not** considered problems when configured `{"directive":["$http","$q"],"controller":["$resource"]}`: +The following patterns are **not** considered problems when configured `{"directive":["http","q"],"controller":["resource"]}`: - /*eslint angular/no-services: [2,{"directive":["$http","$q"],"controller":["$resource"]}]*/ + /*eslint angular/no-services: [2,{"directive":["http","q"],"controller":["resource"]}]*/ // valid app.controller('MyController', function($http, $q, $log) { diff --git a/examples/no-services.js b/examples/no-services.js index 1d007386..ed9a49a4 100644 --- a/examples/no-services.js +++ b/examples/no-services.js @@ -3,6 +3,7 @@ app.controller('MyController', function(myService) { // ... }); + // example - valid: false, errorMessage: "REST API calls should be implemented in a specific service ($http in controller)" app.controller('MyController', function($http) { // ... @@ -13,43 +14,43 @@ app.directive('helloWorld', function($resource) { // ... }); -// example - valid: true, options: [["$http","$q"]] +// example - valid: true, options: [["http","q"]] app.directive('helloWorld', function($resource) { // ... }); -// example - valid: false, options: [["$http","$q"]], errorMessage: "REST API calls should be implemented in a specific service ($q in directive)" +// example - valid: false, options: [["http","q"]], errorMessage: "REST API calls should be implemented in a specific service ($q in directive)" app.directive('helloWorld', function($q) { // ... }); -// example - valid: true, options: [["$http","$q"],["directive"]] +// example - valid: true, options: [["http","q"],["directive"]] app.controller('MyController', function($http) { // ... }); -// example - valid: false, options: [["$http","$q"],["directive"]], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)" +// example - valid: false, options: [["http","q"],["directive"]], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)" app.directive('MyController', function($http) { // ... }); -// example - valid: true, options: [{"directive":["$http","$q"],"controller":["$resource"]}] +// example - valid: true, options: [{"directive":["http","q"],"controller":["resource"]}] app.controller('MyController', function($http, $q, $log) { // ... }); -// example - valid: true, options: [{"directive":["$http","$q"],"controller":["$resource"]}] +// example - valid: true, options: [{"directive":["http","q"],"controller":["resource"]}] app.directive('helloWorld', function($resource, $log) { // ... }); -// example - valid: false, options: [{"directive":["$http","$q"],"controller":["$resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($resource in controller)" +// example - valid: false, options: [{"directive":["http","q"],"controller":["resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($resource in controller)" app.controller('MyController', function($resource, $log) { // ... }); -// example - valid: false, options: [{"directive":["$http","$q"],"controller":["$resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)" +// example - valid: false, options: [{"directive":["http","q"],"controller":["resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)" app.directive('helloWorld', function($http, $log) { // ... }); diff --git a/package.json b/package.json index 1274ee0d..44cf8da8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-angular", - "version": "2.1.0", + "version": "2.2.0", "description": "ESLint rules for AngularJS projects", "main": "index.js", "scripts": { diff --git a/rules/module-dependency-order.js b/rules/module-dependency-order.js index f5878bad..f09fbbdf 100644 --- a/rules/module-dependency-order.js +++ b/rules/module-dependency-order.js @@ -60,8 +60,8 @@ module.exports = { ]; function checkLiteral(node) { - if (node && node.type !== 'Literal') { - context.report(node, 'Unexpected non-literal value'); + if (node && node.type !== 'Literal' && node.type !== 'Identifier') { + context.report(node, 'Unexpected non-literal or identifier value' + node.type); return false; } if (!node) { @@ -76,7 +76,7 @@ module.exports = { if (!checkLiteral(node)) { return; } - var value = node.value; + var value = node.value || node.name; if (lastCorrect === undefined || lastCorrect.localeCompare(value) < 0) { lastCorrect = value; } else { @@ -103,7 +103,7 @@ module.exports = { if (!checkLiteral(node)) { return; } - var value = node.value; + var value = node.value || node.name; if (lastCorrect === undefined) { lastCorrect = value; if (isCustomModule(value)) { diff --git a/rules/no-services.js b/rules/no-services.js index 1f422aa3..c83cdde0 100644 --- a/rules/no-services.js +++ b/rules/no-services.js @@ -38,7 +38,7 @@ module.exports = { } if (context.options[0] === undefined) { - badServices = ['/\$http/', '/\$resource/', 'Restangular', '/\$q/', '/\$filter/']; + badServices = [/\$http/, /\$resource/, /Restangular/, /\$q/, /\$filter/]; } if (isArray(context.options[0])) { diff --git a/test/module-dependency-order.js b/test/module-dependency-order.js index 50137e11..5867a5cf 100644 --- a/test/module-dependency-order.js +++ b/test/module-dependency-order.js @@ -23,9 +23,19 @@ eslintTester.run('module-dependency-order', rule, { code: 'angular.module("", ["app.filters","ngCordova","ngMaterial","ui.router"])', options: [{grouped: false}] }, + { + code: 'angular.module("", [appFilters,ngCordova,ngMaterial,uiRouter])', + options: [{grouped: false}] + }, + { + code: 'angular.module("", [appFilters,"ngCordova",ngMaterial,uiRouter])', + options: [{grouped: false}] + }, // grouped mode 'angular.module("", ["ng","ngAnimate","ngAria","ngCookies","ngLocale","ngMaterial","ngMessageFormat","ngMessages","ngMock","ngNewRouter","ngResource","ngRoute","ngSanitize","ngTouch"])', 'angular.module("", ["ngAnimate","ngResource","ngCordova"])', + 'angular.module("", [ngAnimate,ngResource,ngCordova])', + 'angular.module("", [ngAnimate,"ngResource",ngCordova])', { code: 'angular.module("", ["ngAnimate","ngResource","ngCordova","app.filters"])', options: [{prefix: 'app'}] @@ -38,14 +48,6 @@ eslintTester.run('module-dependency-order', rule, { {message: 'Dependencies should be a literal array'} ] }, - // combined mode - { - code: 'angular.module("", [dep])', - options: [{grouped: false}], - errors: [ - {message: 'Unexpected non-literal value'} - ] - }, { code: 'angular.module("", ["ngCordova","app.filters","app.resources","ngMaterial","app.user","ui.router"])', options: [{grouped: false}], @@ -55,11 +57,13 @@ eslintTester.run('module-dependency-order', rule, { {message: 'app.user should be sorted before ngMaterial'} ] }, - // grouped mode { - code: 'angular.module("", [dep])', + code: 'angular.module("", [ngCordova,"app.filters","app.resources",ngMaterial,"app.user","ui.router"])', + options: [{grouped: false}], errors: [ - {message: 'Unexpected non-literal value'} + {message: 'app.filters should be sorted before ngCordova'}, + {message: 'app.resources should be sorted before ngCordova'}, + {message: 'app.user should be sorted before ngMaterial'} ] }, {