Skip to content

Commit

Permalink
Merge pull request #2465 from dancrumb/chore/#2464
Browse files Browse the repository at this point in the history
Convert to eslint/prettier
  • Loading branch information
murgatroid99 committed Jun 15, 2023
2 parents 2a11a2c + cd24d69 commit dbaaa89
Show file tree
Hide file tree
Showing 71 changed files with 4,278 additions and 3,257 deletions.
58 changes: 54 additions & 4 deletions packages/grpc-js/.eslintrc
@@ -1,11 +1,61 @@
{
"root": true,
"extends": "./node_modules/gts",

"extends": [
"eslint:recommended",
"plugin:node/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"plugins": ["node", "prettier", "@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"ignorePatterns": ["**/generated/**", "**/node_modules/**", "**/build/**"],
"rules": {
"node/no-unpublished-import": ["error", {
"node/no-unpublished-import": [
"error",
{
"tryExtensions": [".ts", ".js", ".json", ".node"]
}],
}
],
"@typescript-eslint/no-unused-vars": "off",
"node/no-unpublished-require": "off"
"node/no-unpublished-require": "off",
"prettier/prettier": "error",
"block-scoped-var": "error",
"eqeqeq": "error",
"no-var": "error",
"prefer-const": "error",
"no-case-declarations": "warn",
"no-restricted-properties": [
"error",
{
"object": "describe",
"property": "only"
},
{
"object": "it",
"property": "only"
}
],

"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-warning-comments": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/camelcase": "off",
"node/no-missing-import": "off",
"node/no-empty-function": "off",
"node/no-unsupported-features/es-syntax": "off",
"node/no-missing-require": "off",
"node/shebang": "off",
"no-dupe-class-members": "off",
"require-atomic-updates": "off"
}
}
4 changes: 4 additions & 0 deletions packages/grpc-js/apache-notice.md
@@ -0,0 +1,4 @@
The following files contain configuration settings that were derived from [the this commit](https://github.com/google/gts/commit/3b9ab6dd59691f77f5c5c632a44c6762ba4ef7c6) in the Google GTS repository:
- .eslintrc
- prettier.config.js
- tsconfig.json
971 changes: 0 additions & 971 deletions packages/grpc-js/log.txt

This file was deleted.

19 changes: 13 additions & 6 deletions packages/grpc-js/package.json
Expand Up @@ -22,20 +22,27 @@
"@types/ncp": "^2.0.1",
"@types/pify": "^3.0.2",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"@typescript-eslint/typescript-estree": "^5.59.11",
"clang-format": "^1.0.55",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"execa": "^2.0.3",
"gts": "^3.1.1",
"gulp": "^4.0.2",
"gulp-mocha": "^6.0.0",
"lodash": "^4.17.4",
"madge": "^5.0.1",
"mocha-jenkins-reporter": "^0.4.1",
"ncp": "^2.0.0",
"pify": "^4.0.1",
"prettier": "^2.8.8",
"rimraf": "^3.0.2",
"semver": "^7.3.5",
"ts-node": "^8.3.0",
"typescript": "^4.8.4"
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
},
"contributors": [
{
Expand All @@ -47,11 +54,11 @@
"clean": "rimraf ./build",
"compile": "tsc -p .",
"format": "clang-format -i -style=\"{Language: JavaScript, BasedOnStyle: Google, ColumnLimit: 80}\" src/*.ts test/*.ts",
"lint": "npm run check",
"lint": "eslint src/*.ts test/*.ts",
"prepare": "npm run generate-types && npm run compile",
"test": "gulp test",
"check": "gts check src/**/*.ts",
"fix": "gts fix src/*.ts",
"check": "npm run lint",
"fix": "eslint --fix src/*.ts test/*.ts",
"pretest": "npm run generate-types && npm run generate-test-types && npm run compile",
"posttest": "npm run check && madge -c ./build/src",
"generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ --include-dirs test/fixtures/ -O src/generated/ --grpcLib ../index channelz.proto",
Expand Down
2 changes: 2 additions & 0 deletions packages/grpc-js/prettier.config.js
Expand Up @@ -2,4 +2,6 @@ module.exports = {
proseWrap: 'always',
singleQuote: true,
trailingComma: 'es5',
bracketSpacing: true,
arrowParens: 'avoid',
};
20 changes: 13 additions & 7 deletions packages/grpc-js/src/admin.ts
Expand Up @@ -15,8 +15,8 @@
*
*/

import { ServiceDefinition } from "./make-client";
import { Server, UntypedServiceImplementation } from "./server";
import { ServiceDefinition } from './make-client';
import { Server, UntypedServiceImplementation } from './server';

interface GetServiceDefinition {
(): ServiceDefinition;
Expand All @@ -26,14 +26,20 @@ interface GetHandlers {
(): UntypedServiceImplementation;
}

const registeredAdminServices: {getServiceDefinition: GetServiceDefinition, getHandlers: GetHandlers}[] = [];
const registeredAdminServices: {
getServiceDefinition: GetServiceDefinition;
getHandlers: GetHandlers;
}[] = [];

export function registerAdminService(getServiceDefinition: GetServiceDefinition, getHandlers: GetHandlers) {
registeredAdminServices.push({getServiceDefinition, getHandlers});
export function registerAdminService(
getServiceDefinition: GetServiceDefinition,
getHandlers: GetHandlers
) {
registeredAdminServices.push({ getServiceDefinition, getHandlers });
}

export function addAdminServicesToServer(server: Server): void {
for (const {getServiceDefinition, getHandlers} of registeredAdminServices) {
for (const { getServiceDefinition, getHandlers } of registeredAdminServices) {
server.addService(getServiceDefinition(), getHandlers());
}
}
}
6 changes: 3 additions & 3 deletions packages/grpc-js/src/call-credentials.ts
Expand Up @@ -125,14 +125,14 @@ export abstract class CallCredentials {
});
}
getHeaders.then(
(headers) => {
headers => {
const metadata = new Metadata();
for (const key of Object.keys(headers)) {
metadata.add(key, headers[key]);
}
callback(null, metadata);
},
(err) => {
err => {
callback(err);
}
);
Expand All @@ -152,7 +152,7 @@ class ComposedCallCredentials extends CallCredentials {
async generateMetadata(options: CallMetadataOptions): Promise<Metadata> {
const base: Metadata = new Metadata();
const generated: Metadata[] = await Promise.all(
this.creds.map((cred) => cred.generateMetadata(options))
this.creds.map(cred => cred.generateMetadata(options))
);
for (const gen of generated) {
base.merge(gen);
Expand Down
22 changes: 11 additions & 11 deletions packages/grpc-js/src/call-interface.ts
Expand Up @@ -15,11 +15,11 @@
*
*/

import { CallCredentials } from "./call-credentials";
import { Status } from "./constants";
import { Deadline } from "./deadline";
import { Metadata } from "./metadata";
import { ServerSurfaceCall } from "./server-call";
import { CallCredentials } from './call-credentials';
import { Status } from './constants';
import { Deadline } from './deadline';
import { Metadata } from './metadata';
import { ServerSurfaceCall } from './server-call';

export interface CallStreamOptions {
deadline: Deadline;
Expand All @@ -38,7 +38,7 @@ export interface StatusObject {

export type PartialStatusObject = Pick<StatusObject, 'code' | 'details'> & {
metadata: Metadata | null;
}
};

export const enum WriteFlags {
BufferHint = 1,
Expand Down Expand Up @@ -118,7 +118,7 @@ export class InterceptingListenerImpl implements InterceptingListener {

onReceiveMetadata(metadata: Metadata): void {
this.processingMetadata = true;
this.listener.onReceiveMetadata(metadata, (metadata) => {
this.listener.onReceiveMetadata(metadata, metadata => {
this.processingMetadata = false;
this.nextListener.onReceiveMetadata(metadata);
this.processPendingMessage();
Expand All @@ -128,9 +128,9 @@ export class InterceptingListenerImpl implements InterceptingListener {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onReceiveMessage(message: any): void {
/* If this listener processes messages asynchronously, the last message may
* be reordered with respect to the status */
* be reordered with respect to the status */
this.processingMessage = true;
this.listener.onReceiveMessage(message, (msg) => {
this.listener.onReceiveMessage(message, msg => {
this.processingMessage = false;
if (this.processingMetadata) {
this.pendingMessage = msg;
Expand All @@ -142,7 +142,7 @@ export class InterceptingListenerImpl implements InterceptingListener {
});
}
onReceiveStatus(status: StatusObject): void {
this.listener.onReceiveStatus(status, (processedStatus) => {
this.listener.onReceiveStatus(status, processedStatus => {
if (this.processingMetadata || this.processingMessage) {
this.pendingStatus = processedStatus;
} else {
Expand Down Expand Up @@ -170,4 +170,4 @@ export interface Call {
halfClose(): void;
getCallNumber(): number;
setCredentials(credentials: CallCredentials): void;
}
}
4 changes: 2 additions & 2 deletions packages/grpc-js/src/call-number.ts
Expand Up @@ -18,5 +18,5 @@
let nextCallNumber = 0;

export function getNextCallNumber() {
return nextCallNumber++;
}
return nextCallNumber++;
}
25 changes: 15 additions & 10 deletions packages/grpc-js/src/call.ts
Expand Up @@ -65,27 +65,29 @@ export type ClientWritableStream<RequestType> = {
/**
* A type representing the return value of a bidirectional stream method call.
*/
export type ClientDuplexStream<
RequestType,
ResponseType
> = ClientWritableStream<RequestType> & ClientReadableStream<ResponseType>;
export type ClientDuplexStream<RequestType, ResponseType> =
ClientWritableStream<RequestType> & ClientReadableStream<ResponseType>;

/**
* Construct a ServiceError from a StatusObject. This function exists primarily
* as an attempt to make the error stack trace clearly communicate that the
* error is not necessarily a problem in gRPC itself.
* @param status
*/
export function callErrorFromStatus(status: StatusObject, callerStack: string): ServiceError {
export function callErrorFromStatus(
status: StatusObject,
callerStack: string
): ServiceError {
const message = `${status.code} ${Status[status.code]}: ${status.details}`;
const error = new Error(message);
const stack = `${error.stack}\nfor call at\n${callerStack}`;
return Object.assign(new Error(message), status, {stack});
return Object.assign(new Error(message), status, { stack });
}

export class ClientUnaryCallImpl
extends EventEmitter
implements ClientUnaryCall {
implements ClientUnaryCall
{
public call?: InterceptingCallInterface;
constructor() {
super();
Expand All @@ -102,7 +104,8 @@ export class ClientUnaryCallImpl

export class ClientReadableStreamImpl<ResponseType>
extends Readable
implements ClientReadableStream<ResponseType> {
implements ClientReadableStream<ResponseType>
{
public call?: InterceptingCallInterface;
constructor(readonly deserialize: (chunk: Buffer) => ResponseType) {
super({ objectMode: true });
Expand All @@ -123,7 +126,8 @@ export class ClientReadableStreamImpl<ResponseType>

export class ClientWritableStreamImpl<RequestType>
extends Writable
implements ClientWritableStream<RequestType> {
implements ClientWritableStream<RequestType>
{
public call?: InterceptingCallInterface;
constructor(readonly serialize: (value: RequestType) => Buffer) {
super({ objectMode: true });
Expand Down Expand Up @@ -156,7 +160,8 @@ export class ClientWritableStreamImpl<RequestType>

export class ClientDuplexStreamImpl<RequestType, ResponseType>
extends Duplex
implements ClientDuplexStream<RequestType, ResponseType> {
implements ClientDuplexStream<RequestType, ResponseType>
{
public call?: InterceptingCallInterface;
constructor(
readonly serialize: (value: RequestType) => Buffer,
Expand Down

0 comments on commit dbaaa89

Please sign in to comment.