From e7bc53c38b2a906c6952a83c5262db521ea468fb Mon Sep 17 00:00:00 2001 From: ijemmy Date: Fri, 7 Jan 2022 14:36:41 +0100 Subject: [PATCH] fix(build): Fix linting issue and add linting to the pre-push hook (#440) --- .husky/pre-push | 1 + packages/metrics/src/Metrics.ts | 42 ++++++++++++++++----------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.husky/pre-push b/.husky/pre-push index d1096ab18a..771caa1dda 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,4 +1,5 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" +npm run lerna-lint npm run test diff --git a/packages/metrics/src/Metrics.ts b/packages/metrics/src/Metrics.ts index c6de6a8376..3afb21a6f4 100644 --- a/packages/metrics/src/Metrics.ts +++ b/packages/metrics/src/Metrics.ts @@ -281,27 +281,6 @@ class Metrics implements MetricsInterface { this.storedMetrics = {}; } - /** - * Throw an Error if the metrics buffer is empty. - * - * @example - * - * ```typescript - * import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics'; - * import { Context } from 'aws-lambda'; - * - * const metrics = new Metrics({namespace:"serverlessAirline", serviceName:"orders"}); - * - * export const handler = async (event: any, context: Context) => { - * metrics.throwOnEmptyMetrics(); - * metrics.publishStoredMetrics(); // will throw since no metrics added. - * } - * ``` - */ - public throwOnEmptyMetrics(): void { - this.shouldThrowOnEmptyMetrics = true; - } - /** * Function to create the right object compliant with Cloudwatch EMF (Event Metric Format). * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html for more details @@ -386,6 +365,27 @@ class Metrics implements MetricsInterface { }); } + /** + * Throw an Error if the metrics buffer is empty. + * + * @example + * + * ```typescript + * import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics'; + * import { Context } from 'aws-lambda'; + * + * const metrics = new Metrics({namespace:"serverlessAirline", serviceName:"orders"}); + * + * export const handler = async (event: any, context: Context) => { + * metrics.throwOnEmptyMetrics(); + * metrics.publishStoredMetrics(); // will throw since no metrics added. + * } + * ``` + */ + public throwOnEmptyMetrics(): void { + this.shouldThrowOnEmptyMetrics = true; + } + private getCurrentDimensionsCount(): number { return Object.keys(this.dimensions).length + Object.keys(this.defaultDimensions).length; }