From 02bc1021dd89d1a515b611de749be649a89709d2 Mon Sep 17 00:00:00 2001 From: Maggie Nolan Date: Tue, 25 May 2021 14:16:43 -0700 Subject: [PATCH] chore: run linter (#168) --- system-test/busybench/src/busybench.ts | 2 +- ts/src/profile-serializer.ts | 29 +++++++-------- ts/src/sourcemapper/sourcemapper.ts | 9 ++--- ts/test/profiles-for-tests.ts | 50 +++++++++++--------------- 4 files changed, 42 insertions(+), 48 deletions(-) diff --git a/system-test/busybench/src/busybench.ts b/system-test/busybench/src/busybench.ts index 24b3c86d..849f28cf 100644 --- a/system-test/busybench/src/busybench.ts +++ b/system-test/busybench/src/busybench.ts @@ -17,7 +17,7 @@ import {writeFile} from 'fs'; // eslint-disable-next-line node/no-extraneous-import import * as pify from 'pify'; -// eslint-disable-next-line node/no-missing-import +// eslint-disable-next-line node/no-extraneous-import import {encode, heap, SourceMapper, time} from 'pprof'; const writeFilePromise = pify(writeFile); diff --git a/ts/src/profile-serializer.ts b/ts/src/profile-serializer.ts index 4f7af006..6f2a5f39 100644 --- a/ts/src/profile-serializer.ts +++ b/ts/src/profile-serializer.ts @@ -326,21 +326,22 @@ export function serializeHeapProfile( ignoreSamplesPath?: string, sourceMapper?: SourceMapper ): perftools.profiles.IProfile { - const appendHeapEntryToSamples: AppendEntryToSamples = ( - entry: Entry, - samples: perftools.profiles.Sample[] - ) => { - if (entry.node.allocations.length > 0) { - for (const alloc of entry.node.allocations) { - const sample = new perftools.profiles.Sample({ - locationId: entry.stack, - value: [alloc.count, alloc.sizeBytes * alloc.count], - // TODO: add tag for allocation size - }); - samples.push(sample); + const appendHeapEntryToSamples: AppendEntryToSamples = + ( + entry: Entry, + samples: perftools.profiles.Sample[] + ) => { + if (entry.node.allocations.length > 0) { + for (const alloc of entry.node.allocations) { + const sample = new perftools.profiles.Sample({ + locationId: entry.stack, + value: [alloc.count, alloc.sizeBytes * alloc.count], + // TODO: add tag for allocation size + }); + samples.push(sample); + } } - } - }; + }; const stringTable = new StringTable(); const sampleValueType = createObjectCountValueType(stringTable); diff --git a/ts/src/sourcemapper/sourcemapper.ts b/ts/src/sourcemapper/sourcemapper.ts index a0c0d8d6..192b10e7 100644 --- a/ts/src/sourcemapper/sourcemapper.ts +++ b/ts/src/sourcemapper/sourcemapper.ts @@ -84,9 +84,9 @@ async function processSourceMap( // TODO: Resolve the cast of `contents as any` (This is needed because the // type is expected to be of `RawSourceMap` but the existing // working code uses a string.) - consumer = ((await new sourceMap.SourceMapConsumer( - (contents as {}) as sourceMap.RawSourceMap - )) as {}) as sourceMap.RawSourceMap; + consumer = (await new sourceMap.SourceMapConsumer( + contents as {} as sourceMap.RawSourceMap + )) as {} as sourceMap.RawSourceMap; } catch (e) { throw new Error( 'An error occurred while reading the ' + @@ -206,7 +206,8 @@ export class SourceMapper { const generatedPos = {line: location.line, column: location.column}; // TODO: Determine how to remove the explicit cast here. - const consumer: sourceMap.SourceMapConsumer = (entry.mapConsumer as {}) as sourceMap.SourceMapConsumer; + const consumer: sourceMap.SourceMapConsumer = + entry.mapConsumer as {} as sourceMap.SourceMapConsumer; const pos = consumer.originalPositionFor(generatedPos); if (pos.source === null) { diff --git a/ts/test/profiles-for-tests.ts b/ts/test/profiles-for-tests.ts index 740ed33d..ecd6abe9 100644 --- a/ts/test/profiles-for-tests.ts +++ b/ts/test/profiles-for-tests.ts @@ -183,9 +183,8 @@ export const timeProfile: perftools.profiles.IProfile = Object.freeze({ // timeProfile is encoded then decoded to convert numbers to longs, in // decodedTimeProfile -const encodedTimeProfile = perftools.profiles.Profile.encode( - timeProfile -).finish(); +const encodedTimeProfile = + perftools.profiles.Profile.encode(timeProfile).finish(); export const decodedTimeProfile = Object.freeze( perftools.profiles.Profile.decode(encodedTimeProfile) ); @@ -340,9 +339,8 @@ export const heapProfile: perftools.profiles.IProfile = Object.freeze({ // heapProfile is encoded then decoded to convert numbers to longs, in // decodedHeapProfile -const encodedHeapProfile = perftools.profiles.Profile.encode( - heapProfile -).finish(); +const encodedHeapProfile = + perftools.profiles.Profile.encode(heapProfile).finish(); export const decodedHeapProfile = Object.freeze( perftools.profiles.Profile.decode(encodedHeapProfile) ); @@ -396,8 +394,8 @@ const heapLocationsWithExternal = [ new perftools.profiles.Location({line: [heapLinesWithExternal[4]], id: 5}), ]; -export const heapProfileWithExternal: perftools.profiles.IProfile = Object.freeze( - { +export const heapProfileWithExternal: perftools.profiles.IProfile = + Object.freeze({ sampleType: [ new perftools.profiles.ValueType({type: 1, unit: 2}), new perftools.profiles.ValueType({type: 3, unit: 4}), @@ -452,14 +450,12 @@ export const heapProfileWithExternal: perftools.profiles.IProfile = Object.freez timeNanos: 0, periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, - } -); + }); // heapProfile is encoded then decoded to convert numbers to longs, in // decodedHeapProfile -const encodedHeapProfileWithExternal = perftools.profiles.Profile.encode( - heapProfile -).finish(); +const encodedHeapProfileWithExternal = + perftools.profiles.Profile.encode(heapProfile).finish(); export const decodedHeapProfileWithExternal = Object.freeze( perftools.profiles.Profile.decode(encodedHeapProfileWithExternal) ); @@ -501,8 +497,8 @@ const anonymousFunctionHeapLocations = [ }), ]; -export const anonymousFunctionHeapProfile: perftools.profiles.IProfile = Object.freeze( - { +export const anonymousFunctionHeapProfile: perftools.profiles.IProfile = + Object.freeze({ sampleType: [ new perftools.profiles.ValueType({type: 1, unit: 2}), new perftools.profiles.ValueType({type: 3, unit: 4}), @@ -528,8 +524,7 @@ export const anonymousFunctionHeapProfile: perftools.profiles.IProfile = Object. timeNanos: 0, periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, - } -); + }); const anonymousFunctionTimeNode = { scriptName: 'main', @@ -574,8 +569,8 @@ const anonymousFunctionTimeLocations = [ }), ]; -export const anonymousFunctionTimeProfile: perftools.profiles.IProfile = Object.freeze( - { +export const anonymousFunctionTimeProfile: perftools.profiles.IProfile = + Object.freeze({ sampleType: [ new perftools.profiles.ValueType({type: 1, unit: 2}), new perftools.profiles.ValueType({type: 3, unit: 4}), @@ -602,8 +597,7 @@ export const anonymousFunctionTimeProfile: perftools.profiles.IProfile = Object. durationNanos: 10 * 1000 * 1000 * 1000, periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 1000, - } -); + }); const heapWithPathLeaf1 = { name: 'foo2', @@ -721,8 +715,8 @@ const heapIncludePathLocations = [ }), ]; -export const heapProfileIncludePath: perftools.profiles.IProfile = Object.freeze( - { +export const heapProfileIncludePath: perftools.profiles.IProfile = + Object.freeze({ sampleType: [ new perftools.profiles.ValueType({type: 1, unit: 2}), new perftools.profiles.ValueType({type: 3, unit: 4}), @@ -764,8 +758,7 @@ export const heapProfileIncludePath: perftools.profiles.IProfile = Object.freeze timeNanos: 0, periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, - } -); + }); // heapProfile is encoded then decoded to convert numbers to longs, in // decodedHeapProfile @@ -802,8 +795,8 @@ const heapExcludePathLocations = [ }), ]; -export const heapProfileExcludePath: perftools.profiles.IProfile = Object.freeze( - { +export const heapProfileExcludePath: perftools.profiles.IProfile = + Object.freeze({ sampleType: [ new perftools.profiles.ValueType({type: 1, unit: 2}), new perftools.profiles.ValueType({type: 3, unit: 4}), @@ -830,8 +823,7 @@ export const heapProfileExcludePath: perftools.profiles.IProfile = Object.freeze timeNanos: 0, periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, - } -); + }); // heapProfile is encoded then decoded to convert numbers to longs, in // decodedHeapProfile