Skip to content

Commit

Permalink
refactor: use the shared prettier config (#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and kjin committed Jun 26, 2019
1 parent 0d954a1 commit e3f763c
Show file tree
Hide file tree
Showing 68 changed files with 552 additions and 560 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/*
samples/node_modules/*
src/**/doc/*
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
bracketSpacing: false
printWidth: 80
semi: true
singleQuote: true
tabWidth: 2
trailingComma: es5
useTabs: false
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"get-plugin-types": "npm run script get-plugin-types",
"coverage": "npm run script run-unit-tests-with-coverage report-coverage",
"check": "gts check",
"lint": "gts check",
"clean": "rimraf build/src",
"compile-all": "npm run script compile-auto",
"compile-strict": "npm run script compile-auto-strict",
Expand Down
24 changes: 12 additions & 12 deletions src/cls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
* limitations under the License.
*/

import { EventEmitter } from 'events';
import {EventEmitter} from 'events';
import * as semver from 'semver';

import { AsyncHooksCLS } from './cls/async-hooks';
import { AsyncListenerCLS } from './cls/async-listener';
import { CLS, Func } from './cls/base';
import { NullCLS } from './cls/null';
import { SingularCLS } from './cls/singular';
import { SpanType } from './constants';
import { Logger } from './logger';
import { RootSpan } from './plugin-types';
import { UNCORRELATED_ROOT_SPAN, DISABLED_ROOT_SPAN } from './span-data';
import { Trace, TraceSpan } from './trace';
import { Singleton } from './util';
import {AsyncHooksCLS} from './cls/async-hooks';
import {AsyncListenerCLS} from './cls/async-listener';
import {CLS, Func} from './cls/base';
import {NullCLS} from './cls/null';
import {SingularCLS} from './cls/singular';
import {SpanType} from './constants';
import {Logger} from './logger';
import {RootSpan} from './plugin-types';
import {UNCORRELATED_ROOT_SPAN, DISABLED_ROOT_SPAN} from './span-data';
import {Trace, TraceSpan} from './trace';
import {Singleton} from './util';

const asyncHooksAvailable = semver.satisfies(process.version, '>=8');

Expand Down
8 changes: 4 additions & 4 deletions src/cls/async-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
// This file calls require('async_hooks') in the AsyncHooksCLS constructor,
// rather than upon module load.
import * as asyncHooksModule from 'async_hooks';
import { EventEmitter } from 'events';
import {EventEmitter} from 'events';
import * as shimmer from 'shimmer';

import { CLS, Func } from './base';
import {CLS, Func} from './base';

type AsyncHooksModule = typeof asyncHooksModule;

Expand All @@ -35,7 +35,7 @@ const EVENT_EMITTER_METHODS: Array<keyof EventEmitter> = [
// A symbol used to check if a method has been wrapped for context.
const WRAPPED = Symbol('@google-cloud/trace-agent:AsyncHooksCLS:WRAPPED');

type ContextWrapped<T> = T & { [WRAPPED]?: boolean };
type ContextWrapped<T> = T & {[WRAPPED]?: boolean};

/**
* An implementation of continuation-local storage on top of the async_hooks
Expand All @@ -46,7 +46,7 @@ export class AsyncHooksCLS<Context extends {}> implements CLS<Context> {
private ah: AsyncHooksModule;

/** A map of AsyncResource IDs to Context objects. */
private contexts: { [id: number]: Context } = {};
private contexts: {[id: number]: Context} = {};
/** The AsyncHook that proactively populates entries in this.contexts. */
private hook: asyncHooksModule.AsyncHook;
/** Whether this instance is enabled. */
Expand Down
4 changes: 2 additions & 2 deletions src/cls/async-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
// This module requires continuation-local-storage in the AsyncListenerCLS
// constructor, rather than upon module load.
import * as clsModule from 'continuation-local-storage';
import { EventEmitter } from 'events';
import {EventEmitter} from 'events';

import { CLS, Func } from './base';
import {CLS, Func} from './base';

type CLSModule = typeof clsModule;

Expand Down
2 changes: 1 addition & 1 deletion src/cls/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { EventEmitter } from 'events';
import {EventEmitter} from 'events';

// tslint:disable-next-line:no-any
export type Func<T = void> = (...args: any[]) => T;
Expand Down
4 changes: 2 additions & 2 deletions src/cls/null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import { EventEmitter } from 'events';
import {EventEmitter} from 'events';

import { CLS, Func } from './base';
import {CLS, Func} from './base';

/**
* A trivial implementation of continuation-local storage where context takes on
Expand Down
4 changes: 2 additions & 2 deletions src/cls/singular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import { EventEmitter } from 'events';
import {EventEmitter} from 'events';

import { CLS, Func } from './base';
import {CLS, Func} from './base';

/**
* A trivial implementation of continuation-local storage where everything is
Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface RequestDetails {
/**
* The parsed trace context, if it exists.
*/
traceContext: { traceId: string; spanId: string; options: number } | null;
traceContext: {traceId: string; spanId: string; options: number} | null;
/**
* The original options object used to create the root span that corresponds
* to this request.
Expand Down Expand Up @@ -166,7 +166,7 @@ export interface Config {
* value. Disabling any of the default plugins may cause unwanted behavior,
* so use caution.
*/
plugins?: { [pluginName: string]: string };
plugins?: {[pluginName: string]: string};

/**
* The max number of frames to include on traces; pass a value of 0 to
Expand Down Expand Up @@ -281,7 +281,7 @@ export interface Config {
* The contents of a key file. If this field is set, its contents will be
* used for authentication instead of your application default credentials.
*/
credentials?: { client_email?: string; private_key?: string };
credentials?: {client_email?: string; private_key?: string};

/**
* A path to a key file relative to the current working directory. If this
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ const filesLoadedBeforeTrace = Object.keys(require.cache);
// This file's top-level imports must not transitively depend on modules that
// do I/O, or continuation-local-storage will not work.
import * as semver from 'semver';
import { Config, defaultConfig, TracePolicy } from './config';
import {Config, defaultConfig, TracePolicy} from './config';
import * as extend from 'extend';
import * as path from 'path';
import * as PluginTypes from './plugin-types';
import { Tracing, TopLevelConfig } from './tracing';
import { FORCE_NEW, Forceable, lastOf } from './util';
import { Constants } from './constants';
import { TraceCLSMechanism } from './cls';
import { StackdriverTracer } from './trace-api';
import { TraceContextHeaderBehavior } from './tracing-policy';
import {Tracing, TopLevelConfig} from './tracing';
import {FORCE_NEW, Forceable, lastOf} from './util';
import {Constants} from './constants';
import {TraceCLSMechanism} from './cls';
import {StackdriverTracer} from './trace-api';
import {TraceContextHeaderBehavior} from './tracing-policy';

export { Config, PluginTypes };
export {Config, PluginTypes};

let traceAgent: StackdriverTracer;

Expand Down Expand Up @@ -164,7 +164,7 @@ function initConfig(userConfig: Forceable<Config>): TopLevelConfig {
},
pluginLoaderConfig: {
[FORCE_NEW]: forceNew,
plugins: { ...mergedConfig.plugins },
plugins: {...mergedConfig.plugins},
tracerConfig: {
enhancedDatabaseReporting: mergedConfig.enhancedDatabaseReporting,
rootSpanNameOverride: getInternalRootSpanNameOverride(
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as consoleLogLevel from 'console-log-level';
import { defaultConfig } from './config';
import {defaultConfig} from './config';

export type ConsoleLogLevel = 'error' | 'warn' | 'info' | 'debug';
export type LogLevel = 'silent' | ConsoleLogLevel;
Expand Down
12 changes: 6 additions & 6 deletions src/plugin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
// This file only describes public-facing interfaces.
// tslint:disable:no-any

import { EventEmitter } from 'events';
import {EventEmitter} from 'events';

import { Constants, SpanType } from './constants';
import { StackdriverTracerConfig } from './trace-api';
import { TraceLabels } from './trace-labels';
import { TraceContext } from './util';
import {Constants, SpanType} from './constants';
import {StackdriverTracerConfig} from './trace-api';
import {TraceLabels} from './trace-labels';
import {TraceContext} from './util';

export { TraceContext };
export {TraceContext};

export type Func<T> = (...args: any[]) => T;

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/plugin-bluebird.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

import * as shimmer from 'shimmer';

import { PluginTypes } from '..';
import {PluginTypes} from '..';

import { bluebird_3 } from './types';
import {bluebird_3} from './types';

type BluebirdModule = typeof bluebird_3 & { prototype: { _then: Function } };
type BluebirdModule = typeof bluebird_3 & {prototype: {_then: Function}};

const plugin: PluginTypes.Plugin = [
{
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/plugin-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
* limitations under the License.
*/

import { IncomingMessage, ServerResponse } from 'http';
import { parse as urlParse } from 'url';
import {IncomingMessage, ServerResponse} from 'http';
import {parse as urlParse} from 'url';

import { PluginTypes } from '..';
import {PluginTypes} from '..';

import { connect_3 } from './types';
import {connect_3} from './types';

type Connect3 = typeof connect_3;
// Connect docs note that routed requests have an originalUrl property.
// https://github.com/senchalabs/connect/tree/3.6.5#appuseroute-fn
type Request = IncomingMessage & { originalUrl?: string };
type Request = IncomingMessage & {originalUrl?: string};

const SUPPORTED_VERSIONS = '3.x';

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/plugin-express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import * as httpMethods from 'methods';
import * as shimmer from 'shimmer';

import { PluginTypes } from '..';
import {PluginTypes} from '..';

import { express_4 } from './types';
import {express_4} from './types';

// application is an undocumented member of the express object.
type Express4Module = typeof express_4 & { application: express_4.Application };
type Express4Module = typeof express_4 & {application: express_4.Application};

const methods: Array<keyof express_4.Application> = (httpMethods as Array<
keyof express_4.Application
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/plugin-grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { EventEmitter } from 'events';
import {EventEmitter} from 'events';
import * as grpcModule from 'grpc'; // for types only.
import {
Client,
Expand Down Expand Up @@ -42,7 +42,7 @@ type Metadata = grpcModule.Metadata & {
type MetadataModule = typeof grpcModule.Metadata;
// Type of makeClientConstructor as exported from client.js
type MakeClientConstructorFunction = (
methods: { [key: string]: { originalName?: string } },
methods: {[key: string]: {originalName?: string}},
serviceName: string,
classOptions: never
) => typeof Client;
Expand Down Expand Up @@ -197,7 +197,7 @@ function patchClient(client: ClientModule, api: Tracer) {
// ReturnType<ClientMethod<S, T>>
function clientMethodTrace(this: Client): EventEmitter {
// The span name will be of form "grpc:/[Service]/[MethodName]".
const span = api.createChildSpan({ name: 'grpc:' + method.path });
const span = api.createChildSpan({name: 'grpc:' + method.path});
if (!api.isRealSpan(span)) {
// Span couldn't be created, either by policy or because a root span
// doesn't exist.
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/plugin-hapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import { IncomingMessage, ServerResponse } from 'http';
import {IncomingMessage, ServerResponse} from 'http';
import * as shimmer from 'shimmer';
import { parse as urlParse } from 'url';
import {parse as urlParse} from 'url';

import { PluginTypes } from '..';
import {PluginTypes} from '..';

import { hapi_16, hapi_17 } from './types';
import {hapi_16, hapi_17} from './types';

// Used when patching Hapi 17.
const ORIGINAL = Symbol();
Expand Down Expand Up @@ -147,7 +147,7 @@ const plugin: PluginTypes.Plugin = [
return origExecute.apply(this, arguments);
});
},
{ [ORIGINAL]: origExecute }
{[ORIGINAL]: origExecute}
);
},
// Request is a class name.
Expand All @@ -157,6 +157,6 @@ const plugin: PluginTypes.Plugin = [
Request.prototype._execute = Request.prototype._execute[ORIGINAL]!;
}
},
} as PluginTypes.Monkeypatch<{ prototype: Hapi17Request }>,
} as PluginTypes.Monkeypatch<{prototype: Hapi17Request}>,
];
export = plugin;
8 changes: 4 additions & 4 deletions src/plugins/plugin-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/

