Skip to content

Commit f41a673

Browse files
authored
Convert all server packages to ESLint (#821)
This commit fully converts all lerna-managed **_server_** packages to use ESLint rather than TSLint. For each package the following was done: - Updated all code to address ESLint rules or ignore them - Removed the tslint.json file from the project - Updated eslintrc to use the `no-tslint` config - (if needed) added an .editorconfig file to help VSCode format indentation properly - Added eslint plugin dependencies to package.json and remove tslint dependency - Updated tslint task - Removed all // tslint comments - Alphabetized rules in eslintrc
1 parent 15a65d2 commit f41a673

File tree

185 files changed

+1137
-898
lines changed

Some content is hidden

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

185 files changed

+1137
-898
lines changed

packages/utils/build-common/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"@typescript-eslint/eslint-plugin-tslint": "^2.9.0",
1515
"@typescript-eslint/parser": "^2.9.0",
1616
"eslint": "^6.7.1",
17+
"eslint-plugin-import": "^2.18.2",
18+
"eslint-plugin-no-null": "^1.0.2",
19+
"eslint-plugin-prefer-arrow": "^1.1.7",
20+
"eslint-plugin-react": "^7.16.0",
21+
"eslint-plugin-unicorn": "^14.0.1",
1722
"tslint": "^5.20.0",
1823
"tslint-microsoft-contrib": "^6.0.0",
1924
"typescript": "~3.4.5"

packages/utils/eslint-config-fluid/default.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ module.exports = {
6262
"lintFile": "./tslint.json"
6363
}
6464
],
65+
"import/no-unresolved": [
66+
"error",
67+
{
68+
"caseSensitive": false
69+
}
70+
],
6571
"no-case-declarations": "off"
6672
},
6773
"settings": {

packages/utils/eslint-config-fluid/no-tslint.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ module.exports = {
181181
],
182182
"import/no-internal-modules": "error",
183183
"import/no-unassigned-import": "error",
184+
"import/no-unresolved": [
185+
"error",
186+
{
187+
"caseSensitive": false
188+
}
189+
],
184190
"import/order": "error",
185191
"linebreak-style": "off",
186192
"max-classes-per-file": "off",

samples/chaincode/chat-3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"start:live": "webpack-dev-server --config webpack.config.js --package package.json --env.mode live",
2121
"start:localhost": "webpack-dev-server --config webpack.config.js --package package.json --env.mode localhost",
2222
"tsc": "tsc",
23-
"tslint": "npm run eslint",
23+
"tslint": "tslint --project tsconfig.json --format verbose",
2424
"webpack": "webpack --env=\"production\""
2525
},
2626
"dependencies": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.spec.ts
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": [
3+
"@microsoft/eslint-config-fluid/no-tslint"
4+
],
5+
"rules": {}
6+
}

server/routerlicious/packages/gitresources/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@
1313
"build:full": "npm run build",
1414
"build:full:compile": "npm run build:compile",
1515
"clean": "rimraf dist *.tsbuildinfo *.build.log",
16+
"eslint": "eslint --ext=ts,tsx --format stylish src",
17+
"eslint:fix": "eslint --ext=ts,tsx --format stylish src --fix",
1618
"tsc": "tsc",
17-
"tslint": "tslint --project tsconfig.json --format verbose"
19+
"tslint": "npm run eslint"
1820
},
1921
"devDependencies": {
22+
"@microsoft/eslint-config-fluid": "^0.13.0",
2023
"@microsoft/fluid-build-common": "^0.13.0",
24+
"@typescript-eslint/eslint-plugin": "^2.9.0",
25+
"@typescript-eslint/parser": "^2.9.0",
2126
"concurrently": "^4.1.0",
27+
"eslint": "^6.7.1",
28+
"eslint-plugin-import": "^2.18.2",
29+
"eslint-plugin-no-null": "^1.0.2",
30+
"eslint-plugin-prefer-arrow": "^1.1.7",
31+
"eslint-plugin-react": "^7.16.0",
32+
"eslint-plugin-unicorn": "^14.0.1",
2233
"rimraf": "^2.6.2",
23-
"tslint": "^5.20.0",
2434
"typescript": "~3.4.5"
2535
}
2636
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.spec.ts
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": [
3+
"@microsoft/eslint-config-fluid/no-tslint"
4+
],
5+
"rules": {}
6+
}

