diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..e21434e3 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules +**/coverage +build/ +proto/ +out/ diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..78215349 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/gts" +} diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000..3435cc0b --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,18 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +module.exports = { + endOfLine:"auto", + ...require('gts/.prettierrc.json') + } diff --git a/package.json b/package.json index 5b0c1722..76e92c90 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "@types/tmp": "0.2.0", "codecov": "^3.0.0", "deep-copy": "^1.4.2", - "gts": "^1.0.0", + "gts": "^3.0.0", "js-green-licenses": "^2.0.0", "linkinator": "^2.0.0", "mocha": "^8.0.0", diff --git a/system-test/busybench-js/src/busybench.js b/system-test/busybench-js/src/busybench.js index d7a49ffc..87bdf123 100644 --- a/system-test/busybench-js/src/busybench.js +++ b/system-test/busybench-js/src/busybench.js @@ -15,7 +15,9 @@ */ const fs = require('fs'); +// eslint-disable-next-line node/no-extraneous-require const pify = require('pify'); +// eslint-disable-next-line node/no-missing-require const pprof = require('pprof'); const writeFilePromise = pify(fs.writeFile); @@ -46,8 +48,11 @@ function benchmark(durationSeconds) { busyLoop(durationSeconds); } -async function collectAndSaveTimeProfile(durationSeconds, sourceMapper, - lineNumbers) { +async function collectAndSaveTimeProfile( + durationSeconds, + sourceMapper, + lineNumbers +) { const profile = await pprof.time.profile({ durationMillis: 1000 * durationSeconds, lineNumbers: lineNumbers, @@ -64,13 +69,19 @@ async function collectAndSaveHeapProfile(sourceMapper) { } async function collectAndSaveProfiles(collectLineNumberTimeProfile) { - const sourceMapper = await pprof.SourceMapper.create([process.cwd()]); + const sourceMapper = await pprof.SourceMapper.create([process.cwd()]); collectAndSaveHeapProfile(sourceMapper); - collectAndSaveTimeProfile(durationSeconds/2, sourceMapper, collectLineNumberTimeProfile); + collectAndSaveTimeProfile( + durationSeconds / 2, + sourceMapper, + collectLineNumberTimeProfile + ); } const durationSeconds = Number(process.argv.length > 2 ? process.argv[2] : 30); -const collectLineNumberTimeProfile = Boolean(process.argv.length > 3 ? process.argv[3] : false); +const collectLineNumberTimeProfile = Boolean( + process.argv.length > 3 ? process.argv[3] : false +); pprof.heap.start(512 * 1024, 64); benchmark(durationSeconds); diff --git a/system-test/busybench/src/busybench.ts b/system-test/busybench/src/busybench.ts index 73bd318b..24b3c86d 100644 --- a/system-test/busybench/src/busybench.ts +++ b/system-test/busybench/src/busybench.ts @@ -15,7 +15,9 @@ */ 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 import {encode, heap, SourceMapper, time} from 'pprof'; const writeFilePromise = pify(writeFile); @@ -47,15 +49,20 @@ function benchmark(durationSeconds: number) { } async function collectAndSaveTimeProfile( - durationSeconds: number, sourceMapper: SourceMapper): Promise { - const profile = await time.profile( - {durationMillis: 1000 * durationSeconds, sourceMapper}); + durationSeconds: number, + sourceMapper: SourceMapper +): Promise { + const profile = await time.profile({ + durationMillis: 1000 * durationSeconds, + sourceMapper, + }); const buf = await encode(profile); await writeFilePromise('time.pb.gz', buf); } -async function collectAndSaveHeapProfile(sourceMapper: SourceMapper): - Promise { +async function collectAndSaveHeapProfile( + sourceMapper: SourceMapper +): Promise { const profile = await heap.profile(undefined, sourceMapper); const buf = await encode(profile); await writeFilePromise('heap.pb.gz', buf); diff --git a/ts/src/heap-profiler-bindings.ts b/ts/src/heap-profiler-bindings.ts index aa50d472..72b39048 100644 --- a/ts/src/heap-profiler-bindings.ts +++ b/ts/src/heap-profiler-bindings.ts @@ -16,7 +16,7 @@ import * as path from 'path'; -import { AllocationProfileNode } from './v8-types'; +import {AllocationProfileNode} from './v8-types'; const binary = require('node-pre-gyp'); const bindingPath = binary.find( diff --git a/ts/src/heap-profiler.ts b/ts/src/heap-profiler.ts index 9fb82960..475836d9 100644 --- a/ts/src/heap-profiler.ts +++ b/ts/src/heap-profiler.ts @@ -14,16 +14,16 @@ * limitations under the License. */ -import { perftools } from '../../proto/profile'; +import {perftools} from '../../proto/profile'; import { getAllocationProfile, startSamplingHeapProfiler, stopSamplingHeapProfiler, } from './heap-profiler-bindings'; -import { serializeHeapProfile } from './profile-serializer'; -import { SourceMapper } from './sourcemapper/sourcemapper'; -import { AllocationProfileNode } from './v8-types'; +import {serializeHeapProfile} from './profile-serializer'; +import {SourceMapper} from './sourcemapper/sourcemapper'; +import {AllocationProfileNode} from './v8-types'; let enabled = false; let heapIntervalBytes = 0; @@ -58,14 +58,14 @@ export function profile( // Add node for external memory usage. // Current type definitions do not have external. // TODO: remove any once type definition is updated to include external. - // tslint:disable-next-line: no-any - const { external }: { external: number } = process.memoryUsage() as any; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const {external}: {external: number} = process.memoryUsage() as any; if (external > 0) { const externalNode: AllocationProfileNode = { name: '(external)', scriptName: '', children: [], - allocations: [{ sizeBytes: external, count: 1 }], + allocations: [{sizeBytes: external, count: 1}], }; result.children.push(externalNode); } diff --git a/ts/src/index.ts b/ts/src/index.ts index 48a815bc..8f7bf9db 100644 --- a/ts/src/index.ts +++ b/ts/src/index.ts @@ -13,19 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { writeFileSync } from 'fs'; +import {writeFileSync} from 'fs'; import * as heapProfiler from './heap-profiler'; -import { encodeSync } from './profile-encoder'; +import {encodeSync} from './profile-encoder'; import * as timeProfiler from './time-profiler'; -export { - AllocationProfileNode, - TimeProfileNode, - ProfileNode, -} from './v8-types'; +export {AllocationProfileNode, TimeProfileNode, ProfileNode} from './v8-types'; -export { encode, encodeSync } from './profile-encoder'; -export { SourceMapper } from './sourcemapper/sourcemapper'; +export {encode, encodeSync} from './profile-encoder'; +export {SourceMapper} from './sourcemapper/sourcemapper'; export const time = { profile: timeProfiler.profile, diff --git a/ts/src/profile-encoder.ts b/ts/src/profile-encoder.ts index ba30039e..0c29f81b 100644 --- a/ts/src/profile-encoder.ts +++ b/ts/src/profile-encoder.ts @@ -15,9 +15,9 @@ */ import * as pify from 'pify'; -import { gzip, gzipSync } from 'zlib'; +import {gzip, gzipSync} from 'zlib'; -import { perftools } from '../../proto/profile'; +import {perftools} from '../../proto/profile'; const gzipPromise = pify(gzip); diff --git a/ts/src/profile-serializer.ts b/ts/src/profile-serializer.ts index bf47d5b1..4f7af006 100644 --- a/ts/src/profile-serializer.ts +++ b/ts/src/profile-serializer.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { perftools } from '../../proto/profile'; +import {perftools} from '../../proto/profile'; import { GeneratedLocation, SourceLocation, @@ -111,8 +111,6 @@ function serialize( const samples: perftools.profiles.Sample[] = []; const locations: perftools.profiles.Location[] = []; const functions: perftools.profiles.Function[] = []; - const locationMap: Map = new Map(); - const functionMap: Map = new Map(); const functionIdMap = new Map(); const locationIdMap = new Map(); @@ -131,7 +129,7 @@ function serialize( stack.unshift(location.id as number); appendToSamples(entry, samples); for (const child of node.children as T[]) { - entries.push({ node: child, stack: stack.slice() }); + entries.push({node: child, stack: stack.slice()}); } } @@ -170,7 +168,7 @@ function serialize( profLoc.name, profLoc.line ); - const location = new perftools.profiles.Location({ id, line: [line] }); + const location = new perftools.profiles.Location({id, line: [line]}); locations.push(location); return location; } diff --git a/ts/src/sourcemapper/sourcemapper.ts b/ts/src/sourcemapper/sourcemapper.ts index bb9759a5..a0c0d8d6 100644 --- a/ts/src/sourcemapper/sourcemapper.ts +++ b/ts/src/sourcemapper/sourcemapper.ts @@ -109,7 +109,7 @@ async function processSourceMap( : path.basename(mapPath, MAP_EXT); const generatedPath = path.resolve(dir, generatedBase); - infoMap.set(generatedPath, { mapFileDir: dir, mapConsumer: consumer }); + infoMap.set(generatedPath, {mapFileDir: dir, mapConsumer: consumer}); } export class SourceMapper { @@ -203,7 +203,7 @@ export class SourceMapper { return location; } - const generatedPos = { line: location.line, column: location.column }; + 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; diff --git a/ts/src/time-profiler-bindings.ts b/ts/src/time-profiler-bindings.ts index 62d0aca8..7c3ce87a 100644 --- a/ts/src/time-profiler-bindings.ts +++ b/ts/src/time-profiler-bindings.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import * as path from 'path'; -import { TimeProfile } from './v8-types'; +import {TimeProfile} from './v8-types'; const binary = require('node-pre-gyp'); const bindingPath = binary.find( diff --git a/ts/src/time-profiler.ts b/ts/src/time-profiler.ts index 12491641..f9296bc8 100644 --- a/ts/src/time-profiler.ts +++ b/ts/src/time-profiler.ts @@ -16,8 +16,8 @@ import delay from 'delay'; -import { serializeTimeProfile } from './profile-serializer'; -import { SourceMapper } from './sourcemapper/sourcemapper'; +import {serializeTimeProfile} from './profile-serializer'; +import {SourceMapper} from './sourcemapper/sourcemapper'; import { setSamplingInterval, startProfiling, @@ -77,13 +77,13 @@ export function start( // code. Ideally this should be default behavior. Until then, use the // undocumented API. // See https://github.com/nodejs/node/issues/19009#issuecomment-403161559. - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (process as any)._startProfilerIdleNotifier(); startProfiling(runName, lineNumbers); return function stop() { profiling = false; const result = stopProfiling(runName, lineNumbers); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (process as any)._stopProfilerIdleNotifier(); const profile = serializeTimeProfile(result, intervalMicros, sourceMapper); return profile; diff --git a/ts/test/profiles-for-tests.ts b/ts/test/profiles-for-tests.ts index 5d4f35a3..740ed33d 100644 --- a/ts/test/profiles-for-tests.ts +++ b/ts/test/profiles-for-tests.ts @@ -16,11 +16,11 @@ import * as fs from 'fs'; import * as path from 'path'; -import { SourceMapGenerator } from 'source-map'; +import {SourceMapGenerator} from 'source-map'; import * as tmp from 'tmp'; -import { perftools } from '../../proto/profile'; -import { TimeProfile } from '../src/v8-types'; +import {perftools} from '../../proto/profile'; +import {TimeProfile} from '../src/v8-types'; const timeLeaf1 = { name: 'function1', @@ -89,10 +89,10 @@ export const v8TimeProfile: TimeProfile = Object.freeze({ }); const timeLines = [ - { functionId: 1, line: 1 }, - { functionId: 2, line: 5 }, - { functionId: 3, line: 15 }, - { functionId: 2, line: 10 }, + {functionId: 1, line: 1}, + {functionId: 2, line: 5}, + {functionId: 3, line: 15}, + {functionId: 2, line: 10}, ]; const timeFunctions = [ @@ -137,8 +137,8 @@ const timeLocations = [ export const timeProfile: perftools.profiles.IProfile = Object.freeze({ sampleType: [ - new perftools.profiles.ValueType({ type: 1, unit: 2 }), - new perftools.profiles.ValueType({ type: 3, unit: 4 }), + new perftools.profiles.ValueType({type: 1, unit: 2}), + new perftools.profiles.ValueType({type: 3, unit: 4}), ], sample: [ new perftools.profiles.Sample({ @@ -177,7 +177,7 @@ export const timeProfile: perftools.profiles.IProfile = Object.freeze({ ], timeNanos: 0, durationNanos: 10 * 1000 * 1000 * 1000, - periodType: new perftools.profiles.ValueType({ type: 3, unit: 4 }), + periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 1000, }); @@ -196,7 +196,7 @@ const heapLeaf1 = { scriptId: 1, lineNumber: 8, columnNumber: 5, - allocations: [{ count: 5, sizeBytes: 1024 }], + allocations: [{count: 5, sizeBytes: 1024}], children: [], }; @@ -207,8 +207,8 @@ const heapLeaf2 = { lineNumber: 10, columnNumber: 5, allocations: [ - { count: 8, sizeBytes: 10 }, - { count: 15, sizeBytes: 72 }, + {count: 8, sizeBytes: 10}, + {count: 15, sizeBytes: 72}, ], children: [], }; @@ -230,8 +230,8 @@ const heapNode1 = { lineNumber: 1, columnNumber: 5, allocations: [ - { count: 1, sizeBytes: 5 }, - { count: 3, sizeBytes: 7 }, + {count: 1, sizeBytes: 5}, + {count: 3, sizeBytes: 7}, ], children: [heapNode2], }; @@ -247,10 +247,10 @@ export const v8HeapProfile = Object.freeze({ }); const heapLines = [ - { functionId: 1, line: 1 }, - { functionId: 2, line: 5 }, - { functionId: 3, line: 10 }, - { functionId: 4, line: 8 }, + {functionId: 1, line: 1}, + {functionId: 2, line: 5}, + {functionId: 3, line: 10}, + {functionId: 4, line: 8}, ]; const heapFunctions = [ @@ -281,16 +281,16 @@ const heapFunctions = [ ]; const heapLocations = [ - new perftools.profiles.Location({ line: [heapLines[0]], id: 1 }), - new perftools.profiles.Location({ line: [heapLines[1]], id: 2 }), - new perftools.profiles.Location({ line: [heapLines[2]], id: 3 }), - new perftools.profiles.Location({ line: [heapLines[3]], id: 4 }), + new perftools.profiles.Location({line: [heapLines[0]], id: 1}), + new perftools.profiles.Location({line: [heapLines[1]], id: 2}), + new perftools.profiles.Location({line: [heapLines[2]], id: 3}), + new perftools.profiles.Location({line: [heapLines[3]], id: 4}), ]; export const heapProfile: perftools.profiles.IProfile = Object.freeze({ sampleType: [ - new perftools.profiles.ValueType({ type: 1, unit: 2 }), - new perftools.profiles.ValueType({ type: 3, unit: 4 }), + new perftools.profiles.ValueType({type: 1, unit: 2}), + new perftools.profiles.ValueType({type: 3, unit: 4}), ], sample: [ new perftools.profiles.Sample({ @@ -334,7 +334,7 @@ export const heapProfile: perftools.profiles.IProfile = Object.freeze({ 'function2', ], timeNanos: 0, - periodType: new perftools.profiles.ValueType({ type: 3, unit: 4 }), + periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, }); @@ -348,11 +348,11 @@ export const decodedHeapProfile = Object.freeze( ); const heapLinesWithExternal = [ - { functionId: 1 }, - { functionId: 2, line: 1 }, - { functionId: 3, line: 5 }, - { functionId: 4, line: 10 }, - { functionId: 5, line: 8 }, + {functionId: 1}, + {functionId: 2, line: 1}, + {functionId: 3, line: 5}, + {functionId: 4, line: 10}, + {functionId: 5, line: 8}, ]; const heapFunctionsWithExternal = [ @@ -389,18 +389,18 @@ const heapFunctionsWithExternal = [ ]; const heapLocationsWithExternal = [ - new perftools.profiles.Location({ line: [heapLinesWithExternal[0]], id: 1 }), - new perftools.profiles.Location({ line: [heapLinesWithExternal[1]], id: 2 }), - new perftools.profiles.Location({ line: [heapLinesWithExternal[2]], id: 3 }), - new perftools.profiles.Location({ line: [heapLinesWithExternal[3]], id: 4 }), - new perftools.profiles.Location({ line: [heapLinesWithExternal[4]], id: 5 }), + new perftools.profiles.Location({line: [heapLinesWithExternal[0]], id: 1}), + new perftools.profiles.Location({line: [heapLinesWithExternal[1]], id: 2}), + new perftools.profiles.Location({line: [heapLinesWithExternal[2]], id: 3}), + new perftools.profiles.Location({line: [heapLinesWithExternal[3]], id: 4}), + new perftools.profiles.Location({line: [heapLinesWithExternal[4]], id: 5}), ]; 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 }), + new perftools.profiles.ValueType({type: 1, unit: 2}), + new perftools.profiles.ValueType({type: 3, unit: 4}), ], sample: [ new perftools.profiles.Sample({ @@ -450,7 +450,7 @@ export const heapProfileWithExternal: perftools.profiles.IProfile = Object.freez 'function2', ], timeNanos: 0, - periodType: new perftools.profiles.ValueType({ type: 3, unit: 4 }), + periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, } ); @@ -461,7 +461,7 @@ const encodedHeapProfileWithExternal = perftools.profiles.Profile.encode( heapProfile ).finish(); export const decodedHeapProfileWithExternal = Object.freeze( - perftools.profiles.Profile.decode(encodedHeapProfile) + perftools.profiles.Profile.decode(encodedHeapProfileWithExternal) ); const anonymousHeapNode = { @@ -469,7 +469,7 @@ const anonymousHeapNode = { scriptId: 0, lineNumber: 1, columnNumber: 5, - allocations: [{ count: 1, sizeBytes: 5 }], + allocations: [{count: 1, sizeBytes: 5}], children: [], }; @@ -483,7 +483,7 @@ export const v8AnonymousFunctionHeapProfile = Object.freeze({ children: [anonymousHeapNode], }); -const anonymousFunctionHeapLines = [{ functionId: 1, line: 1 }]; +const anonymousFunctionHeapLines = [{functionId: 1, line: 1}]; const anonymousFunctionHeapFunctions = [ new perftools.profiles.Function({ @@ -495,14 +495,17 @@ const anonymousFunctionHeapFunctions = [ ]; const anonymousFunctionHeapLocations = [ - new perftools.profiles.Location({ line: [heapLines[0]], id: 1 }), + new perftools.profiles.Location({ + line: [anonymousFunctionHeapLines[0]], + id: 1, + }), ]; 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 }), + new perftools.profiles.ValueType({type: 1, unit: 2}), + new perftools.profiles.ValueType({type: 3, unit: 4}), ], sample: [ new perftools.profiles.Sample({ @@ -523,7 +526,7 @@ export const anonymousFunctionHeapProfile: perftools.profiles.IProfile = Object. 'main', ], timeNanos: 0, - periodType: new perftools.profiles.ValueType({ type: 3, unit: 4 }), + periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, } ); @@ -553,7 +556,7 @@ export const v8AnonymousFunctionTimeProfile: TimeProfile = Object.freeze({ topDownRoot: anonymousFunctionTimeRoot, }); -const anonymousFunctionTimeLines = [{ functionId: 1, line: 1 }]; +const anonymousFunctionTimeLines = [{functionId: 1, line: 1}]; const anonymousFunctionTimeFunctions = [ new perftools.profiles.Function({ @@ -566,7 +569,7 @@ const anonymousFunctionTimeFunctions = [ const anonymousFunctionTimeLocations = [ new perftools.profiles.Location({ - line: [timeLines[0]], + line: [anonymousFunctionTimeLines[0]], id: 1, }), ]; @@ -574,8 +577,8 @@ const anonymousFunctionTimeLocations = [ 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 }), + new perftools.profiles.ValueType({type: 1, unit: 2}), + new perftools.profiles.ValueType({type: 3, unit: 4}), ], sample: [ new perftools.profiles.Sample({ @@ -597,7 +600,7 @@ export const anonymousFunctionTimeProfile: perftools.profiles.IProfile = Object. ], timeNanos: 0, durationNanos: 10 * 1000 * 1000 * 1000, - periodType: new perftools.profiles.ValueType({ type: 3, unit: 4 }), + periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 1000, } ); @@ -608,7 +611,7 @@ const heapWithPathLeaf1 = { scriptId: 0, lineNumber: 3, columnNumber: 3, - allocations: [{ count: 1, sizeBytes: 2 }], + allocations: [{count: 1, sizeBytes: 2}], children: [], }; @@ -618,7 +621,7 @@ const heapWithPathLeaf2 = { scriptId: 1, lineNumber: 10, columnNumber: 5, - allocations: [{ count: 2, sizeBytes: 2 }], + allocations: [{count: 2, sizeBytes: 2}], children: [], }; @@ -628,7 +631,7 @@ const heapWithPathLeaf3 = { scriptId: 2, lineNumber: 3, columnNumber: 3, - allocations: [{ count: 3, sizeBytes: 2 }], + allocations: [{count: 3, sizeBytes: 2}], children: [], }; @@ -697,23 +700,23 @@ const heapIncludePathFunctions = [ const heapIncludePathLocations = [ new perftools.profiles.Location({ - line: [{ functionId: 1, line: 1 }], + line: [{functionId: 1, line: 1}], id: 1, }), new perftools.profiles.Location({ - line: [{ functionId: 2, line: 10 }], + line: [{functionId: 2, line: 10}], id: 2, }), new perftools.profiles.Location({ - line: [{ functionId: 3, line: 3 }], + line: [{functionId: 3, line: 3}], id: 3, }), new perftools.profiles.Location({ - line: [{ functionId: 4, line: 2 }], + line: [{functionId: 4, line: 2}], id: 4, }), new perftools.profiles.Location({ - line: [{ functionId: 5, line: 3 }], + line: [{functionId: 5, line: 3}], id: 5, }), ]; @@ -721,8 +724,8 @@ const heapIncludePathLocations = [ 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 }), + new perftools.profiles.ValueType({type: 1, unit: 2}), + new perftools.profiles.ValueType({type: 3, unit: 4}), ], sample: [ new perftools.profiles.Sample({ @@ -759,7 +762,7 @@ export const heapProfileIncludePath: perftools.profiles.IProfile = Object.freeze 'bar.ts', ], timeNanos: 0, - periodType: new perftools.profiles.ValueType({ type: 3, unit: 4 }), + periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, } ); @@ -790,11 +793,11 @@ const heapExcludePathFunctions = [ const heapExcludePathLocations = [ new perftools.profiles.Location({ - line: [{ functionId: 1, line: 1 }], + line: [{functionId: 1, line: 1}], id: 1, }), new perftools.profiles.Location({ - line: [{ functionId: 2, line: 3 }], + line: [{functionId: 2, line: 3}], id: 2, }), ]; @@ -802,8 +805,8 @@ const heapExcludePathLocations = [ 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 }), + new perftools.profiles.ValueType({type: 1, unit: 2}), + new perftools.profiles.ValueType({type: 3, unit: 4}), ], sample: [ new perftools.profiles.Sample({ @@ -825,7 +828,7 @@ export const heapProfileExcludePath: perftools.profiles.IProfile = Object.freeze 'foo2', ], timeNanos: 0, - periodType: new perftools.profiles.ValueType({ type: 3, unit: 4 }), + periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, } ); @@ -842,26 +845,26 @@ export const decodedHeapProfileExcludePath = Object.freeze( const mapDir = tmp.dirSync(); export const mapDirPath = mapDir.name; -export const mapFoo = new SourceMapGenerator({ file: 'foo.js' }); +export const mapFoo = new SourceMapGenerator({file: 'foo.js'}); mapFoo.addMapping({ source: path.join(mapDirPath, 'foo.ts'), name: 'foo1', - generated: { line: 1, column: 3 }, - original: { line: 10, column: 0 }, + generated: {line: 1, column: 3}, + original: {line: 10, column: 0}, }); mapFoo.addMapping({ source: path.join(mapDirPath, 'foo.ts'), name: 'foo2', - generated: { line: 5, column: 5 }, - original: { line: 20, column: 0 }, + generated: {line: 5, column: 5}, + original: {line: 20, column: 0}, }); -export const mapBaz = new SourceMapGenerator({ file: 'baz.js' }); +export const mapBaz = new SourceMapGenerator({file: 'baz.js'}); mapBaz.addMapping({ source: path.join(mapDirPath, 'baz.ts'), name: 'baz', - generated: { line: 3, column: 0 }, - original: { line: 5, column: 0 }, + generated: {line: 3, column: 0}, + original: {line: 5, column: 0}, }); fs.writeFileSync(path.join(mapDirPath, 'foo.js.map'), mapFoo.toString()); @@ -873,7 +876,7 @@ const heapGeneratedLeaf1 = { scriptId: 1, lineNumber: 5, columnNumber: 5, - allocations: [{ count: 3, sizeBytes: 2 }], + allocations: [{count: 3, sizeBytes: 2}], children: [], }; @@ -883,7 +886,7 @@ const heapGeneratedLeaf2 = { scriptId: 3, lineNumber: 3, columnNumber: 0, - allocations: [{ count: 5, sizeBytes: 5 }], + allocations: [{count: 5, sizeBytes: 5}], children: [], }; @@ -946,27 +949,27 @@ const heapSourceFunctions = [ const heapSourceLocations = [ new perftools.profiles.Location({ - line: [{ functionId: 1, line: 10 }], + line: [{functionId: 1, line: 10}], id: 1, }), new perftools.profiles.Location({ - line: [{ functionId: 2, line: 20 }], + line: [{functionId: 2, line: 20}], id: 2, }), new perftools.profiles.Location({ - line: [{ functionId: 3, line: 10 }], + line: [{functionId: 3, line: 10}], id: 3, }), new perftools.profiles.Location({ - line: [{ functionId: 4, line: 5 }], + line: [{functionId: 4, line: 5}], id: 4, }), ]; export const heapSourceProfile: perftools.profiles.IProfile = Object.freeze({ sampleType: [ - new perftools.profiles.ValueType({ type: 1, unit: 2 }), - new perftools.profiles.ValueType({ type: 3, unit: 4 }), + new perftools.profiles.ValueType({type: 1, unit: 2}), + new perftools.profiles.ValueType({type: 3, unit: 4}), ], sample: [ new perftools.profiles.Sample({ @@ -997,7 +1000,7 @@ export const heapSourceProfile: perftools.profiles.IProfile = Object.freeze({ path.join(mapDirPath, 'baz.ts'), ], timeNanos: 0, - periodType: new perftools.profiles.ValueType({ type: 3, unit: 4 }), + periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 524288, }); @@ -1085,27 +1088,27 @@ const timeSourceFunctions = [ const timeSourceLocations = [ new perftools.profiles.Location({ - line: [{ functionId: 1, line: 10 }], + line: [{functionId: 1, line: 10}], id: 1, }), new perftools.profiles.Location({ - line: [{ functionId: 2, line: 20 }], + line: [{functionId: 2, line: 20}], id: 2, }), new perftools.profiles.Location({ - line: [{ functionId: 3, line: 10 }], + line: [{functionId: 3, line: 10}], id: 3, }), new perftools.profiles.Location({ - line: [{ functionId: 4, line: 5 }], + line: [{functionId: 4, line: 5}], id: 4, }), ]; export const timeSourceProfile: perftools.profiles.IProfile = Object.freeze({ sampleType: [ - new perftools.profiles.ValueType({ type: 1, unit: 2 }), - new perftools.profiles.ValueType({ type: 3, unit: 4 }), + new perftools.profiles.ValueType({type: 1, unit: 2}), + new perftools.profiles.ValueType({type: 3, unit: 4}), ], sample: [ new perftools.profiles.Sample({ @@ -1137,6 +1140,6 @@ export const timeSourceProfile: perftools.profiles.IProfile = Object.freeze({ ], timeNanos: 0, durationNanos: 10 * 1000 * 1000 * 1000, - periodType: new perftools.profiles.ValueType({ type: 3, unit: 4 }), + periodType: new perftools.profiles.ValueType({type: 3, unit: 4}), period: 1000, }); diff --git a/ts/test/test-heap-profiler.ts b/ts/test/test-heap-profiler.ts index 56f75042..94861909 100644 --- a/ts/test/test-heap-profiler.ts +++ b/ts/test/test-heap-profiler.ts @@ -18,7 +18,7 @@ import * as sinon from 'sinon'; import * as heapProfiler from '../src/heap-profiler'; import * as v8HeapProfiler from '../src/heap-profiler-bindings'; -import { AllocationProfileNode } from '../src/v8-types'; +import {AllocationProfileNode} from '../src/v8-types'; import { heapProfileExcludePath, diff --git a/ts/test/test-profile-encoder.ts b/ts/test/test-profile-encoder.ts index 46063287..d24ddb61 100644 --- a/ts/test/test-profile-encoder.ts +++ b/ts/test/test-profile-encoder.ts @@ -15,12 +15,12 @@ */ import * as pify from 'pify'; -import { gunzip as gunzipPromise, gunzipSync } from 'zlib'; +import {gunzip as gunzipPromise, gunzipSync} from 'zlib'; -import { perftools } from '../../proto/profile'; -import { encode, encodeSync } from '../src/profile-encoder'; +import {perftools} from '../../proto/profile'; +import {encode, encodeSync} from '../src/profile-encoder'; -import { decodedTimeProfile, timeProfile } from './profiles-for-tests'; +import {decodedTimeProfile, timeProfile} from './profiles-for-tests'; const assert = require('assert'); const gunzip = pify(gunzipPromise); diff --git a/ts/test/test-profile-serializer.ts b/ts/test/test-profile-serializer.ts index 24a6c794..6a10e903 100644 --- a/ts/test/test-profile-serializer.ts +++ b/ts/test/test-profile-serializer.ts @@ -20,7 +20,7 @@ import { serializeHeapProfile, serializeTimeProfile, } from '../src/profile-serializer'; -import { SourceMapper } from '../src/sourcemapper/sourcemapper'; +import {SourceMapper} from '../src/sourcemapper/sourcemapper'; import { anonymousFunctionHeapProfile, diff --git a/ts/test/test-time-profiler.ts b/ts/test/test-time-profiler.ts index c00ef8b9..b940080a 100644 --- a/ts/test/test-time-profiler.ts +++ b/ts/test/test-time-profiler.ts @@ -18,7 +18,7 @@ import delay from 'delay'; import * as sinon from 'sinon'; import * as time from '../src/time-profiler'; import * as v8TimeProfiler from '../src/time-profiler-bindings'; -import { timeProfile, v8TimeProfile } from './profiles-for-tests'; +import {timeProfile, v8TimeProfile} from './profiles-for-tests'; const assert = require('assert'); @@ -43,8 +43,8 @@ describe('Time Profiler', () => { }); describe('profile (w/ stubs)', () => { - // tslint:disable-next-line: no-any - const sinonStubs: Array> = new Array(); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const sinonStubs: Array> = []; before(() => { sinonStubs.push(sinon.stub(v8TimeProfiler, 'startProfiling')); sinonStubs.push( @@ -62,7 +62,7 @@ describe('Time Profiler', () => { it('should profile during duration and finish profiling after duration', async () => { let isProfiling = true; - const profilePromise = time.profile(PROFILE_OPTIONS).then(() => { + time.profile(PROFILE_OPTIONS).then(() => { isProfiling = false; }); await delay(2 * PROFILE_OPTIONS.durationMillis); diff --git a/ts/third_party/cloud-debug-nodejs/src/agent/io/scanner.ts b/ts/third_party/cloud-debug-nodejs/src/agent/io/scanner.ts index 8b8ca64b..2c850816 100644 --- a/ts/third_party/cloud-debug-nodejs/src/agent/io/scanner.ts +++ b/ts/third_party/cloud-debug-nodejs/src/agent/io/scanner.ts @@ -123,7 +123,8 @@ function computeStats( fileList: string[], shouldHash: boolean ): Promise { - return new Promise(async (resolve, reject) => { + // eslint-disable-next-line no-async-promise-executor + return new Promise(async resolve => { // return a valid, if fake, result when there are no js files to hash. if (fileList.length === 0) { resolve(new ScanResultsImpl({}, new Map(), 'EMPTY-no-js-files')); @@ -152,10 +153,7 @@ function computeStats( // Sort the hashes to get a deterministic order as the files may // not be in the same order each time we scan the disk. const buffer = hashes.sort().join(); - const sha1 = crypto - .createHash('sha1') - .update(buffer) - .digest('hex'); + const sha1 = crypto.createHash('sha1').update(buffer).digest('hex'); hash = 'SHA1-' + sha1; } resolve(new ScanResultsImpl(statistics, errors, hash)); @@ -250,7 +248,7 @@ function statsForFile( reject(error); } else { const hash = shouldHash ? shasum.digest('hex') : undefined; - resolve({ hash, lines }); + resolve({hash, lines}); } }); });