import * as httpModule from 'http';
import { Agent, ClientRequest, ClientRequestArgs, get, request } from 'http';
import {Agent, ClientRequest, ClientRequestArgs, get, request} from 'http';
import * as httpsModule from 'https';
import * as is from 'is';
import * as semver from 'semver';
import * as shimmer from 'shimmer';
import * as url from 'url';

import { Plugin, Tracer } from '../plugin-types';
import {Plugin, Tracer} from '../plugin-types';

type HttpModule = typeof httpModule;
type HttpsModule = typeof httpsModule;
Expand Down Expand Up @@ -69,7 +69,7 @@ function extractUrl(
// pathname only exists on a URL object.
path = options.pathname || '/';
} else {
const agent = options._defaultAgent as Agent & { protocol?: string };
const agent = options._defaultAgent as Agent & {protocol?: string};
if (agent) {
fallbackProtocol = agent.protocol || fallbackProtocol;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ function makeRequestTrace(
options = url.parse(options);
}

const span = api.createChildSpan({ name: getSpanName(options) });
const span = api.createChildSpan({name: getSpanName(options)});
if (!api.isRealSpan(span)) {
return request(options, callback);
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/plugin-http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import { EventEmitter } from 'events';
import {EventEmitter} from 'events';
// This is imported only for types. Generated .js file should NOT load 'http2'.
// `http2` must be used only in type annotations, not in expressions.
import * as http2 from 'http2';
import * as shimmer from 'shimmer';
import { URL } from 'url';
import {URL} from 'url';

import { Tracer } from '../plugin-types';
import {Tracer} from '../plugin-types';

type Http2Module = typeof http2;

Expand Down
Loading

0 comments on commit e3f763c

Please sign in to comment.