Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 65560e4

Browse files
authored
chore: update @typescript-eslint to v2 (#671)
* chore: update `@typescript-eslint` dependencies to v2 * chore: apply eslint fixes * test: remove unused parameter * test: cast `unknown` to `any` * chore: apply more eslint fixes
1 parent d5203a5 commit 65560e4

18 files changed

+424
-280
lines changed

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"plugins": ["@typescript-eslint"],
77
"extends": ["plugin:@typescript-eslint/recommended"],
88
"rules": {
9+
"prefer-const": ["error", { "destructuring": "all" }],
910
"quotes": ["error", "double"],
1011
"@typescript-eslint/indent": [
1112
"error",
@@ -17,4 +18,4 @@
1718
"@typescript-eslint/no-use-before-define": 0,
1819
"@typescript-eslint/no-object-literal-type-assertion": 0
1920
}
20-
}
21+
}

package-lock.json

+359-233
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"clean:int": "rm -rf integrationTests/configurations/**/.serverless integrationTests/configurations/**/node_modules integrationTests/configurations/**/local.settings.json",
1818
"pretest:int": "npm run clean:int",
1919
"test:int": "clvr",
20-
"compile": "tsc",
20+
"compile": "tsc -p tsconfig.build.json",
2121
"prebuild": "shx rm -rf lib/ && npm run test",
2222
"build": "npm run compile",
2323
"generate:spn": "bash ./scripts/generate-service-principal.sh",
@@ -78,8 +78,8 @@
7878
"@types/serverless": "^1.18.2",
7979
"@types/xml": "^1.0.3",
8080
"@types/xml2js": "^0.4.5",
81-
"@typescript-eslint/eslint-plugin": "^1.9.0",
82-
"@typescript-eslint/parser": "^1.9.0",
81+
"@typescript-eslint/eslint-plugin": "^2.0.0",
82+
"@typescript-eslint/parser": "^2.0.0",
8383
"acorn": "^7.0.0",
8484
"axios-mock-adapter": "^1.16.0",
8585
"babel-jest": "^24.8.0",