server/routerlicious/packages/kafka-orderer/package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@
1414
"build:full": "npm run build",
1515
"build:full:compile": "npm run build:compile",
1616
"clean": "rimraf dist lib *.tsbuildinfo *.build.log",
17+
"eslint": "eslint --ext=ts,tsx --format stylish src",
18+
"eslint:fix": "eslint --ext=ts,tsx --format stylish src --fix",
1719
"tsc": "tsc",
18-
"tslint": "tslint --project tsconfig.json --format verbose"
20+
"tslint": "npm run eslint"
1921
},
2022
"dependencies": {
2123
"@microsoft/fluid-protocol-definitions": "^0.1001.0",
2224
"@microsoft/fluid-server-services-core": "^0.1001.0",
2325
"@types/lodash": "^4.14.118",
24-
"@types/node": "^10.14.6",
25-
"lodash": "^4.17.11"
26+
"@types/node": "^10.14.6"
2627
},
2728
"devDependencies": {
2829
"@microsoft/fluid-build-common": "^0.13.0",
2930
"concurrently": "^4.1.0",
31+
"eslint": "^6.7.1",
32+
"eslint-plugin-import": "^2.18.2",
33+
"eslint-plugin-no-null": "^1.0.2",
34+
"eslint-plugin-prefer-arrow": "^1.1.7",
35+
"eslint-plugin-react": "^7.16.0",
36+
"eslint-plugin-unicorn": "^14.0.1",
3037
"rimraf": "^2.6.2",
31-
"tslint": "^5.20.0",
3238
"typescript": "~3.4.5"
3339
}
34-
}
40+
}

server/routerlicious/packages/kafka-orderer/src/kafkaOrderer.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
MessageType,
1313
} from "@microsoft/fluid-protocol-definitions";
1414
import * as core from "@microsoft/fluid-server-services-core";
15-
import * as _ from "lodash";
15+
16+
/* eslint-disable no-null/no-null */
1617

