From ea79123b1fbd94b85ca1339a0f57b6cfa65a2939 Mon Sep 17 00:00:00 2001 From: ori livni Date: Sun, 1 Jan 2017 14:16:57 +0200 Subject: [PATCH 1/2] service-name warn only once if there is an oldBehavior=true --- rules/service-name.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/rules/service-name.js b/rules/service-name.js index bda6e20c..bd8f5ccd 100644 --- a/rules/service-name.js +++ b/rules/service-name.js @@ -44,7 +44,34 @@ 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); + + 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 = function(context) { + // Warn if needed for breaking changes in API in new versions + warnForDeprecatedBehavior(context.options); + return { CallExpression: function(node) { @@ -61,9 +88,6 @@ module.exports = function(context) { if (config.oldBehavior) { isService = utils.isAngularServiceDeclarationDeprecated(node); - // Warning that the API is deprecated - // 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'); } else { isService = utils.isAngularServiceDeclaration(node); } From d56afa6d2772b2d49cdf6b7fbb1bc5eb51cc005f Mon Sep 17 00:00:00 2001 From: ori livni Date: Sun, 5 Feb 2017 10:22:28 +0200 Subject: [PATCH 2/2] Don't cover console.warn of service-name rule, since there is no before/after hook for ESLint unit testing --- rules/service-name.js | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/service-name.js b/rules/service-name.js index bd8f5ccd..c177a17c 100644 --- a/rules/service-name.js +++ b/rules/service-name.js @@ -62,6 +62,7 @@ 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');