src/plugins/func/azureFuncPlugin.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ describe("Azure Func Plugin", () => {
6262

6363
it("creates function handler and updates serverless.yml", async () => {
6464
const sls = MockFactory.createTestServerless();
65-
MockFactory.updateService(sls, MockFactory.createTestSlsFunctionConfig(false))
65+
MockFactory.updateService(sls, MockFactory.createTestSlsFunctionConfig())
6666
const options = MockFactory.createTestServerlessOptions();
6767
const functionName = "myFunction";
6868
options["name"] = functionName;
69-
const expectedFunctionsYml = MockFactory.createTestSlsFunctionConfig(false);
69+
const expectedFunctionsYml = MockFactory.createTestSlsFunctionConfig();
7070
expectedFunctionsYml[functionName] = MockFactory.createTestFunctionMetadata(functionName);
7171

7272
const plugin = new AzureFuncPlugin(sls, options);

src/plugins/login/utils/simpleFileTokenCache.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import fs from "fs";
88
describe("Simple File Token Cache", () => {
99
const tokenFilePath = "slsTokenCache.json";
1010

11-
let fileContent = {
11+
const fileContent = {
1212
entries: [],
1313
subscriptions: []
1414
};

src/plugins/login/utils/simpleFileTokenCache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class SimpleFileTokenCache implements adal.TokenCache {
4242
}
4343

4444
public find(query: any, callback: (err?: Error, result?: any[]) => void) {
45-
let result = (this.entries)
45+
const result = (this.entries)
4646
?
4747
this.entries.filter(e => {
4848
return Object.keys(query).every(key => e[key] === query[key]);

src/plugins/package/azurePackagePlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PackageService } from "../../services/packageService";
99
import { AzureBasePlugin } from "../azureBasePlugin";
1010

1111
export class AzurePackagePlugin extends AzureBasePlugin {
12-
private bindingsCreated: boolean = false;
12+
private bindingsCreated = false;
1313
public provider: AzureProvider;
1414

1515
public constructor(serverless: Serverless, options: Serverless.Options) {

src/services/apimService.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ describe("APIM Service", () => {
526526

527527
Object.assign(serverless.service, { functions });
528528

529-
let apimResource: ApiManagementServiceResource = {
529+
const apimResource: ApiManagementServiceResource = {
530530
name: apimConfig.name,
531531
location: "West US",
532532
gatewayUrl: "https://you.url.com",
@@ -596,7 +596,7 @@ describe("APIM Service", () => {
596596
functions.goodbye.events.forEach((event) => delete event.methods);
597597
Object.assign(serverless.service, { functions });
598598

599-
let apimResource: ApiManagementServiceResource = {
599+
const apimResource: ApiManagementServiceResource = {
600600
name: apimConfig.name,
601601
location: "West US",
602602
gatewayUrl: "https://you.url.com",
@@ -713,7 +713,7 @@ describe("APIM Service", () => {
713713

714714
const createOperationCall = ApiOperation.prototype.createOrUpdate as jest.Mock;
715715
createOperationCall.mock.calls.forEach((args, index) => {
716-
const expected = slsFunctions[index].apim.operations[0] as OperationContract;
716+
const expected = (slsFunctions[index] as any).apim.operations[0] as OperationContract;
717717
const actual = args[4] as OperationContract;
718718

719719
expect(actual).toMatchObject({

src/services/azureBlobStorageService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class AzureBlobStorageService extends BaseService {
192192
* @param blobName Name of blob to generate SAS token for
193193
* @param days Number of days from current date until expiry of SAS token. Defaults to 1 year
194194
*/
195-
public async generateBlobSasTokenUrl(containerName: string, blobName: string, days: number = 365): Promise<string> {
195+
public async generateBlobSasTokenUrl(containerName: string, blobName: string, days = 365): Promise<string> {
196196
this.checkInitialization();
197197
if (this.authType !== AzureStorageAuthType.SharedKey) {
198198
throw new Error("Need to authenticate with shared key in order to generate SAS tokens. " +

src/services/baseService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export abstract class BaseService {
2929
protected constructor(
3030
protected serverless: Serverless,
3131
protected options: ServerlessAzureOptions = { stage: null, region: null },
32-
authenticate: boolean = true
32+
authenticate = true
3333
) {
3434
Guard.null(serverless);
3535
this.configService = new ConfigService(serverless, options);

src/services/funcService.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ describe("Azure Func Service", () => {
5757

5858
it("creates function handler and updates serverless.yml", async () => {
5959
const sls = MockFactory.createTestServerless();
60-
MockFactory.updateService(sls, MockFactory.createTestSlsFunctionConfig(false))
60+
MockFactory.updateService(sls, MockFactory.createTestSlsFunctionConfig())
6161
const options = MockFactory.createTestServerlessOptions();
6262
const functionName = "myFunction";
6363
options["name"] = functionName;
64-
const expectedFunctionsYml = MockFactory.createTestSlsFunctionConfig(false);
64+
const expectedFunctionsYml = MockFactory.createTestSlsFunctionConfig();
6565
expectedFunctionsYml[functionName] = MockFactory.createTestFunctionMetadata(functionName);
6666

6767
const service = createService(sls, options);

src/services/functionAppService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class FunctionAppService extends BaseService {
187187

188188
const armService = new ArmService(this.serverless, this.options);
189189
const { armTemplate, type } = this.config.provider;
190-
let deployment: ArmDeployment = armTemplate
190+
const deployment: ArmDeployment = armTemplate
191191
? await armService.createDeploymentFromConfig(armTemplate)
192192
: await armService.createDeploymentFromType(type || "consumption");
193193

src/services/packageService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class PackageService extends BaseService {
2525
/**
2626
* Creates the function.json binding files required for the serverless service
2727
*/
28-
public async createBindings(offlineMode: boolean = false): Promise<void> {
28+
public async createBindings(offlineMode = false): Promise<void> {
2929
const createEventsPromises = this.serverless.service.getAllFunctions()
3030
.map(async (functionName) => {
3131
const metaData = await Utils.getFunctionMetaData(functionName, this.serverless, offlineMode);

src/services/rollbackService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class RollbackService extends BaseService {
109109
* Lists deployments if no timestamp is provided
110110
*/
111111
private async getDeployment(): Promise<DeploymentExtended> {
112-
let timestamp = Utils.get(this.options, "timestamp");
112+
const timestamp = Utils.get(this.options, "timestamp");
113113
if (!timestamp) {
114114
this.log("Need to specify a timestamp for rollback.\n\n" +
115115
"Example usage:\n\nsls rollback -t 1562014362\n\n" +

src/shared/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface ServerlessSpawnOptions {
2828
}
2929

3030
export class Utils {
31-
public static async getFunctionMetaData(functionName: string, serverless: Serverless, offlineMode: boolean = false): Promise<FunctionMetadata> {
31+
public static async getFunctionMetaData(functionName: string, serverless: Serverless, offlineMode = false): Promise<FunctionMetadata> {
3232
const config: ServerlessAzureConfig = serverless.service as any;
3333
const bindings = [];
3434
let bindingSettingsNames = [];
@@ -188,7 +188,7 @@ export class Utils {
188188
* @param maxRetries The max number of retries
189189
* @param retryWaitInterval The time to wait between retries
190190
*/
191-
public static async runWithRetry<T>(operation: (retry?: number) => Promise<T>, maxRetries: number = 3, retryWaitInterval: number = 1000) {
191+
public static async runWithRetry<T>(operation: (retry?: number) => Promise<T>, maxRetries = 3, retryWaitInterval = 1000) {
192192
let retry = 0;
193193
let error = null;
194194

@@ -211,7 +211,7 @@ export class Utils {
211211
* Waits for the specified amount of time.
212212
* @param time The amount of time to wait (default = 1000ms)
213213
*/
214-
public static wait(time: number = 1000) {
214+
public static wait(time = 1000) {
215215
return new Promise((resolve) => {
216216
setTimeout(resolve, time);
217217
});

src/test/mockFactory.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class MockFactory {
129129
return functions;
130130
}
131131

132-
public static createTestFunction(name: string = "TestFunction") {
132+
public static createTestFunction(name = "TestFunction") {
133133
return {
134134
properties: {
135135
name,
@@ -153,7 +153,7 @@ export class MockFactory {
153153
return credentials;
154154
}
155155

156-
public static createTestTokenCacheEntries(count: number = 1): TokenResponse[] {
156+
public static createTestTokenCacheEntries(count = 1): TokenResponse[] {
157157
const token: TokenResponse = {
158158
tokenType: "Bearer",
159159
accessToken: "ABC123",
@@ -164,7 +164,7 @@ export class MockFactory {
164164
return result;
165165
}
166166

167-
public static createTestSubscriptions(count: number = 1): any[] {
167+
public static createTestSubscriptions(count = 1): any[] {
168168
const sub = {
169169
id: "abc-1234-5678",
170170
state: "Enabled",
@@ -182,7 +182,7 @@ export class MockFactory {
182182
return "1562184492";
183183
}
184184

185-
public static createTestDeployments(count: number = 5, includeTimestamp = false): DeploymentsListByResourceGroupResponse {
185+
public static createTestDeployments(count = 5, includeTimestamp = false): DeploymentsListByResourceGroupResponse {
186186
const result = [];
187187
const originalTimestamp = +MockFactory.createTestTimestamp();
188188
for (let i = 0; i < count; i++) {
@@ -201,7 +201,7 @@ export class MockFactory {
201201
}
202202
}
203203

204-
public static createTestDeployment(name?: string, second: number = 0): DeploymentExtended {
204+
public static createTestDeployment(name?: string, second = 0): DeploymentExtended {
205205
return {
206206
name: name || `${constants.naming.suffix.deployment}1-t${MockFactory.createTestTimestamp()}`,
207207
properties: {
@@ -215,7 +215,7 @@ export class MockFactory {
215215
public static createTestAxiosResponse<T>(
216216
config: AxiosRequestConfig,
217217
responseJson: T,
218-
statusCode: number = 200,
218+
statusCode = 200,
219219
): Promise<AxiosResponse> {
220220
let statusText;
221221
switch (statusCode) {
@@ -240,7 +240,7 @@ export class MockFactory {
240240
return Promise.resolve(response);
241241
}
242242

243-
public static createTestAzureContainers(count: number = 5): ServiceListContainersSegmentResponse {
243+
public static createTestAzureContainers(count = 5): ServiceListContainersSegmentResponse {
244244
const result = [];
245245
for (let i = 0; i < count; i++) {
246246
result.push({
@@ -251,7 +251,7 @@ export class MockFactory {
251251
return { containerItems: result } as ServiceListContainersSegmentResponse;
252252
}
253253

254-
public static createTestBlockBlobUrl(containerName: string, blobName: string, contents: string = "test") {
254+
public static createTestBlockBlobUrl(containerName: string, blobName: string, contents = "test") {
255255
return {
256256
containerName,
257257
blobName,
@@ -263,21 +263,21 @@ export class MockFactory {
263263
}
264264
}
265265

266-
public static createTestAzureBlobItems(id: number = 1, count: number = 5) {
266+
public static createTestAzureBlobItems(id = 1, count = 5) {
267267
const result = [];
268268
for (let i = 0; i < count; i++) {
269269
result.push(MockFactory.createTestAzureBlobItem(id, i));
270270
}
271271
return { segment: { blobItems: result } };
272272
}
273273

274-
public static createTestAzureBlobItem(id: number = 1, index: number = 1, ext: string = ".zip") {
274+
public static createTestAzureBlobItem(id = 1, index = 1, ext = ".zip") {
275275
return {
276276
name: `blob-${id}-${index}${ext}`
277277
}
278278
}
279279

280-
public static createTestAzureClientResponse<T>(responseJson: T, statusCode: number = 200): Promise<HttpOperationResponse> {
280+
public static createTestAzureClientResponse<T>(responseJson: T, statusCode = 200): Promise<HttpOperationResponse> {
281281
const response: HttpOperationResponse = {
282282
request: new WebResource(),
283283
parsedBody: responseJson,
@@ -303,7 +303,7 @@ export class MockFactory {
303303
return (asYaml) ? yaml.dump(data) : data;
304304
}
305305

306-
public static createTestApimConfig(generateName: boolean = false): ApiManagementConfig {
306+
public static createTestApimConfig(generateName = false): ApiManagementConfig {
307307
return {
308308
name: generateName ? null : "test-apim-resource",
309309
apis: [{
@@ -332,7 +332,7 @@ export class MockFactory {
332332
};
333333
}
334334

335-
public static createTestKeyVaultConfig(name: string = "testVault") {
335+
public static createTestKeyVaultConfig(name = "testVault") {
336336
return {
337337
name: name,
338338
resourceGroup: "testGroup",
@@ -422,7 +422,7 @@ export class MockFactory {
422422
}
423423
}
424424

425-
public static createTestSite(name: string = "Test"): Site {
425+
public static createTestSite(name = "Test"): Site {
426426
return {
427427
id: "appId",
428428
name: name,
@@ -435,7 +435,7 @@ export class MockFactory {
435435
};
436436
}
437437

438-
public static createTestFunctionEnvelope(name: string = "TestFunction"): FunctionEnvelope {
438+
public static createTestFunctionEnvelope(name = "TestFunction"): FunctionEnvelope {
439439
return {
440440
name,
441441
config: {
@@ -520,7 +520,7 @@ export class MockFactory {
520520
}
521521
}
522522

523-
public static createTestEventHubBinding(direction: string = "in") {
523+
public static createTestEventHubBinding(direction = "in") {
524524
return {
525525
event: "eventHubTrigger",
526526
direction,
@@ -530,7 +530,7 @@ export class MockFactory {
530530
connection: "EventHubsConnection"
531531
}
532532
}
533-
public static createTestBindingsObject(name: string = "index.js") {
533+
public static createTestBindingsObject(name = "index.js") {
534534
return {
535535
scriptFile: name,
536536
entryPoint: "handler",
@@ -578,7 +578,7 @@ export class MockFactory {
578578
return apis;
579579
}
580580

581-
public static createTestApimApi(index: number = 1): ApiContract {
581+
public static createTestApimApi(index = 1): ApiContract {
582582
return {
583583
displayName: `API ${index}`,
584584
description: `Description for API ${index}`,
@@ -597,7 +597,7 @@ export class MockFactory {
597597
return backends;
598598
}
599599

600-
public static createTestApimBackend(index: number = 1): BackendContract {
600+
public static createTestApimBackend(index = 1): BackendContract {
601601
return {
602602
name: `backend-${index}`,
603603
description: `Description for Backend ${index}`,

tsconfig.build.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"noEmit": false
6+
},
7+
"include": [
8+
"./src",
9+
"./src/**/*.json"
10+
],
11+
"exclude": [
12+
"**/test",
13+
"**/*.test.ts"
14+
]
15+
}

0 commit comments

Comments
 (0)