1718
export class KafkaOrdererConnection implements core.IOrdererConnection {
1819
public static async create(
@@ -43,16 +44,16 @@ export class KafkaOrdererConnection implements core.IOrdererConnection {
4344
return this._parentBranch;
4445
}
4546

46-
private _parentBranch: string;
47+
private readonly _parentBranch: string;
4748

4849
constructor(
4950
public readonly existing: boolean,
5051
document: core.IDocument,
51-
private producer: core.IProducer,
52+
private readonly producer: core.IProducer,
5253
public readonly tenantId: string,
5354
public readonly documentId: string,
5455
public readonly clientId: string,
55-
private client: IClient,
56+
private readonly client: IClient,
5657
public readonly maxMessageSize: number,
5758
public readonly serviceConfiguration: IServiceConfiguration,
5859
) {
@@ -129,7 +130,7 @@ export class KafkaOrdererConnection implements core.IOrdererConnection {
129130
private submitRawOperation(messages: core.IRawOperationMessage[]) {
130131
// Add trace
131132
messages.forEach((message) => {
132-
const operation = message.operation as IDocumentMessage;
133+
const operation = message.operation;
133134
if (operation && operation.traces === undefined) {
134135
operation.traces = [];
135136
} else if (operation && operation.traces && operation.traces.length > 1) {
@@ -142,6 +143,7 @@ export class KafkaOrdererConnection implements core.IOrdererConnection {
142143
}
143144
});
144145

146+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
145147
this.producer.send(messages, this.tenantId, this.documentId);
146148
}
147149
}
@@ -160,11 +162,11 @@ export class KafkaOrderer implements core.IOrderer {
160162
private existing: boolean;
161163

162164
constructor(
163-
private producer: core.IProducer,
164-
private tenantId: string,
165-
private documentId: string,
166-
private maxMessageSize: number,
167-
private serviceConfiguration: IServiceConfiguration,
165+
private readonly producer: core.IProducer,
166+
private readonly tenantId: string,
167+
private readonly documentId: string,
168+
private readonly maxMessageSize: number,
169+
private readonly serviceConfiguration: IServiceConfiguration,
168170
) {
169171
}
170172

@@ -186,24 +188,25 @@ export class KafkaOrderer implements core.IOrderer {
186188
clientId,
187189
this.serviceConfiguration);
188190

189-
// document is now existing regardless of the original value
191+
// Document is now existing regardless of the original value
190192
this.existing = true;
191193

192194
return connection;
193195
}
194196

197+
// eslint-disable-next-line @typescript-eslint/promise-function-async
195198
public close() {
196199
return Promise.resolve();
197200
}
198201
}
199202

200203
export class KafkaOrdererFactory {
201-
private ordererMap = new Map<string, Promise<core.IOrderer>>();
204+
private readonly ordererMap = new Map<string, Promise<core.IOrderer>>();
202205

203206
constructor(
204-
private producer: core.IProducer,
205-
private maxMessageSize: number,
206-
private serviceConfiguration: IServiceConfiguration,
207+
private readonly producer: core.IProducer,
208+
private readonly maxMessageSize: number,
209+
private readonly serviceConfiguration: IServiceConfiguration,
207210
) {
208211
}
209212

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.spec.ts
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": [
3+
"@microsoft/eslint-config-fluid/no-tslint"
4+
],
5+
"rules": {
6+
"@typescript-eslint/strict-boolean-expressions": "off"
7+
}
8+
}

server/routerlicious/packages/lambdas-driver/package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
"build:full": "npm run build",
1616
"build:full:compile": "npm run build:compile",
1717
"clean": "rimraf dist lib *.tsbuildinfo *.build.log",
18+
"eslint": "eslint --ext=ts,tsx --format stylish src",
19+
"eslint:fix": "eslint --ext=ts,tsx --format stylish src --fix",
1820
"test": "mocha --recursive dist/test -r make-promises-safe",
1921
"test:coverage": "nyc npm test -- --reporter mocha-junit-reporter --reporter-options mochaFile=nyc/junit-report.xml",
2022
"tsc": "tsc",
21-
"tslint": "tslint --project tsconfig.json --format verbose"
23+
"tslint": "npm run eslint"
2224
},
2325
"dependencies": {
2426
"@microsoft/fluid-core-utils": "0.13.17538",
@@ -32,18 +34,27 @@
3234
"winston": "^3.1.0"
3335
},
3436
"devDependencies": {
37+
"@microsoft/eslint-config-fluid": "^0.13.0",
3538
"@microsoft/fluid-build-common": "^0.13.0",
3639
"@microsoft/fluid-server-test-utils": "^0.1001.0",
40+
"@typescript-eslint/eslint-plugin": "^2.9.0",
41+
"@typescript-eslint/parser": "^2.9.0",
3742
"@types/async": "^2.0.50",
3843
"@types/lodash": "^4.14.118",
3944
"@types/mocha": "^5.2.5",
4045
"@types/nconf": "^0.0.37",
4146
"@types/node": "^10.14.6",
4247
"concurrently": "^4.1.0",
48+
"eslint": "^6.7.1",
49+
"eslint-plugin-import": "^2.18.2",
50+
"eslint-plugin-no-null": "^1.0.2",
51+
"eslint-plugin-prefer-arrow": "^1.1.7",
52+
"eslint-plugin-react": "^7.16.0",
53+
"eslint-plugin-unicorn": "^14.0.1",
4354
"make-promises-safe": "^5.1.0",
4455
"mocha": "^5.2.0",
56+
"nyc": "^14.1.1",
4557
"rimraf": "^2.6.2",
46-
"tslint": "^5.20.0",
4758
"typescript": "~3.4.5"
4859
},
4960
"nyc": {

server/routerlicious/packages/lambdas-driver/src/document-router/contextManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import { IContext } from "@microsoft/fluid-server-services-core";
76
import * as assert from "assert";
87
import { EventEmitter } from "events";
8+
import { IContext } from "@microsoft/fluid-server-services-core";
99
import { DocumentContext } from "./documentContext";
1010

1111
// Constant representing the previous checkpointed offset
@@ -16,7 +16,7 @@ const LastCheckpointedOffset = -1;
1616
* from them.
1717
*/
1818
export class DocumentContextManager extends EventEmitter {
19-
private contexts: DocumentContext[] = [];
19+
private readonly contexts: DocumentContext[] = [];
2020

2121
// Head and tail represent our processing position of the queue. Head is the latest message seen and
2222
// tail is the last message processed
@@ -28,7 +28,7 @@ export class DocumentContextManager extends EventEmitter {
2828

2929
private closed = false;
3030

31-
constructor(private partitionContext: IContext) {
31+
constructor(private readonly partitionContext: IContext) {
3232
super();
3333
}
3434

server/routerlicious/packages/lambdas-driver/src/document-router/documentContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import { IContext } from "@microsoft/fluid-server-services-core";
76
import * as assert from "assert";
87
import { EventEmitter } from "events";
8+
import { IContext } from "@microsoft/fluid-server-services-core";
99

1010
export class DocumentContext extends EventEmitter implements IContext {
1111
// We track two offsets - head and tail. Head represents the largest offset related to this document we

server/routerlicious/packages/lambdas-driver/src/document-router/documentLambda.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ import { DocumentContextManager } from "./contextManager";
1515
import { DocumentPartition } from "./documentPartition";
1616

1717
export class DocumentLambda implements IPartitionLambda {
18-
private documents = new Map<string, DocumentPartition>();
19-
private contextManager: DocumentContextManager;
18+
private readonly documents = new Map<string, DocumentPartition>();
19+
private readonly contextManager: DocumentContextManager;
2020

21-
constructor(private factory: IPartitionLambdaFactory, private config: Provider, context: IContext) {
21+
constructor(
22+
private readonly factory: IPartitionLambdaFactory,
23+
private readonly config: Provider,
24+
context: IContext) {
2225
this.contextManager = new DocumentContextManager(context);
2326
this.contextManager.on("error", (error, restart) => {
2427
context.error(error, restart);
@@ -65,7 +68,7 @@ export class DocumentLambda implements IPartitionLambda {
6568
this.documents.set(routingKey, document);
6669
} else {
6770
document = this.documents.get(routingKey);
68-
// setHead assumes it will always receive increasing offsets. So we need to split the creation case
71+
// SetHead assumes it will always receive increasing offsets. So we need to split the creation case
6972
// from the update case.
7073
document.context.setHead(kafkaMessage.offset);
7174
}

server/routerlicious/packages/lambdas-driver/src/document-router/documentPartition.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import * as winston from "winston";
1111
import { DocumentContext } from "./documentContext";
1212

1313
export class DocumentPartition {
14-
private q: AsyncQueue<IKafkaMessage>;
15-
private lambdaP: Promise<IPartitionLambda>;
14+
private readonly q: AsyncQueue<IKafkaMessage>;
15+
private readonly lambdaP: Promise<IPartitionLambda>;
1616
private lambda: IPartitionLambda;
1717
private corrupt = false;
1818

@@ -23,15 +23,15 @@ export class DocumentPartition {
2323
documentId: string,
2424
public context: DocumentContext) {
2525

26-
// default to the git tenant if not specified
26+
// Default to the git tenant if not specified
2727
const clonedConfig = _.cloneDeep((config as any).get());
2828
clonedConfig.tenantId = tenantId;
2929
clonedConfig.documentId = documentId;
3030
const documentConfig = new Provider({}).defaults(clonedConfig).use("memory");
3131

3232
this.q = queue(
3333
(message: IKafkaMessage, callback) => {
34-
// winston.verbose(`${message.topic}:${message.partition}@${message.offset}`);
34+
// Winston.verbose(`${message.topic}:${message.partition}@${message.offset}`);
3535
try {
3636
if (!this.corrupt) {
3737
this.lambda.handler(message);
@@ -46,7 +46,7 @@ export class DocumentPartition {
4646
this.corrupt = true;
4747
}
4848

49-
// handle the next message
49+
// Handle the next message
5050
callback();
5151
},
5252
1);

server/routerlicious/packages/lambdas-driver/src/document-router/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { DocumentLambdaFactory } from "./lambdaFactory";
99

1010
export async function create(config: Provider): Promise<IPartitionLambdaFactory> {
1111
const pluginConfig = config.get("documentLambda") as string | object;
12-
// tslint:disable-next-line:non-literal-require
12+
// eslint-disable-next-line @typescript-eslint/no-require-imports
1313
const plugin = (typeof pluginConfig === "object" ? pluginConfig : require(pluginConfig)) as IPlugin;
1414

1515
// Factory used to create document lambda processors

0 commit comments

Comments
 (0)