From be2df3a358d856a2be7a5beacc9b545a39ca94e1 Mon Sep 17 00:00:00 2001 From: gal koren Date: Fri, 26 Jun 2020 17:58:55 +0300 Subject: [PATCH 1/6] di support for angular/1.8.0 --- rules/di.js | 185 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 133 insertions(+), 52 deletions(-) diff --git a/rules/di.js b/rules/di.js index 1ccd6c88..bb7e3a88 100644 --- a/rules/di.js +++ b/rules/di.js @@ -7,61 +7,70 @@ * @category conventions * @sinceAngularVersion 1.x */ -'use strict'; +"use strict"; -var utils = require('./utils/utils'); - -var angularRule = require('./utils/angular-rule'); +var utils = require("./utils/utils"); +var angularRule = require("./utils/angular-rule"); module.exports = { meta: { docs: { - url: 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/di.md' + url: + "https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/di.md", }, - schema: [{ - enum: [ - 'function', - 'array', - '$inject' - ] - }, { - type: 'object', - properties: { - matchNames: { - type: 'boolean' + schema: [ + { + enum: ["function", "array", "$inject"], + }, + { + type: "object", + properties: { + matchNames: { + type: "boolean", + }, + stripUnderscores: { + type: "boolean", + }, }, - stripUnderscores: { - type: 'boolean' - } - } - }] + }, + ], }, - create: angularRule(function(context) { - var syntax = context.options[0] || 'function'; + create: angularRule(function (context) { + var syntax = context.options[0] || "function"; var extra = context.options[1] || {}; var matchNames = extra.matchNames !== false; var stripUnderscores = extra.stripUnderscores === true; function report(node) { - context.report(node, 'You should use the {{syntax}} syntax for DI', { - syntax: syntax - }); + context.report( + node, + "You should use the {{syntax}} syntax for DI", + { + syntax: syntax, + } + ); } var $injectProperties = {}; function maybeNoteInjection(node) { - if (syntax === '$inject' && node.left && node.left.property && - ((utils.isLiteralType(node.left.property) && node.left.property.value === '$inject') || - (utils.isIdentifierType(node.left.property) && node.left.property.name === '$inject'))) { + if ( + syntax === "$inject" && + node.left && + node.left.property && + ((utils.isLiteralType(node.left.property) && + node.left.property.value === "$inject") || + (utils.isIdentifierType(node.left.property) && + node.left.property.name === "$inject")) + ) { $injectProperties[node.left.object.name] = node.right; } } function normalizeParameter(param) { - return param.replace(/^_(.+)_$/, function(match, p1) { + return param.replace(/^_(.+)_$/, function (match, p1) { return p1; }); } @@ -71,15 +80,19 @@ module.exports = { return; } - if (syntax === 'array') { + if (syntax === "array") { if (utils.isArrayType(fn.parent)) { if (fn.parent.elements.length - 1 !== fn.params.length) { - context.report(fn, 'The signature of the method is incorrect', {}); + context.report( + fn, + "The signature of the method is incorrect", + {} + ); return; } if (matchNames) { - var invalidArray = fn.params.filter(function(e, i) { + var invalidArray = fn.params.filter(function (e, i) { var name = e.name; if (stripUnderscores) { @@ -89,7 +102,11 @@ module.exports = { return name !== fn.parent.elements[i].value; }); if (invalidArray.length > 0) { - context.report(fn, 'You have an error in your DI configuration. Each items of the array should match exactly one function parameter', {}); + context.report( + fn, + "You have an error in your DI configuration. Each items of the array should match exactly one function parameter", + {} + ); return; } } @@ -101,24 +118,31 @@ module.exports = { } } - if (syntax === 'function') { + if (syntax === "function") { if (utils.isArrayType(fn.parent)) { report(fn); } } - if (syntax === '$inject') { + if (syntax === "$inject") { if (fn && fn.id && utils.isIdentifierType(fn.id)) { var $injectArray = $injectProperties[fn.id.name]; if ($injectArray && utils.isArrayType($injectArray)) { if ($injectArray.elements.length !== fn.params.length) { - context.report(fn, 'The signature of the method is incorrect', {}); + context.report( + fn, + "The signature of the method is incorrect", + {} + ); return; } if (matchNames) { - var invalidInjectArray = fn.params.filter(function(e, i) { + var invalidInjectArray = fn.params.filter(function ( + e, + i + ) { var name = e.name; if (stripUnderscores) { @@ -128,7 +152,11 @@ module.exports = { return name !== $injectArray.elements[i].value; }); if (invalidInjectArray.length > 0) { - context.report(fn, 'You have an error in your DI configuration. Each items of the array should match exactly one function parameter', {}); + context.report( + fn, + "You have an error in your DI configuration. Each items of the array should match exactly one function parameter", + {} + ); return; } } @@ -142,22 +170,75 @@ 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); }, - AssignmentExpression: function(node) { + "angular?component": function (callee) { + var routeObject = callee.parent.arguments[1]; + + var elementLength = 0; + var elements = null; + var parameters = null; + + if (routeObject.properties) { + routeObject.properties.forEach(function (prop) { + if (prop.key.name === "controller") { + elements = prop.value.elements; + if (elements.length) { + elementLength = elements.length - 1; + } + prop.value.elements.forEach(function (element) { + if (element.type === "FunctionExpression") { + parameters = element.params; + } + }); + } + }); + } + + if (elementLength !== parameters.length) { + context.report( + routeObject, + "The signature of the method is incorrect", + {} + ); + return; + } + + if (matchNames) { + var invalidArray = parameters.filter(function (e, i) { + var name = e.name; + + if (stripUnderscores) { + name = normalizeParameter(name); + } + + return name !== elements[i].value; + }); + + if (invalidArray.length > 0) { + context.report( + routeObject, + "You have an error in your DI configuration. Each items of the array should match exactly one function parameter", + {} + ); + return; + } + } + }, + AssignmentExpression: function (node) { maybeNoteInjection(node); - } + }, }; - }) + }), }; From c465cfaf8b5f7fe0b40e295ac5ffb019c121bab5 Mon Sep 17 00:00:00 2001 From: gal koren Date: Sun, 28 Jun 2020 13:56:46 +0300 Subject: [PATCH 2/6] remove warning --- rules/service-name.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rules/service-name.js b/rules/service-name.js index df132e6c..f801bff8 100644 --- a/rules/service-name.js +++ b/rules/service-name.js @@ -66,11 +66,11 @@ function warnForDeprecatedBehavior(options) { var config = getConfig(options); - /* istanbul ignore if */ - if (config.oldBehavior) { - // eslint-disable-next-line - console.warn('The rule `angular/service-name` will be split up to different rules in the next version. Please read the docs for more information'); - } + // /* istanbul ignore if */ + // if (config.oldBehavior) { + // // eslint-disable-next-line + // console.warn('The rule `angular/service-name` will be split up to different rules in the next version. Please read the docs for more information'); + // } } module.exports = { From f546ed1becfc37fa4366e5758be1218a8a7183a6 Mon Sep 17 00:00:00 2001 From: gal koren Date: Fri, 22 Oct 2021 11:04:11 +0300 Subject: [PATCH 3/6] change Apostrophes --- rules/di.js | 72 ++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/rules/di.js b/rules/di.js index bb7e3a88..63f2279a 100644 --- a/rules/di.js +++ b/rules/di.js @@ -1,43 +1,43 @@ /** * require a consistent DI syntax * - * All your DI should use the same syntax : the Array, function, or $inject syntaxes ("di": [2, "array, function, or $inject"]) + * All your DI should use the same syntax : the Array, function, or $inject syntaxes ('di': [2, 'array, function, or $inject']) * * @version 0.1.0 * @category conventions * @sinceAngularVersion 1.x */ -"use strict"; +'use strict'; -var utils = require("./utils/utils"); +var utils = require('./utils/utils'); -var angularRule = require("./utils/angular-rule"); +var angularRule = require('./utils/angular-rule'); module.exports = { meta: { docs: { url: - "https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/di.md", + 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/di.md', }, schema: [ { - enum: ["function", "array", "$inject"], + enum: ['function', 'array', '$inject'], }, { - type: "object", + type: 'object', properties: { matchNames: { - type: "boolean", + type: 'boolean', }, stripUnderscores: { - type: "boolean", + type: 'boolean', }, }, }, ], }, create: angularRule(function (context) { - var syntax = context.options[0] || "function"; + var syntax = context.options[0] || 'function'; var extra = context.options[1] || {}; var matchNames = extra.matchNames !== false; @@ -46,7 +46,7 @@ module.exports = { function report(node) { context.report( node, - "You should use the {{syntax}} syntax for DI", + 'You should use the {{syntax}} syntax for DI', { syntax: syntax, } @@ -57,13 +57,13 @@ module.exports = { function maybeNoteInjection(node) { if ( - syntax === "$inject" && + syntax === '$inject' && node.left && node.left.property && ((utils.isLiteralType(node.left.property) && - node.left.property.value === "$inject") || + node.left.property.value === '$inject') || (utils.isIdentifierType(node.left.property) && - node.left.property.name === "$inject")) + node.left.property.name === '$inject')) ) { $injectProperties[node.left.object.name] = node.right; } @@ -80,12 +80,12 @@ module.exports = { return; } - if (syntax === "array") { + if (syntax === 'array') { if (utils.isArrayType(fn.parent)) { if (fn.parent.elements.length - 1 !== fn.params.length) { context.report( fn, - "The signature of the method is incorrect", + 'The signature of the method is incorrect', {} ); return; @@ -104,7 +104,7 @@ module.exports = { if (invalidArray.length > 0) { context.report( fn, - "You have an error in your DI configuration. Each items of the array should match exactly one function parameter", + 'You have an error in your DI configuration. Each items of the array should match exactly one function parameter', {} ); return; @@ -118,13 +118,13 @@ module.exports = { } } - if (syntax === "function") { + if (syntax === 'function') { if (utils.isArrayType(fn.parent)) { report(fn); } } - if (syntax === "$inject") { + if (syntax === '$inject') { if (fn && fn.id && utils.isIdentifierType(fn.id)) { var $injectArray = $injectProperties[fn.id.name]; @@ -132,7 +132,7 @@ module.exports = { if ($injectArray.elements.length !== fn.params.length) { context.report( fn, - "The signature of the method is incorrect", + 'The signature of the method is incorrect', {} ); return; @@ -154,7 +154,7 @@ module.exports = { if (invalidInjectArray.length > 0) { context.report( fn, - "You have an error in your DI configuration. Each items of the array should match exactly one function parameter", + 'You have an error in your DI configuration. Each items of the array should match exactly one function parameter', {} ); return; @@ -170,20 +170,20 @@ 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); }, - "angular?component": function (callee) { + 'angular?component': function (callee) { var routeObject = callee.parent.arguments[1]; var elementLength = 0; @@ -192,13 +192,13 @@ module.exports = { if (routeObject.properties) { routeObject.properties.forEach(function (prop) { - if (prop.key.name === "controller") { + if (prop.key.name === 'controller') { elements = prop.value.elements; if (elements.length) { elementLength = elements.length - 1; } prop.value.elements.forEach(function (element) { - if (element.type === "FunctionExpression") { + if (element.type === 'FunctionExpression') { parameters = element.params; } }); @@ -209,7 +209,7 @@ module.exports = { if (elementLength !== parameters.length) { context.report( routeObject, - "The signature of the method is incorrect", + 'The signature of the method is incorrect', {} ); return; @@ -229,7 +229,7 @@ module.exports = { if (invalidArray.length > 0) { context.report( routeObject, - "You have an error in your DI configuration. Each items of the array should match exactly one function parameter", + 'You have an error in your DI configuration. Each items of the array should match exactly one function parameter', {} ); return; From 114569baf2519e9ecadd77606d48be7cfe40959c Mon Sep 17 00:00:00 2001 From: gal koren Date: Fri, 22 Oct 2021 11:18:23 +0300 Subject: [PATCH 4/6] eslint --- .vscode/settings.json | 5 +++++ package-lock.json | 2 +- rules/di.js | 42 +++++++++++++++++++++--------------------- 3 files changed, 27 insertions(+), 22 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..dc8891d5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4c4ebf70..172f5ad0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-angular", - "version": "4.0.1", + "version": "4.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/rules/di.js b/rules/di.js index 63f2279a..283edb99 100644 --- a/rules/di.js +++ b/rules/di.js @@ -17,26 +17,26 @@ module.exports = { meta: { docs: { url: - 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/di.md', + 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/di.md' }, schema: [ { - enum: ['function', 'array', '$inject'], + enum: ['function', 'array', '$inject'] }, { type: 'object', properties: { matchNames: { - type: 'boolean', + type: 'boolean' }, stripUnderscores: { - type: 'boolean', - }, - }, - }, - ], + type: 'boolean' + } + } + } + ] }, - create: angularRule(function (context) { + create: angularRule(function(context) { var syntax = context.options[0] || 'function'; var extra = context.options[1] || {}; @@ -48,7 +48,7 @@ module.exports = { node, 'You should use the {{syntax}} syntax for DI', { - syntax: syntax, + syntax: syntax } ); } @@ -70,7 +70,7 @@ module.exports = { } function normalizeParameter(param) { - return param.replace(/^_(.+)_$/, function (match, p1) { + return param.replace(/^_(.+)_$/, function(match, p1) { return p1; }); } @@ -92,7 +92,7 @@ module.exports = { } if (matchNames) { - var invalidArray = fn.params.filter(function (e, i) { + var invalidArray = fn.params.filter(function(e, i) { var name = e.name; if (stripUnderscores) { @@ -139,7 +139,7 @@ module.exports = { } if (matchNames) { - var invalidInjectArray = fn.params.filter(function ( + var invalidInjectArray = fn.params.filter(function( e, i ) { @@ -179,11 +179,11 @@ module.exports = { 'angular?inject': checkDi, 'angular?run': checkDi, 'angular?service': checkDi, - 'angular?provider': function (callee, providerFn, $get) { + 'angular?provider': function(callee, providerFn, $get) { checkDi(null, providerFn); checkDi(null, $get); }, - 'angular?component': function (callee) { + 'angular?component': function(callee) { var routeObject = callee.parent.arguments[1]; var elementLength = 0; @@ -191,13 +191,13 @@ module.exports = { var parameters = null; if (routeObject.properties) { - routeObject.properties.forEach(function (prop) { + routeObject.properties.forEach(function(prop) { if (prop.key.name === 'controller') { elements = prop.value.elements; if (elements.length) { elementLength = elements.length - 1; } - prop.value.elements.forEach(function (element) { + prop.value.elements.forEach(function(element) { if (element.type === 'FunctionExpression') { parameters = element.params; } @@ -216,7 +216,7 @@ module.exports = { } if (matchNames) { - var invalidArray = parameters.filter(function (e, i) { + var invalidArray = parameters.filter(function(e, i) { var name = e.name; if (stripUnderscores) { @@ -236,9 +236,9 @@ module.exports = { } } }, - AssignmentExpression: function (node) { + AssignmentExpression: function(node) { maybeNoteInjection(node); - }, + } }; - }), + }) }; From f8897f53647726ffc92e6f3b9e05af2733a0f1e4 Mon Sep 17 00:00:00 2001 From: gal koren Date: Fri, 22 Oct 2021 11:19:39 +0300 Subject: [PATCH 5/6] remove vscode folder --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index dc8891d5..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true - } -} \ No newline at end of file From 688da46146d01f153d2064560ece80264688b44e Mon Sep 17 00:00:00 2001 From: gal koren Date: Sat, 15 Jan 2022 14:16:00 +0200 Subject: [PATCH 6/6] remove warnings --- rules/service-name.js | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/rules/service-name.js b/rules/service-name.js index f801bff8..e7cedcc1 100644 --- a/rules/service-name.js +++ b/rules/service-name.js @@ -48,31 +48,6 @@ function getConfig(options) { return config; } -/** - * Used only by `ForDeprecatedBehavior()` for making sure it was run only one time - * @type {boolean} - */ -var didWarnForDeprecatedBehavior = false; - -/** - * Warn if API is deprecated - * @param {Array.<*>} options - */ -function warnForDeprecatedBehavior(options) { - if (didWarnForDeprecatedBehavior) { - return; - } - didWarnForDeprecatedBehavior = true; - - var config = getConfig(options); - - // /* istanbul ignore if */ - // if (config.oldBehavior) { - // // eslint-disable-next-line - // console.warn('The rule `angular/service-name` will be split up to different rules in the next version. Please read the docs for more information'); - // } -} - module.exports = { meta: { docs: { @@ -85,8 +60,6 @@ module.exports = { }] }, create: function(context) { - warnForDeprecatedBehavior(context.options); - return { CallExpression: function(node) {