Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit c85b228

Browse files
authored
refactor: run gts fix (#1150)
1 parent 3947e5b commit c85b228

8 files changed

Lines changed: 60 additions & 53 deletions

File tree

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function initConfig(userConfig: Forceable<Config>): TopLevelConfig {
5353
// 2. Project Config
5454
// 3. Environment Variable Set Configuration File (from GCLOUD_TRACE_CONFIG)
5555
// 4. Default Config (as specified in './config')
56-
const mergedConfig: (typeof defaultConfig) & Forceable<Config> = extend(
56+
const mergedConfig: typeof defaultConfig & Forceable<Config> = extend(
5757
true,
5858
{},
5959
defaultConfig,
@@ -214,7 +214,7 @@ export function start(config?: Config): PluginTypes.Tracer {
214214
}
215215

216216
if (!traceAgent) {
217-
traceAgent = new (require('./trace-api')).StackdriverTracer();
217+
traceAgent = new (require('./trace-api').StackdriverTracer)();
218218
}
219219

220220
try {
@@ -250,7 +250,7 @@ export function start(config?: Config): PluginTypes.Tracer {
250250
*/
251251
export function get(): PluginTypes.Tracer {
252252
if (!traceAgent) {
253-
traceAgent = new (require('./trace-api')).StackdriverTracer();
253+
traceAgent = new (require('./trace-api').StackdriverTracer)();
254254
}
255255
return traceAgent;
256256
}

src/plugins/plugin-grpc.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ type MakeClientConstructorFunction = (
4848
) => typeof Client;
4949
// Meta-type of client-side handlers
5050
type ClientMethod<S, T> = (
51-
| (typeof Client.prototype.makeUnaryRequest)
52-
| (typeof Client.prototype.makeClientStreamRequest)
53-
| (typeof Client.prototype.makeServerStreamRequest)
54-
| (typeof Client.prototype.makeBidiStreamRequest)) &
51+
| typeof Client.prototype.makeUnaryRequest
52+
| typeof Client.prototype.makeClientStreamRequest
53+
| typeof Client.prototype.makeServerStreamRequest
54+
| typeof Client.prototype.makeBidiStreamRequest
55+
) &
5556
(() => EventEmitter) &
5657
MethodDefinition<S, T>;
5758
// Partial module exports of client.js

src/plugins/plugin-pg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type ClientQueryArguments =
2828
| [string]
2929
| [string, {}];
3030
type PG7QueryReturnValue =
31-
| (pg_7.QueryConfig & ({submit: Function} & EventEmitter) | pg_7.Query)
31+
| ((pg_7.QueryConfig & ({submit: Function} & EventEmitter)) | pg_7.Query)
3232
| Promise<pg_7.QueryResult>;
3333
type Callback<T> = (err: Error | null, res?: T) => void;
3434

src/trace-plugin-loader.ts

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ export class ModulePluginWrapper implements PluginWrapper {
158158
const plugin = this.getPluginExportedValue();
159159
// Get a list of supported patches. This is the subset of objects in the
160160
// plugin exported value with matching file/version fields.
161-
const supportedPatches: Array<
162-
Partial<Monkeypatch<T> & Intercept<T>>
163-
> = plugin.filter(
161+
const supportedPatches: Array<Partial<
162+
Monkeypatch<T> & Intercept<T>
163+
>> = plugin.filter(
164164
patch =>
165165
semver.satisfies(version, patch.versions || '*') &&
166166
(file === patch.file || (!file && !patch.file))
@@ -172,43 +172,40 @@ export class ModulePluginWrapper implements PluginWrapper {
172172
}
173173

174174
// Apply each patch object.
175-
return supportedPatches.reduce<T>(
176-
(exportedValue, patch) => {
177-
// TODO(kjin): The only benefit of creating a new StackdriverTracer object
178-
// per patched file is to give us granularity in log messages. See if we
179-
// can refactor the StackdriverTracer class to avoid this.
180-
181-
this.logger.info(
182-
`PluginWrapper#applyPlugin: [${logString}] Applying plugin.`
183-
);
184-
if (patch.patch) {
185-
patch.patch(exportedValue, this.createTraceAgentInstance(logString));
186-
// Queue a function to run if the plugin gets disabled.
187-
if (patch.unpatch) {
188-
const unpatch = patch.unpatch;
189-
this.unpatchFns.push(() => {
190-
this.logger.info(
191-
`PluginWrapper#unapplyAll: [${logString}] Unpatching file.`
192-
);
193-
unpatch(exportedValue);
194-
});
195-
}
196-
// The patch object should only have either patch() or intercept().
197-
if (patch.intercept) {
198-
this.logger.warn(
199-
`PluginWrapper#applyPlugin: [${logString}] Patch object has both patch() and intercept() for this file. Only applying patch().`
175+
return supportedPatches.reduce<T>((exportedValue, patch) => {
176+
// TODO(kjin): The only benefit of creating a new StackdriverTracer object
177+
// per patched file is to give us granularity in log messages. See if we
178+
// can refactor the StackdriverTracer class to avoid this.
179+
180+
this.logger.info(
181+
`PluginWrapper#applyPlugin: [${logString}] Applying plugin.`
182+
);
183+
if (patch.patch) {
184+
patch.patch(exportedValue, this.createTraceAgentInstance(logString));
185+
// Queue a function to run if the plugin gets disabled.
186+
if (patch.unpatch) {
187+
const unpatch = patch.unpatch;
188+
this.unpatchFns.push(() => {
189+
this.logger.info(
190+
`PluginWrapper#unapplyAll: [${logString}] Unpatching file.`
200191
);
201-
}
202-
} else if (patch.intercept) {
203-
exportedValue = patch.intercept(
204-
exportedValue,
205-
this.createTraceAgentInstance(file)
192+
unpatch(exportedValue);
193+
});
194+
}
195+
// The patch object should only have either patch() or intercept().
196+
if (patch.intercept) {
197+
this.logger.warn(
198+
`PluginWrapper#applyPlugin: [${logString}] Patch object has both patch() and intercept() for this file. Only applying patch().`
206199
);
207200
}
208-
return exportedValue;
209-
},
210-
moduleExports as T
211-
);
201+
} else if (patch.intercept) {
202+
exportedValue = patch.intercept(
203+
exportedValue,
204+
this.createTraceAgentInstance(file)
205+
);
206+
}
207+
return exportedValue;
208+
}, moduleExports as T);
212209
}
213210

214211
// Helper function to get the cached plugin value if it wasn't loaded yet.

test/plugins/test-cls-bluebird.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,12 @@ describe('Patch plugin for bluebird', () => {
164164
// tslint:disable-next-line:no-any
165165
testCases.forEach((testCase: TestCase<any>) => {
166166
it(`enables context propagation in the same way as native promises for test case: ${testCase.description}`, async () => {
167-
const actual = (await getTracesForPromiseImplementation(
168-
testCase.makePromise,
169-
testCase.thenFn
170-
))
167+
const actual = (
168+
await getTracesForPromiseImplementation(
169+
testCase.makePromise,
170+
testCase.thenFn
171+
)
172+
)
171173
.map(trace => trace.spans.length)
172174
.join(', ');
173175
// In each case, the second trace should have the child span.

test/plugins/test-trace-http2.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ maybeSkipHttp2('Trace Agent integration with http2', () => {
260260
server.on(
261261
'stream',
262262
(
263-
s: http2Types.ServerHttp2Stream & ({rstWithInternalError: () => void})
263+
s: http2Types.ServerHttp2Stream & {rstWithInternalError: () => void}
264264
) => {
265265
// In Node 9.9+, the error handler is not added by default.
266266
s.on('error', () => {});
@@ -383,7 +383,10 @@ maybeSkipHttp2('Trace Agent integration with http2', () => {
383383
assert.strictEqual(statusCodes.indexOf(code), -1);
384384
statusCodes.push(code);
385385
}
386-
assert.strictEqual(statusCodes.reduce((a, b) => a + b), 1010);
386+
assert.strictEqual(
387+
statusCodes.reduce((a, b) => a + b),
388+
1010
389+
);
387390
slowServer.close();
388391
done();
389392
}

test/test-cls.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ describe('Continuation-Local Storage', () => {
274274
c.disable();
275275
assert.ok(!c.isEnabled());
276276
assert.ok(c.getContext().type, SpanType.UNSAMPLED);
277-
assert.ok(c.runWithContext(() => 'hi', TraceCLS.UNCORRELATED), 'hi');
277+
assert.ok(
278+
c.runWithContext(() => 'hi', TraceCLS.UNCORRELATED),
279+
'hi'
280+
);
278281
const fn = () => {};
279282
assert.strictEqual(c.bindWithCurrentContext(fn), fn);
280283
c.patchEmitterToPropagateContext(new EventEmitter());

test/web-frameworks/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export type WebFrameworkAddHandlerOptions = {
4747
fn: (
4848
incomingHeaders: IncomingHttpHeaders
4949
) => Promise<WebFrameworkResponse>;
50-
});
50+
}
51+
);
5152

5253
/**
5354
* A type that describes a ramework-agnostic request handler function.

0 commit comments

Comments
 (0)