From beb7b2fb492ad6c3aa3d0f901df99dcb739628c8 Mon Sep 17 00:00:00 2001 From: Simon Roberts Date: Fri, 27 Dec 2024 13:53:23 +1100 Subject: [PATCH] Various minor code cleanups, from WebStorm --- drivers/ebs.ts | 2 +- drivers/ec2.ts | 2 +- drivers/instrumentedResource.ts | 4 ++-- drivers/redshiftClusterSnapshot.ts | 2 +- lib/assume.ts | 2 +- lib/objectLog.ts | 1 + plugins/parsers/strict.ts | 2 +- plugins/powercycle.ts | 8 ++++---- revolver.ts | 2 +- test/lib/resourceLog.spec.ts | 6 +++--- tools/showSchedule.ts | 4 +++- 11 files changed, 19 insertions(+), 16 deletions(-) diff --git a/drivers/ebs.ts b/drivers/ebs.ts index 74f57a9..c43b34f 100644 --- a/drivers/ebs.ts +++ b/drivers/ebs.ts @@ -14,7 +14,7 @@ import { type InstrumentedResource, ToolingInterface } from './instrumentedResou import { ec2Tagger } from './tags.js'; class InstrumentedEBS extends ToolingInterface { - private volumeARN: string; + private readonly volumeARN: string; constructor(resource: CreateVolumeCommandOutput, volumeARN: string) { super(resource); diff --git a/drivers/ec2.ts b/drivers/ec2.ts index 0e49a33..f3de5b2 100644 --- a/drivers/ec2.ts +++ b/drivers/ec2.ts @@ -21,7 +21,7 @@ import { type InstrumentedResource, ToolingInterface } from './instrumentedResou import { ec2Tagger } from './tags.js'; class InstrumentedEc2 extends ToolingInterface { - private instanceARN: string; + private readonly instanceARN: string; constructor(resource: Instance, instanceARN: string) { super(resource); diff --git a/drivers/instrumentedResource.ts b/drivers/instrumentedResource.ts index b848cd1..2e4cedb 100644 --- a/drivers/instrumentedResource.ts +++ b/drivers/instrumentedResource.ts @@ -16,7 +16,7 @@ export interface InstrumentedResource { export abstract class ToolingInterface implements InstrumentedResource { public resource: any; public actions: RevolverAction[]; - private meta: any; + private readonly meta: any; constructor(awsResource: any) { this.resource = awsResource; @@ -41,7 +41,7 @@ export abstract class ToolingInterface implements InstrumentedResource { } // Try and see if we already have an action that can swallow this one for (const xa of this.actions.filter((xxa) => xxa.what === action.what)) { - if (xa.swallow(action) === true) { + if (xa.swallow(action)) { return; } } diff --git a/drivers/redshiftClusterSnapshot.ts b/drivers/redshiftClusterSnapshot.ts index cd34a37..3d96ce6 100644 --- a/drivers/redshiftClusterSnapshot.ts +++ b/drivers/redshiftClusterSnapshot.ts @@ -19,7 +19,7 @@ import { type InstrumentedResource, ToolingInterface } from './instrumentedResou class InstrumentedRedshiftClusterSnapshot extends ToolingInterface { public tags: Tag[] = []; - private snapshotARN: string; + private readonly snapshotARN: string; constructor(resource: Cluster, snapshotARN: string) { super(resource); diff --git a/lib/assume.ts b/lib/assume.ts index 5f16626..a13a908 100644 --- a/lib/assume.ts +++ b/lib/assume.ts @@ -11,7 +11,7 @@ export interface Creds { } class RemoteCredentials { - private creds: { [key: string]: Creds }; + private readonly creds: { [key: string]: Creds }; constructor() { this.creds = {}; diff --git a/lib/objectLog.ts b/lib/objectLog.ts index 2be71d0..4ec69a9 100644 --- a/lib/objectLog.ts +++ b/lib/objectLog.ts @@ -132,6 +132,7 @@ abstract class AbstractOutputWriter { } // here as reference, unused + // noinspection JSUnusedLocalSymbols private static decompress(compressedB64: string): string { return zlib.inflateSync(Buffer.from(compressedB64, 'base64')).toString('utf-8'); } diff --git a/plugins/parsers/strict.ts b/plugins/parsers/strict.ts index e799183..97c9495 100644 --- a/plugins/parsers/strict.ts +++ b/plugins/parsers/strict.ts @@ -211,7 +211,7 @@ class ParsedAvailability { function startOrStop(tag: string, timeNow: DateTime) { const t = new ParsedAvailability(tag); - if (t.override === true) { + if (t.override) { return ['NOOP', 'Availability override']; } else if (t.available === '24x7') { return ['START', 'Availability 24x7']; diff --git a/plugins/powercycle.ts b/plugins/powercycle.ts index 43550fc..bc21cb9 100644 --- a/plugins/powercycle.ts +++ b/plugins/powercycle.ts @@ -9,10 +9,10 @@ import { RevolverPlugin } from './pluginInterface.js'; */ export default class PowerCyclePlugin extends RevolverPlugin { private parser: any; - private scheduleTagName: string; - private timezoneTagName: string; - private warningTagName: string; - private reasonTagName: string; + private readonly scheduleTagName: string; + private readonly timezoneTagName: string; + private readonly warningTagName: string; + private readonly reasonTagName: string; protected supportedResources = [ 'ec2', 'rdsCluster', diff --git a/revolver.ts b/revolver.ts index ae77b60..179ad5b 100644 --- a/revolver.ts +++ b/revolver.ts @@ -76,7 +76,7 @@ async function main(config: any) { } // Filter final accounts list to be processed - const filteredAccountsList = await RevolverConfig.filterAccountsList(orgsAccountsList, config); + const filteredAccountsList = RevolverConfig.filterAccountsList(orgsAccountsList, config); // Try to assume role on the listed accounts and remove from the list if fails logger.info('Caching STS credentials...'); diff --git a/test/lib/resourceLog.spec.ts b/test/lib/resourceLog.spec.ts index 3c822ad..1d7e967 100644 --- a/test/lib/resourceLog.spec.ts +++ b/test/lib/resourceLog.spec.ts @@ -12,9 +12,9 @@ import { ObjectLogCsv, ObjectLogHtml, ObjectLogJson, ObjectLogTable, ResourceTab // A dummy AWS resource for testing class FakeResource extends ToolingInterface { - private myResourceId: string; - private myResourceType: string; - private myResourceState: string; + private readonly myResourceId: string; + private readonly myResourceType: string; + private readonly myResourceState: string; constructor(resourceId: string, resourceType: string, resourceState: string, resource: any) { super(resource); this.myResourceId = resourceId; diff --git a/tools/showSchedule.ts b/tools/showSchedule.ts index 524357a..5a2736c 100644 --- a/tools/showSchedule.ts +++ b/tools/showSchedule.ts @@ -15,8 +15,11 @@ const zeroPad = (num: any, places: number) => String(num).padStart(places, '0'); /** * Evaluate the schedule for every interval in the window and return a list of time:results. + * @param parser * @param schedule a Revolver schedule string * @param startTime when to start the test window + * @param testInterval how long between test steps + * @param testDuration total test duration * @returns a Map of DateTime to boolean representing "matches schedule" */ async function runSchedule( @@ -43,7 +46,6 @@ async function runSchedule( /** * Evaluate the schedule every `interval` within the `window` and print a table with results. * @param schedule a Revolver schedule string - * @param startTime when to start the test window * @returns a Map of DateTime to boolean representing "matches schedule" */ async function showSchedule(schedule: string) {