From a7b198cf24c9ea7807fd004726855346ae4ab829 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Wed, 22 Mar 2017 20:42:10 +0100 Subject: [PATCH 1/4] Issue #437 module-dependency-order: allow Identifiers --- rules/module-dependency-order.js | 8 ++++---- test/module-dependency-order.js | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) 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/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'} ] }, { From 9fcf8354e66da335ce691f23e9a247bee9122171 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Wed, 22 Mar 2017 20:43:10 +0100 Subject: [PATCH 2/4] Update to 2.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": { From 43f155118863dbb1b5de2d1fa4d000ec8d6815f3 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Wed, 22 Mar 2017 21:00:32 +0100 Subject: [PATCH 3/4] Solve doc for no-service --- docs/no-services.md | 24 ++++++++++++------------ examples/no-services.js | 17 +++++++++-------- rules/no-services.js | 3 ++- 3 files changed, 23 insertions(+), 21 deletions(-) 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/rules/no-services.js b/rules/no-services.js index 1f422aa3..c4b8ecb9 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])) { @@ -65,6 +65,7 @@ module.exports = { } function isSetBedService(serviceName, angularObjectName) { + console.log(badServices) if (map) { return map[angularObjectName].find(object => utils.convertPrefixToRegex(object).test(serviceName)); } From 1995dc8269fa5bb13f864f9c574cdb21c0d0e4bb Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Wed, 22 Mar 2017 21:03:26 +0100 Subject: [PATCH 4/4] Delete useless console.log --- rules/no-services.js | 1 - 1 file changed, 1 deletion(-) diff --git a/rules/no-services.js b/rules/no-services.js index c4b8ecb9..c83cdde0 100644 --- a/rules/no-services.js +++ b/rules/no-services.js @@ -65,7 +65,6 @@ module.exports = { } function isSetBedService(serviceName, angularObjectName) { - console.log(badServices) if (map) { return map[angularObjectName].find(object => utils.convertPrefixToRegex(object).test(serviceName)); }