Skip to content

Commit dbaaa89

Browse files
authored
Merge pull request #2465 from dancrumb/chore/#2464
Convert to eslint/prettier
2 parents 2a11a2c + cd24d69 commit dbaaa89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4278
-3257
lines changed

packages/grpc-js/.eslintrc

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,61 @@
11
{
22
"root": true,
3-
"extends": "./node_modules/gts",
3+
4+
"extends": [
5+
"eslint:recommended",
6+
"plugin:node/recommended",
7+
"plugin:@typescript-eslint/recommended",
8+
"plugin:prettier/recommended"
9+
],
10+
"plugins": ["node", "prettier", "@typescript-eslint"],
11+
"parser": "@typescript-eslint/parser",
12+
"parserOptions": {
13+
"ecmaVersion": 2018,
14+
"sourceType": "module"
15+
},
16+
"ignorePatterns": ["**/generated/**", "**/node_modules/**", "**/build/**"],
417
"rules": {
5-
"node/no-unpublished-import": ["error", {
18+
"node/no-unpublished-import": [
19+
"error",
20+
{
621
"tryExtensions": [".ts", ".js", ".json", ".node"]
7-
}],
22+
}
23+
],
824
"@typescript-eslint/no-unused-vars": "off",
9-
"node/no-unpublished-require": "off"
25+
"node/no-unpublished-require": "off",
26+
"prettier/prettier": "error",
27+
"block-scoped-var": "error",
28+
"eqeqeq": "error",
29+
"no-var": "error",
30+
"prefer-const": "error",
31+
"no-case-declarations": "warn",
32+
"no-restricted-properties": [
33+
"error",
34+
{
35+
"object": "describe",
36+
"property": "only"
37+
},
38+
{
39+
"object": "it",
40+
"property": "only"
41+
}
42+
],
43+
44+
"@typescript-eslint/no-non-null-assertion": "off",
45+
"@typescript-eslint/no-use-before-define": "off",
46+
"@typescript-eslint/no-warning-comments": "off",
47+
"@typescript-eslint/no-empty-function": "off",
48+
"@typescript-eslint/no-var-requires": "off",
49+
"@typescript-eslint/explicit-function-return-type": "off",
50+
"@typescript-eslint/explicit-module-boundary-types": "off",
51+
"@typescript-eslint/ban-types": "off",
52+
"@typescript-eslint/camelcase": "off",
53+
"node/no-missing-import": "off",
54+
"node/no-empty-function": "off",
55+
"node/no-unsupported-features/es-syntax": "off",
56+
"node/no-missing-require": "off",
57+
"node/shebang": "off",
58+
"no-dupe-class-members": "off",
59+
"require-atomic-updates": "off"
1060
}
1161
}

packages/grpc-js/apache-notice.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
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:
2+
- .eslintrc
3+
- prettier.config.js
4+
- tsconfig.json

packages/grpc-js/log.txt

Lines changed: 0 additions & 971 deletions
This file was deleted.

