From b93b6582e8ee0c1f54ec1a194689a6f5ef1be0d2 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Sat, 18 Mar 2017 15:17:05 +0100 Subject: [PATCH 1/9] Update to eslint 3.18.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aa01c7fa..42f643be 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "chai": "^3.5.0", "chai-spies": "^0.7.1", "coveralls": "^2.11.6", - "eslint": "^3.0.0", + "eslint": "^3.18.0", "espree": "^3.0.1", "gulp": "^3.9.1", "gulp-eslint": "^3.0.1", From 91c8530c11887868b2e993d28c73e70a1df8edef Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Sat, 18 Mar 2017 15:17:10 +0100 Subject: [PATCH 2/9] Issue #454 Change angular: into angular? --- rules/component-limit.js | 20 ++++++++++---------- rules/di-order.js | 20 ++++++++++---------- rules/di-unused.js | 20 ++++++++++---------- rules/di.js | 20 ++++++++++---------- rules/dumb-inject.js | 2 +- rules/no-directive-replace.js | 2 +- rules/no-run-logic.js | 2 +- rules/prefer-component.js | 2 +- rules/utils/angular-rule.js | 26 +++++++++++++------------- 9 files changed, 57 insertions(+), 57 deletions(-) diff --git a/rules/component-limit.js b/rules/component-limit.js index f53506c8..1b4fbe26 100644 --- a/rules/component-limit.js +++ b/rules/component-limit.js @@ -41,16 +41,16 @@ module.exports = { } return { - 'angular:animation': checkLimit, - 'angular:config': checkLimit, - 'angular:controller': checkLimit, - 'angular:directive': checkLimit, - 'angular:factory': checkLimit, - 'angular:filter': checkLimit, - 'angular:provider': checkLimit, - 'angular:run': checkLimit, - 'angular:service': checkLimit, - 'angular:component': checkLimit + 'angular?animation': checkLimit, + 'angular?config': checkLimit, + 'angular?controller': checkLimit, + 'angular?directive': checkLimit, + 'angular?factory': checkLimit, + 'angular?filter': checkLimit, + 'angular?provider': checkLimit, + 'angular?run': checkLimit, + 'angular?service': checkLimit, + 'angular?component': checkLimit }; }) }; diff --git a/rules/di-order.js b/rules/di-order.js index 835f2e8d..bad96f8f 100644 --- a/rules/di-order.js +++ b/rules/di-order.js @@ -47,16 +47,16 @@ module.exports = { } return { - 'angular:animation': checkOrder, - 'angular:config': checkOrder, - 'angular:controller': checkOrder, - 'angular:directive': checkOrder, - 'angular:factory': checkOrder, - 'angular:filter': checkOrder, - 'angular:inject': checkOrder, - 'angular:run': checkOrder, - 'angular:service': checkOrder, - 'angular:provider': function(callee, providerFn, $get) { + 'angular?animation': checkOrder, + 'angular?config': checkOrder, + 'angular?controller': checkOrder, + 'angular?directive': checkOrder, + 'angular?factory': checkOrder, + 'angular?filter': checkOrder, + 'angular?inject': checkOrder, + 'angular?run': checkOrder, + 'angular?service': checkOrder, + 'angular?provider': function(callee, providerFn, $get) { checkOrder(null, providerFn); checkOrder(null, $get); } diff --git a/rules/di-unused.js b/rules/di-unused.js index 2403b596..7d63ebc8 100644 --- a/rules/di-unused.js +++ b/rules/di-unused.js @@ -54,16 +54,16 @@ module.exports = { } return { - 'angular:animation': reportUnusedVariables, - 'angular:config': reportUnusedVariables, - 'angular:controller': reportUnusedVariables, - 'angular:directive': reportUnusedVariables, - 'angular:factory': reportUnusedVariables, - 'angular:filter': reportUnusedVariables, - 'angular:inject': reportUnusedVariables, - 'angular:run': reportUnusedVariables, - 'angular:service': reportUnusedVariables, - 'angular:provider': function(callee, providerFn, $get) { + 'angular?animation': reportUnusedVariables, + 'angular?config': reportUnusedVariables, + 'angular?controller': reportUnusedVariables, + 'angular?directive': reportUnusedVariables, + 'angular?factory': reportUnusedVariables, + 'angular?filter': reportUnusedVariables, + 'angular?inject': reportUnusedVariables, + 'angular?run': reportUnusedVariables, + 'angular?service': reportUnusedVariables, + 'angular?provider': function(callee, providerFn, $get) { reportUnusedVariables(null, providerFn); reportUnusedVariables(null, $get); }, diff --git a/rules/di.js b/rules/di.js index 69485df8..b68c86a8 100644 --- a/rules/di.js +++ b/rules/di.js @@ -117,16 +117,16 @@ module.exports = { } return { - 'angular:animation': checkDi, - 'angular:config': checkDi, - 'angular:controller': checkDi, - 'angular:directive': checkDi, - 'angular:factory': checkDi, - 'angular:filter': checkDi, - 'angular:inject': checkDi, - 'angular:run': checkDi, - 'angular:service': checkDi, - 'angular:provider': function(callee, providerFn, $get) { + 'angular?animation': checkDi, + 'angular?config': checkDi, + 'angular?controller': checkDi, + 'angular?directive': checkDi, + 'angular?factory': checkDi, + 'angular?filter': checkDi, + 'angular?inject': checkDi, + 'angular?run': checkDi, + 'angular?service': checkDi, + 'angular?provider': function(callee, providerFn, $get) { checkDi(null, providerFn); checkDi(null, $get); }, diff --git a/rules/dumb-inject.js b/rules/dumb-inject.js index e2d310ce..b8a49237 100644 --- a/rules/dumb-inject.js +++ b/rules/dumb-inject.js @@ -25,7 +25,7 @@ module.exports = { } return { - 'angular:inject': function(callExpression, fn) { + 'angular?inject': function(callExpression, fn) { if (!fn) { return; } diff --git a/rules/no-directive-replace.js b/rules/no-directive-replace.js index fbdcdb52..5bb43641 100644 --- a/rules/no-directive-replace.js +++ b/rules/no-directive-replace.js @@ -44,7 +44,7 @@ module.exports = { } return { - 'angular:directive': function(callExpressionNode, fnNode) { + 'angular?directive': function(callExpressionNode, fnNode) { if (!fnNode || !fnNode.body) { return; } diff --git a/rules/no-run-logic.js b/rules/no-run-logic.js index 7ad8ecb2..2aa056c0 100644 --- a/rules/no-run-logic.js +++ b/rules/no-run-logic.js @@ -33,7 +33,7 @@ module.exports = { } return { - 'angular:run': function(callExpression, fn) { + 'angular?run': function(callExpression, fn) { if (!fn) { return; } diff --git a/rules/prefer-component.js b/rules/prefer-component.js index 2822365f..9214fa7a 100644 --- a/rules/prefer-component.js +++ b/rules/prefer-component.js @@ -31,7 +31,7 @@ module.exports = { } return { - 'angular:directive': function(callExpressionNode, fnNode) { + 'angular?directive': function(callExpressionNode, fnNode) { if (!fnNode || !fnNode.body) { return; } diff --git a/rules/utils/angular-rule.js b/rules/utils/angular-rule.js index 90254b90..c30b2fa7 100644 --- a/rules/utils/angular-rule.js +++ b/rules/utils/angular-rule.js @@ -29,17 +29,17 @@ var angularChainableNames = [ * ```js * module.exports = angularRule(function(context) { * return { - * 'angular:animation': function(configCallee, configFn) {}, - * 'angular:component': function(componentCallee, componentObj) {}, - * 'angular:config': function(configCallee, configFn) {}, - * 'angular:controller': function(controllerCallee, controllerFn) {}, - * 'angular:directive': function(directiveCallee, directiveFn) {}, - * 'angular:factory': function(factoryCallee, factoryFn) {}, - * 'angular:filter': function(filterCallee, filterFn) {}, - * 'angular:inject': function(injectCallee, injectFn) {}, // inject() calls from angular-mocks - * 'angular:run': function(runCallee, runFn) {}, - * 'angular:service': function(serviceCallee, serviceFn) {}, - * 'angular:provider': function(providerCallee, providerFn, provider$getFn) {} + * 'angular?animation': function(configCallee, configFn) {}, + * 'angular?component': function(componentCallee, componentObj) {}, + * 'angular?config': function(configCallee, configFn) {}, + * 'angular?controller': function(controllerCallee, controllerFn) {}, + * 'angular?directive': function(directiveCallee, directiveFn) {}, + * 'angular?factory': function(factoryCallee, factoryFn) {}, + * 'angular?filter': function(filterCallee, filterFn) {}, + * 'angular?inject': function(injectCallee, injectFn) {}, // inject() calls from angular-mocks + * 'angular?run': function(runCallee, runFn) {}, + * 'angular?service': function(serviceCallee, serviceFn) {}, + * 'angular?provider': function(providerCallee, providerFn, provider$getFn) {} * }; * }) * ``` @@ -227,13 +227,13 @@ function angularRule(ruleDefinition) { function callAngularRules(ruleObject, context) { angularComponents.forEach(function(component) { var name = component.callExpression.callee.property.name; - var fn = ruleObject['angular:' + name]; + var fn = ruleObject['angular?' + name]; if (!fn) { return; } fn.apply(ruleObject, assembleArguments(component, context)); }); - var injectRule = ruleObject['angular:inject']; + var injectRule = ruleObject['angular?inject']; if (injectRule) { injectCalls.forEach(function(node) { injectRule.call(ruleObject, node.CallExpression, node.fn); From 545cccabd52cf14478f3871cd8d752d65511613a Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Sat, 18 Mar 2017 15:19:07 +0100 Subject: [PATCH 3/9] Update doc --- docs/timeout-service.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/timeout-service.md b/docs/timeout-service.md index 2df3bae9..0fbabb8c 100644 --- a/docs/timeout-service.md +++ b/docs/timeout-service.md @@ -26,11 +26,11 @@ The following patterns are considered problems; window.setTimeout(function() { // ... }, 1000) // error: You should use the $timeout service instead of the default window.setTimeout method - - // invalid + + // invalid $window.setTimeout(function() { // ... - }, 1000) // error: You should use the $timeout service instead of the default window.setTimeout method + }, 1000) // error: You should use the $timeout service instead of the default window.setTimeout method The following patterns are **not** considered problems; From 959693ea4ba81735a5be61190aaf457d427c4e60 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Sat, 18 Mar 2017 15:37:38 +0100 Subject: [PATCH 4/9] Update version to 1.6.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 42f643be..ac882ea1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-angular", - "version": "1.6.2", + "version": "1.6.3", "description": "ESLint rules for AngularJS projects", "main": "index.js", "scripts": { From 6768269e33759e341c63aa8a5a35455a3adbe5df Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Sat, 18 Mar 2017 15:38:14 +0100 Subject: [PATCH 5/9] #Issue #446 run method devined in a service can be executed in a angular run method --- rules/utils/false-values.js | 3 ++- rules/utils/utils.js | 6 +++--- test/module-getter.js | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rules/utils/false-values.js b/rules/utils/false-values.js index fcb55de0..1f9933d8 100644 --- a/rules/utils/false-values.js +++ b/rules/utils/false-values.js @@ -1,5 +1,6 @@ 'use strict'; module.exports = { - config: ['jwtOptionsProvider', 'ngTableHelperProvider', '$ocLazyLoadProvider', '$route', '$localForageProvider'] + config: [/Provider$/, /$route/], + run: [/mocha/, /Service$/] }; diff --git a/rules/utils/utils.js b/rules/utils/utils.js index 9bfbc694..af35fd2b 100644 --- a/rules/utils/utils.js +++ b/rules/utils/utils.js @@ -1,5 +1,6 @@ 'use strict'; var falseConfigValues = require('./false-values').config; +var falseRunValues = require('./false-values').run; var scopeProperties = [ '$id', @@ -458,8 +459,7 @@ function isAngularRunSection(node) { return isMemberExpression(node.callee) && node.callee.property.type === 'Identifier' && node.callee.property.name === 'run' && - (node.callee.object.type === 'Identifier' && - node.callee.object.name !== 'mocha'); + !falseRunValues.find(pattern => new RegExp(pattern).test(node.callee.object.name)); } /** @@ -488,7 +488,7 @@ function isAngularConfigSection(node) { return isMemberExpression(node.callee) && node.callee.property.type === 'Identifier' && node.callee.property.name === 'config' && - falseConfigValues.indexOf(node.callee.object.name) < 0; + !falseConfigValues.find(pattern => new RegExp(pattern).test(node.callee.object.name)); } /** diff --git a/test/module-getter.js b/test/module-getter.js index 6d03200c..7995ea22 100644 --- a/test/module-getter.js +++ b/test/module-getter.js @@ -23,6 +23,7 @@ eslintTester.run('module-getter', rule, { 'angular.module("module").config(function(ngTableHelperProvider){' + 'ngTableHelperProvider.config({count: 10}, {});' + '})', + 'angular.module("module").controller("ctrl", function(ReportService) { ReportService.run();});', 'angular.module("module").controller("TestCtrl", function() {});', 'angular.module("module").factory("TestService", function() {});', 'angular.module("module").service("TestService", function() {});', From b561aa4af2ec9b42b37295bd94ab6446939edb80 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Sat, 18 Mar 2017 15:47:56 +0100 Subject: [PATCH 6/9] Issue #453 avoid error when angular name used a variable --- rules/file-name.js | 5 ++++- test/file-name.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/rules/file-name.js b/rules/file-name.js index cceb6cc5..9e50cf5f 100644 --- a/rules/file-name.js +++ b/rules/file-name.js @@ -124,7 +124,10 @@ module.exports = { if (type === undefined || (type === 'service' && node.callee.object.name === '$provide')) { return; } - + + if(!name){ + return; + } expectedName = filenameUtil.createExpectedName(name, type, options); if (expectedName !== filename) { diff --git a/test/file-name.js b/test/file-name.js index 4932b91f..52f3e7a4 100644 --- a/test/file-name.js +++ b/test/file-name.js @@ -15,6 +15,24 @@ var commonFalsePositives = require('./utils/commonFalsePositives'); var eslintTester = new RuleTester(); eslintTester.run('file-name', rule, { valid: [{ + // basic module + filename: 'app.module.js', + options: [{ + typeSeparator: 'dot', + ignoreTypeSuffix: true, + ignorePrefix: 'fs' + }], + code: `(function () { + +var mod = 'shared.sales'; + +angular.module(mod + 'shared.sales.core.angular', ['ngCookies', 'ngRoute', 'ngLocale', 'ngResource', 'ngAnimate', 'ngSanitize', 'ngMessages', 'ngIOS9UIWebViewPatch']); + +angular.module(mod + 'shared.sales.thirdparty', ['tmh.dynamicLocale', 'gettext', 'ngMaterial', 'md.data.table', 'fixed.table.header', 'as.sortable', 'ngCsv', 'telemetry']); + +angular.module(mod, [mod + '.core.angular', mod + '.thirdparty']); +})();` + }, { // basic module filename: 'myModule.js', code: 'angular.module("myModule", []);' From 092ce8cca802c817140c816b3fdccdf40908c4b2 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Sat, 18 Mar 2017 16:05:55 +0100 Subject: [PATCH 7/9] Issue #444 Rule `typecheck-object` is failed for simple comparing with 'object' --- test/typecheck-array.js | 1 + test/typecheck-date.js | 1 + test/typecheck-function.js | 1 + test/typecheck-number.js | 1 + test/typecheck-object.js | 1 + test/typecheck-string.js | 1 + 6 files changed, 6 insertions(+) diff --git a/test/typecheck-array.js b/test/typecheck-array.js index 4843bb40..7a504a11 100644 --- a/test/typecheck-array.js +++ b/test/typecheck-array.js @@ -19,6 +19,7 @@ eslintTester.run('typecheck-array', rule, { ].concat(commonFalsePositives), invalid: [ {code: 'Object.prototype.toString.call([]) === "[object Array]"', errors: [{message: 'You should use the angular.isArray method'}]}, + {code: 'function name(){return variable === "[object Array]";}', errors: [{message: 'You should use the angular.isArray method'}]}, {code: '"[object Array]" === Object.prototype.toString.call([])', errors: [{message: 'You should use the angular.isArray method'}]}, {code: 'variable === "[object Array]"', errors: [{message: 'You should use the angular.isArray method'}]}, {code: '"[object Array]" === variable', errors: [{message: 'You should use the angular.isArray method'}]}, diff --git a/test/typecheck-date.js b/test/typecheck-date.js index 7f1254b7..01e40aa2 100644 --- a/test/typecheck-date.js +++ b/test/typecheck-date.js @@ -19,6 +19,7 @@ eslintTester.run('typecheck-date', rule, { ].concat(commonFalsePositives), invalid: [ {code: 'Object.prototype.toString.call(variable) === "[object Date]"', errors: [{message: 'You should use the angular.isDate method'}]}, + {code: 'function name(){return variable === "[object Date]";}', errors: [{message: 'You should use the angular.isDate method'}]}, {code: '"[object Date]" === Object.prototype.toString.call(variable)', errors: [{message: 'You should use the angular.isDate method'}]}, {code: 'variable === "[object Date]"', errors: [{message: 'You should use the angular.isDate method'}]}, {code: '"[object Date]" === variable', errors: [{message: 'You should use the angular.isDate method'}]}, diff --git a/test/typecheck-function.js b/test/typecheck-function.js index 7e8c0933..dbe1b878 100644 --- a/test/typecheck-function.js +++ b/test/typecheck-function.js @@ -19,6 +19,7 @@ eslintTester.run('typecheck-function', rule, { ].concat(commonFalsePositives), invalid: [ {code: 'typeof variable === "function"', errors: [{message: 'You should use the angular.isFunction method'}]}, + {code: 'function name(){return variable === "function";}', errors: [{message: 'You should use the angular.isFunction method'}]}, {code: '"function" === typeof variable', errors: [{message: 'You should use the angular.isFunction method'}]}, {code: 'variable === "function"', errors: [{message: 'You should use the angular.isFunction method'}]}, {code: '"function" === variable', errors: [{message: 'You should use the angular.isFunction method'}]}, diff --git a/test/typecheck-number.js b/test/typecheck-number.js index 47a0a6a5..30391aa6 100644 --- a/test/typecheck-number.js +++ b/test/typecheck-number.js @@ -19,6 +19,7 @@ eslintTester.run('typecheck-number', rule, { ].concat(commonFalsePositives), invalid: [ {code: 'Object.prototype.toString.call(variable) === "[object Number]"', errors: [{message: 'You should use the angular.isNumber method'}]}, + {code: 'function name(){return variable === "[object Number]";}', errors: [{message: 'You should use the angular.isNumber method'}]}, {code: '"[object Number]" === Object.prototype.toString.call(variable)', errors: [{message: 'You should use the angular.isNumber method'}]}, {code: 'variable === "[object Number]"', errors: [{message: 'You should use the angular.isNumber method'}]}, {code: '"[object Number]" === variable', errors: [{message: 'You should use the angular.isNumber method'}]}, diff --git a/test/typecheck-object.js b/test/typecheck-object.js index 8ac13a9b..a78a0a65 100644 --- a/test/typecheck-object.js +++ b/test/typecheck-object.js @@ -19,6 +19,7 @@ eslintTester.run('typecheck-object', rule, { ].concat(commonFalsePositives), invalid: [ {code: 'typeof variable === "object"', errors: [{message: 'You should use the angular.isObject method'}]}, + {code: 'function name(){return variable === "object";}', errors: [{message: 'You should use the angular.isObject method'}]}, {code: '"object" === typeof variable', errors: [{message: 'You should use the angular.isObject method'}]}, {code: 'variable === "object"', errors: [{message: 'You should use the angular.isObject method'}]}, {code: '"object" === variable', errors: [{message: 'You should use the angular.isObject method'}]}, diff --git a/test/typecheck-string.js b/test/typecheck-string.js index a4e572d4..8f1832b8 100644 --- a/test/typecheck-string.js +++ b/test/typecheck-string.js @@ -19,6 +19,7 @@ eslintTester.run('typecheck-string', rule, { ].concat(commonFalsePositives), invalid: [ {code: 'Object.prototype.toString.call(variable) === "[object String]"', errors: [{message: 'You should use the angular.isString method'}]}, + {code: 'function name(){return variable === "[object String]";}', errors: [{message: 'You should use the angular.isString method'}]}, {code: '"[object String]" === Object.prototype.toString.call(variable)', errors: [{message: 'You should use the angular.isString method'}]}, {code: 'variable === "[object String]"', errors: [{message: 'You should use the angular.isString method'}]}, {code: '"[object String]" === variable', errors: [{message: 'You should use the angular.isString method'}]}, From c7be88d5ce00d3c51131b4fd8e71c07c9d111f87 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Sat, 18 Mar 2017 16:13:44 +0100 Subject: [PATCH 8/9] Solve Eslint issue --- rules/file-name.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/file-name.js b/rules/file-name.js index 9e50cf5f..f9074af9 100644 --- a/rules/file-name.js +++ b/rules/file-name.js @@ -124,8 +124,8 @@ module.exports = { if (type === undefined || (type === 'service' && node.callee.object.name === '$provide')) { return; } - - if(!name){ + + if (!name) { return; } expectedName = filenameUtil.createExpectedName(name, type, options); From 59ecabb52b9a08aed11795d4ae9de3400fe2a4d5 Mon Sep 17 00:00:00 2001 From: Emmanuel DEMEY Date: Sat, 18 Mar 2017 16:13:58 +0100 Subject: [PATCH 9/9] Allow ES6 code --- .eslintrc.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 72864a96..5ef6b469 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -1,6 +1,9 @@ env: node: true +parserOptions: + ecmaVersion: 6 + rules: # http://eslint.org/docs/rules/#possible-errors comma-dangle: