Skip to content

Commit 57e0d8f

Browse files
Michael Brewerdreamorosi
Michael Brewer
andauthored
chore(all): fix doc typos and apply basic lint recommendations (#444)
* chore(all): fix doc typos and apply basic lint recommendations - Simplify comparisons - Fix gramma or spelling on doc strings - Fix doc string typos * fix: Update packages/tracing/src/Tracer.ts Co-authored-by: Andrea Amorosi <[email protected]> * fix: Update packages/tracing/src/Tracer.ts Co-authored-by: Andrea Amorosi <[email protected]> Co-authored-by: Andrea Amorosi <[email protected]>
1 parent 45edd6d commit 57e0d8f

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed

Diff for: packages/logger/src/Logger.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import cloneDeep from 'lodash.clonedeep';
55
import merge from 'lodash.merge';
66
import { ConfigServiceInterface, EnvironmentVariablesService } from './config';
77
import type {
8+
ClassThatLogs,
89
Environment,
910
HandlerMethodDecorator,
1011
LambdaFunctionContext,
1112
LogAttributes,
12-
ClassThatLogs,
1313
LoggerOptions,
1414
LogItemExtraInput,
1515
LogItemMessage,
@@ -90,7 +90,7 @@ class Logger implements ClassThatLogs {
9090
}
9191

9292
public static evaluateColdStartOnce(): void {
93-
if (Logger.getColdStartEvaluatedValue() === false) {
93+
if (!Logger.getColdStartEvaluatedValue()) {
9494
Logger.evaluateColdStart();
9595
}
9696
}
@@ -117,9 +117,8 @@ class Logger implements ClassThatLogs {
117117

118118
descriptor.value = (event, context, callback) => {
119119
this.addContext(context);
120-
const result = originalMethod?.apply(this, [ event, context, callback ]);
121120

122-
return result;
121+
return originalMethod?.apply(this, [ event, context, callback ]);
123122
};
124123
};
125124
}
@@ -181,7 +180,7 @@ class Logger implements ClassThatLogs {
181180
const coldStartValue = Logger.getColdStartValue();
182181
if (typeof coldStartValue === 'undefined') {
183182
Logger.setColdStartValue(true);
184-
} else if (coldStartValue === true) {
183+
} else if (coldStartValue) {
185184
Logger.setColdStartValue(false);
186185
} else {
187186
Logger.setColdStartValue(false);

Diff for: packages/logger/src/log/LogItemInterface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LogAttributes } from '../types/Log';
1+
import { LogAttributes } from '../types';
22

33
interface LogItemInterface {
44

Diff for: packages/logger/src/types/formats/PowertoolLog.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type PowertoolLog = LogAttributes & {
3737
/**
3838
* message
3939
*
40-
* Description: Log statement value. Unserializable JSON values will be casted to string.
40+
* Description: Log statement value. Unserializable JSON values will be cast to string.
4141
* Example: "Collecting payment"
4242
*/
4343
message?: string

Diff for: packages/tracing/src/Tracer.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ class Tracer implements TracerInterface {
144144
* @param error - Error to serialize as metadata
145145
*/
146146
public addErrorAsMetadata(error: Error): void {
147-
if (this.isTracingEnabled() === false) {
147+
if (!this.isTracingEnabled()) {
148148
return;
149149
}
150150

151151
const subsegment = this.getSegment();
152-
if (this.captureError === false) {
152+
if (!this.captureError) {
153153
subsegment.addErrorFlag();
154154

155155
return;
@@ -167,7 +167,7 @@ class Tracer implements TracerInterface {
167167
* @param methodName - Name of the method that is being traced
168168
*/
169169
public addResponseAsMetadata(data?: unknown, methodName?: string): void {
170-
if (data === undefined || this.captureResponse === false || this.isTracingEnabled() === false) {
170+
if (data === undefined || !this.captureResponse || !this.isTracingEnabled()) {
171171
return;
172172
}
173173

@@ -179,7 +179,7 @@ class Tracer implements TracerInterface {
179179
*
180180
*/
181181
public addServiceNameAnnotation(): void {
182-
if (this.isTracingEnabled() === false || this.serviceName === undefined) {
182+
if (!this.isTracingEnabled() || this.serviceName === undefined) {
183183
return;
184184
}
185185
this.putAnnotation('Service', this.serviceName);
@@ -188,17 +188,17 @@ class Tracer implements TracerInterface {
188188
/**
189189
* Add ColdStart annotation to the current segment or subsegment.
190190
*
191-
* If Tracer has been initialized outside of the Lambda handler then the same instance
192-
* of Tracer will be reused throghout the lifecycle of that same Lambda execution environment
191+
* If Tracer has been initialized outside the Lambda handler then the same instance
192+
* of Tracer will be reused throughout the lifecycle of that same Lambda execution environment
193193
* and this method will annotate `ColdStart: false` after the first invocation.
194194
*
195195
* @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html
196196
*/
197197
public annotateColdStart(): void {
198-
if (this.isTracingEnabled() === true) {
198+
if (this.isTracingEnabled()) {
199199
this.putAnnotation('ColdStart', Tracer.coldStart);
200200
}
201-
if (Tracer.coldStart === true) {
201+
if (Tracer.coldStart) {
202202
Tracer.coldStart = false;
203203
}
204204
}
@@ -226,7 +226,7 @@ class Tracer implements TracerInterface {
226226
* @returns AWS - Instrumented AWS SDK
227227
*/
228228
public captureAWS<T>(aws: T): T {
229-
if (this.isTracingEnabled() === false) return aws;
229+
if (!this.isTracingEnabled()) return aws;
230230

231231
return this.provider.captureAWS(aws);
232232
}
@@ -255,7 +255,7 @@ class Tracer implements TracerInterface {
255255
* @returns service - Instrumented AWS SDK v2 client
256256
*/
257257
public captureAWSClient<T>(service: T): T {
258-
if (this.isTracingEnabled() === false) return service;
258+
if (!this.isTracingEnabled()) return service;
259259

260260
return this.provider.captureAWSClient(service);
261261
}
@@ -285,7 +285,7 @@ class Tracer implements TracerInterface {
285285
* @returns service - Instrumented AWS SDK v3 client
286286
*/
287287
public captureAWSv3Client<T>(service: T): T {
288-
if (this.isTracingEnabled() === false) return service;
288+
if (!this.isTracingEnabled()) return service;
289289

290290
return this.provider.captureAWSv3Client(service);
291291
}
@@ -326,7 +326,7 @@ class Tracer implements TracerInterface {
326326
const originalMethod = descriptor.value;
327327

328328
descriptor.value = ((event, context, callback) => {
329-
if (this.isTracingEnabled() === false) {
329+
if (!this.isTracingEnabled()) {
330330
return originalMethod?.apply(target, [ event, context, callback ]);
331331
}
332332

@@ -393,7 +393,7 @@ class Tracer implements TracerInterface {
393393
const originalMethod = descriptor.value;
394394

395395
descriptor.value = (...args: unknown[]) => {
396-
if (this.isTracingEnabled() === false) {
396+
if (!this.isTracingEnabled()) {
397397
return originalMethod?.apply(target, [...args]);
398398
}
399399

@@ -421,16 +421,16 @@ class Tracer implements TracerInterface {
421421
/**
422422
* Retrieve the current value of `ColdStart`.
423423
*
424-
* If Tracer has been initialized outside of the Lambda handler then the same instance
425-
* of Tracer will be reused throghout the lifecycle of that same Lambda execution environment
424+
* If Tracer has been initialized outside the Lambda handler then the same instance
425+
* of Tracer will be reused throughout the lifecycle of that same Lambda execution environment
426426
* and this method will return `false` after the first invocation.
427427
*
428428
* @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html
429429
*
430430
* @returns boolean - `true` if is cold start, otherwise `false`
431431
*/
432432
public static getColdStart(): boolean {
433-
if (Tracer.coldStart === true) {
433+
if (Tracer.coldStart) {
434434
Tracer.coldStart = false;
435435

436436
return true;
@@ -505,7 +505,7 @@ class Tracer implements TracerInterface {
505505
* @param value - Value for annotation
506506
*/
507507
public putAnnotation(key: string, value: string | number | boolean): void {
508-
if (this.isTracingEnabled() === false) return;
508+
if (!this.isTracingEnabled()) return;
509509

510510
const document = this.getSegment();
511511
if (document instanceof Segment) {
@@ -535,10 +535,10 @@ class Tracer implements TracerInterface {
535535
*
536536
* @param key - Metadata key
537537
* @param value - Value for metadata
538-
* @param timestamp - Namespace that metadata will lie under, if none is passed it will use the serviceName
538+
* @param namespace - Namespace that metadata will lie under, if none is passed it will use the serviceName
539539
*/
540540
public putMetadata(key: string, value: unknown, namespace?: string | undefined): void {
541-
if (this.isTracingEnabled() === false) return;
541+
if (!this.isTracingEnabled()) return;
542542

543543
const document = this.getSegment();
544544
if (document instanceof Segment) {
@@ -617,7 +617,7 @@ class Tracer implements TracerInterface {
617617
*
618618
* @param serviceName - Service name to validate
619619
*/
620-
private isValidServiceName(serviceName?: string): boolean {
620+
private static isValidServiceName(serviceName?: string): boolean {
621621
return typeof serviceName === 'string' && serviceName.trim().length > 0;
622622
}
623623

@@ -709,21 +709,21 @@ class Tracer implements TracerInterface {
709709
* @param serviceName - Name of the service to use
710710
*/
711711
private setServiceName(serviceName?: string): void {
712-
if (serviceName !== undefined && this.isValidServiceName(serviceName)) {
712+
if (serviceName !== undefined && Tracer.isValidServiceName(serviceName)) {
713713
this.serviceName = serviceName;
714714

715715
return;
716716
}
717717

718718
const customConfigValue = this.getCustomConfigService()?.getServiceName();
719-
if (customConfigValue !== undefined && this.isValidServiceName(customConfigValue)) {
719+
if (customConfigValue !== undefined && Tracer.isValidServiceName(customConfigValue)) {
720720
this.serviceName = customConfigValue;
721721

722722
return;
723723
}
724724

725725
const envVarsValue = this.getEnvVarsService()?.getServiceName();
726-
if (envVarsValue !== undefined && this.isValidServiceName(envVarsValue)) {
726+
if (envVarsValue !== undefined && Tracer.isValidServiceName(envVarsValue)) {
727727
this.serviceName = envVarsValue;
728728

729729
return;
@@ -737,7 +737,7 @@ class Tracer implements TracerInterface {
737737
* @param enabled - Whether or not tracing is enabled
738738
*/
739739
private setTracingEnabled(enabled?: boolean): void {
740-
if (enabled !== undefined && enabled === false) {
740+
if (enabled !== undefined && !enabled) {
741741
this.tracingEnabled = enabled;
742742

743743
return;
@@ -757,7 +757,7 @@ class Tracer implements TracerInterface {
757757
return;
758758
}
759759

760-
if (this.isLambdaSamCli() || this.isLambdaExecutionEnv() === false) {
760+
if (this.isLambdaSamCli() || !this.isLambdaExecutionEnv()) {
761761
this.tracingEnabled = false;
762762
}
763763
}

Diff for: packages/tracing/src/middleware/middy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Segment, Subsegment } from 'aws-xray-sdk-core';
2323
* }).use(captureLambdaHandler(tracer));
2424
* ```
2525
*
26-
* @param tracer - The Tracer instance to use for tracing
26+
* @param target - The Tracer instance to use for tracing
2727
* @returns middleware object - The middy middleware object
2828
*/
2929
const captureLambdaHandler = (target: Tracer): middy.MiddlewareObj => {

0 commit comments

Comments
 (0)