packages/grpc-js/package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,27 @@
2222
"@types/ncp": "^2.0.1",
2323
"@types/pify": "^3.0.2",
2424
"@types/semver": "^7.3.9",
25+
"@typescript-eslint/eslint-plugin": "^5.59.11",
26+
"@typescript-eslint/parser": "^5.59.11",
27+
"@typescript-eslint/typescript-estree": "^5.59.11",
2528
"clang-format": "^1.0.55",
29+
"eslint": "^8.42.0",
30+
"eslint-config-prettier": "^8.8.0",
31+
"eslint-plugin-node": "^11.1.0",
32+
"eslint-plugin-prettier": "^4.2.1",
2633
"execa": "^2.0.3",
27-
"gts": "^3.1.1",
2834
"gulp": "^4.0.2",
2935
"gulp-mocha": "^6.0.0",
3036
"lodash": "^4.17.4",
3137
"madge": "^5.0.1",
3238
"mocha-jenkins-reporter": "^0.4.1",
3339
"ncp": "^2.0.0",
3440
"pify": "^4.0.1",
41+
"prettier": "^2.8.8",
3542
"rimraf": "^3.0.2",
3643
"semver": "^7.3.5",
37-
"ts-node": "^8.3.0",
38-
"typescript": "^4.8.4"
44+
"ts-node": "^10.9.1",
45+
"typescript": "^5.1.3"
3946
},
4047
"contributors": [
4148
{
@@ -47,11 +54,11 @@
4754
"clean": "rimraf ./build",
4855
"compile": "tsc -p .",
4956
"format": "clang-format -i -style=\"{Language: JavaScript, BasedOnStyle: Google, ColumnLimit: 80}\" src/*.ts test/*.ts",
50-
"lint": "npm run check",
57+
"lint": "eslint src/*.ts test/*.ts",
5158
"prepare": "npm run generate-types && npm run compile",
5259
"test": "gulp test",
53-
"check": "gts check src/**/*.ts",
54-
"fix": "gts fix src/*.ts",
60+
"check": "npm run lint",
61+
"fix": "eslint --fix src/*.ts test/*.ts",
5562
"pretest": "npm run generate-types && npm run generate-test-types && npm run compile",
5663
"posttest": "npm run check && madge -c ./build/src",
5764
"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",

packages/grpc-js/prettier.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ module.exports = {
22
proseWrap: 'always',
33
singleQuote: true,
44
trailingComma: 'es5',
5+
bracketSpacing: true,
6+
arrowParens: 'avoid',
57
};

packages/grpc-js/src/admin.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*
1616
*/
1717

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

2121
interface GetServiceDefinition {
2222
(): ServiceDefinition;
@@ -26,14 +26,20 @@ interface GetHandlers {
2626
(): UntypedServiceImplementation;
2727
}
2828

29-
const registeredAdminServices: {getServiceDefinition: GetServiceDefinition, getHandlers: GetHandlers}[] = [];
29+
const registeredAdminServices: {
30+
getServiceDefinition: GetServiceDefinition;
31+
getHandlers: GetHandlers;
32+
}[] = [];
3033

31-
export function registerAdminService(getServiceDefinition: GetServiceDefinition, getHandlers: GetHandlers) {
32-
registeredAdminServices.push({getServiceDefinition, getHandlers});
34+
export function registerAdminService(
35+
getServiceDefinition: GetServiceDefinition,
36+
getHandlers: GetHandlers
37+
) {
38+
registeredAdminServices.push({ getServiceDefinition, getHandlers });
3339
}
3440

3541
export function addAdminServicesToServer(server: Server): void {
36-
for (const {getServiceDefinition, getHandlers} of registeredAdminServices) {
42+
for (const { getServiceDefinition, getHandlers } of registeredAdminServices) {
3743
server.addService(getServiceDefinition(), getHandlers());
3844
}
39-
}
45+
}

packages/grpc-js/src/call-credentials.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ export abstract class CallCredentials {
125125
});
126126
}
127127
getHeaders.then(
128-
(headers) => {
128+
headers => {
129129
const metadata = new Metadata();
130130
for (const key of Object.keys(headers)) {
131131
metadata.add(key, headers[key]);
132132
}
133133
callback(null, metadata);
134134
},
135-
(err) => {
135+
err => {
136136
callback(err);
137137
}
138138
);
@@ -152,7 +152,7 @@ class ComposedCallCredentials extends CallCredentials {
152152
async generateMetadata(options: CallMetadataOptions): Promise<Metadata> {
153153
const base: Metadata = new Metadata();
154154
const generated: Metadata[] = await Promise.all(
155-
this.creds.map((cred) => cred.generateMetadata(options))
155+
this.creds.map(cred => cred.generateMetadata(options))
156156
);
157157
for (const gen of generated) {
158158
base.merge(gen);

packages/grpc-js/src/call-interface.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*
1616
*/
1717

18-
import { CallCredentials } from "./call-credentials";
19-
import { Status } from "./constants";
20-
import { Deadline } from "./deadline";
21-
import { Metadata } from "./metadata";
22-
import { ServerSurfaceCall } from "./server-call";
18+
import { CallCredentials } from './call-credentials';
19+
import { Status } from './constants';
20+
import { Deadline } from './deadline';
21+
import { Metadata } from './metadata';
22+
import { ServerSurfaceCall } from './server-call';
2323

2424
export interface CallStreamOptions {
2525
deadline: Deadline;
@@ -38,7 +38,7 @@ export interface StatusObject {
3838

3939
export type PartialStatusObject = Pick<StatusObject, 'code' | 'details'> & {
4040
metadata: Metadata | null;
41-
}
41+
};
4242

4343
export const enum WriteFlags {
4444
BufferHint = 1,
@@ -118,7 +118,7 @@ export class InterceptingListenerImpl implements InterceptingListener {
118118

119119
onReceiveMetadata(metadata: Metadata): void {
120120
this.processingMetadata = true;
121-
this.listener.onReceiveMetadata(metadata, (metadata) => {
121+
this.listener.onReceiveMetadata(metadata, metadata => {
122122
this.processingMetadata = false;
123123
this.nextListener.onReceiveMetadata(metadata);
124124
this.processPendingMessage();
@@ -128,9 +128,9 @@ export class InterceptingListenerImpl implements InterceptingListener {
128128
// eslint-disable-next-line @typescript-eslint/no-explicit-any
129129
onReceiveMessage(message: any): void {
130130
/* If this listener processes messages asynchronously, the last message may
131-
* be reordered with respect to the status */
131+
* be reordered with respect to the status */
132132
this.processingMessage = true;
133-
this.listener.onReceiveMessage(message, (msg) => {
133+
this.listener.onReceiveMessage(message, msg => {
134134
this.processingMessage = false;
135135
if (this.processingMetadata) {
136136
this.pendingMessage = msg;
@@ -142,7 +142,7 @@ export class InterceptingListenerImpl implements InterceptingListener {
142142
});
143143
}
144144
onReceiveStatus(status: StatusObject): void {
145-
this.listener.onReceiveStatus(status, (processedStatus) => {
145+
this.listener.onReceiveStatus(status, processedStatus => {
146146
if (this.processingMetadata || this.processingMessage) {
147147
this.pendingStatus = processedStatus;
148148
} else {
@@ -170,4 +170,4 @@ export interface Call {
170170
halfClose(): void;
171171
getCallNumber(): number;
172172
setCredentials(credentials: CallCredentials): void;
173-
}
173+
}

packages/grpc-js/src/call-number.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
let nextCallNumber = 0;
1919

2020
export function getNextCallNumber() {
21-
return nextCallNumber++;
22-
}
21+
return nextCallNumber++;
22+
}

packages/grpc-js/src/call.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,29 @@ export type ClientWritableStream<RequestType> = {
6565
/**
6666
* A type representing the return value of a bidirectional stream method call.
6767
*/
68-
export type ClientDuplexStream<
69-
RequestType,
70-
ResponseType
71-
> = ClientWritableStream<RequestType> & ClientReadableStream<ResponseType>;
68+
export type ClientDuplexStream<RequestType, ResponseType> =
69+
ClientWritableStream<RequestType> & ClientReadableStream<ResponseType>;
7270

7371
/**
7472
* Construct a ServiceError from a StatusObject. This function exists primarily
7573
* as an attempt to make the error stack trace clearly communicate that the
7674
* error is not necessarily a problem in gRPC itself.
7775
* @param status
7876
*/
79-
export function callErrorFromStatus(status: StatusObject, callerStack: string): ServiceError {
77+
export function callErrorFromStatus(
78+
status: StatusObject,
79+
callerStack: string
80+
): ServiceError {
8081
const message = `${status.code} ${Status[status.code]}: ${status.details}`;
8182
const error = new Error(message);
8283
const stack = `${error.stack}\nfor call at\n${callerStack}`;
83-
return Object.assign(new Error(message), status, {stack});
84+
return Object.assign(new Error(message), status, { stack });
8485
}
8586

8687
export class ClientUnaryCallImpl
8788
extends EventEmitter
88-
implements ClientUnaryCall {
89+
implements ClientUnaryCall
90+
{
8991
public call?: InterceptingCallInterface;
9092
constructor() {
9193
super();
@@ -102,7 +104,8 @@ export class ClientUnaryCallImpl
102104

103105
export class ClientReadableStreamImpl<ResponseType>
104106
extends Readable
105-
implements ClientReadableStream<ResponseType> {
107+
implements ClientReadableStream<ResponseType>
108+
{
106109
public call?: InterceptingCallInterface;
107110
constructor(readonly deserialize: (chunk: Buffer) => ResponseType) {
108111
super({ objectMode: true });
@@ -123,7 +126,8 @@ export class ClientReadableStreamImpl<ResponseType>
123126

124127
export class ClientWritableStreamImpl<RequestType>
125128
extends Writable
126-
implements ClientWritableStream<RequestType> {
129+
implements ClientWritableStream<RequestType>
130+
{
127131
public call?: InterceptingCallInterface;
128132
constructor(readonly serialize: (value: RequestType) => Buffer) {
129133
super({ objectMode: true });
@@ -156,7 +160,8 @@ export class ClientWritableStreamImpl<RequestType>
156160

157161
export class ClientDuplexStreamImpl<RequestType, ResponseType>
158162
extends Duplex
159-
implements ClientDuplexStream<RequestType, ResponseType> {
163+
implements ClientDuplexStream<RequestType, ResponseType>
164+
{
160165
public call?: InterceptingCallInterface;
161166
constructor(
162167
readonly serialize: (value: RequestType) => Buffer,

0 commit comments

Comments
 (0)