Skip to content

Commit

Permalink
chore: update @typescript-eslint to v2 (#671)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
G-Rath committed May 29, 2023
1 parent d5203a5 commit 65560e4
Show file tree
Hide file tree
Showing 18 changed files with 424 additions and 280 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"],
"rules": {
"prefer-const": ["error", { "destructuring": "all" }],
"quotes": ["error", "double"],
"@typescript-eslint/indent": [
"error",
Expand All @@ -17,4 +18,4 @@
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/no-object-literal-type-assertion": 0
}
}
}
592 changes: 359 additions & 233 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"clean:int": "rm -rf integrationTests/configurations/**/.serverless integrationTests/configurations/**/node_modules integrationTests/configurations/**/local.settings.json",
"pretest:int": "npm run clean:int",
"test:int": "clvr",
"compile": "tsc",
"compile": "tsc -p tsconfig.build.json",
"prebuild": "shx rm -rf lib/ && npm run test",
"build": "npm run compile",
"generate:spn": "bash ./scripts/generate-service-principal.sh",
Expand Down Expand Up @@ -78,8 +78,8 @@
"@types/serverless": "^1.18.2",
"@types/xml": "^1.0.3",
"@types/xml2js": "^0.4.5",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"acorn": "^7.0.0",
"axios-mock-adapter": "^1.16.0",
"babel-jest": "^24.8.0",
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/func/azureFuncPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ describe("Azure Func Plugin", () => {

it("creates function handler and updates serverless.yml", async () => {
const sls = MockFactory.createTestServerless();
MockFactory.updateService(sls, MockFactory.createTestSlsFunctionConfig(false))
MockFactory.updateService(sls, MockFactory.createTestSlsFunctionConfig())
const options = MockFactory.createTestServerlessOptions();
const functionName = "myFunction";
options["name"] = functionName;
const expectedFunctionsYml = MockFactory.createTestSlsFunctionConfig(false);
const expectedFunctionsYml = MockFactory.createTestSlsFunctionConfig();
expectedFunctionsYml[functionName] = MockFactory.createTestFunctionMetadata(functionName);

const plugin = new AzureFuncPlugin(sls, options);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/login/utils/simpleFileTokenCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from "fs";
describe("Simple File Token Cache", () => {
const tokenFilePath = "slsTokenCache.json";

let fileContent = {
const fileContent = {
entries: [],
subscriptions: []
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/login/utils/simpleFileTokenCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class SimpleFileTokenCache implements adal.TokenCache {
}

public find(query: any, callback: (err?: Error, result?: any[]) => void) {
let result = (this.entries)
const result = (this.entries)
?
this.entries.filter(e => {
return Object.keys(query).every(key => e[key] === query[key]);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/package/azurePackagePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PackageService } from "../../services/packageService";
import { AzureBasePlugin } from "../azureBasePlugin";

export class AzurePackagePlugin extends AzureBasePlugin {
private bindingsCreated: boolean = false;
private bindingsCreated = false;
public provider: AzureProvider;

public constructor(serverless: Serverless, options: Serverless.Options) {
Expand Down
6 changes: 3 additions & 3 deletions src/services/apimService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ describe("APIM Service", () => {

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

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

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

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

expect(actual).toMatchObject({
Expand Down
2 changes: 1 addition & 1 deletion src/services/azureBlobStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class AzureBlobStorageService extends BaseService {
* @param blobName Name of blob to generate SAS token for
* @param days Number of days from current date until expiry of SAS token. Defaults to 1 year
*/
public async generateBlobSasTokenUrl(containerName: string, blobName: string, days: number = 365): Promise<string> {
public async generateBlobSasTokenUrl(containerName: string, blobName: string, days = 365): Promise<string> {
this.checkInitialization();
if (this.authType !== AzureStorageAuthType.SharedKey) {
throw new Error("Need to authenticate with shared key in order to generate SAS tokens. " +
Expand Down
2 changes: 1 addition & 1 deletion src/services/baseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export abstract class BaseService {
protected constructor(
protected serverless: Serverless,
protected options: ServerlessAzureOptions = { stage: null, region: null },
authenticate: boolean = true
authenticate = true
) {
Guard.null(serverless);
this.configService = new ConfigService(serverless, options);
Expand Down
4 changes: 2 additions & 2 deletions src/services/funcService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ describe("Azure Func Service", () => {

it("creates function handler and updates serverless.yml", async () => {
const sls = MockFactory.createTestServerless();
MockFactory.updateService(sls, MockFactory.createTestSlsFunctionConfig(false))
MockFactory.updateService(sls, MockFactory.createTestSlsFunctionConfig())
const options = MockFactory.createTestServerlessOptions();
const functionName = "myFunction";
options["name"] = functionName;
const expectedFunctionsYml = MockFactory.createTestSlsFunctionConfig(false);
const expectedFunctionsYml = MockFactory.createTestSlsFunctionConfig();
expectedFunctionsYml[functionName] = MockFactory.createTestFunctionMetadata(functionName);

const service = createService(sls, options);
Expand Down
2 changes: 1 addition & 1 deletion src/services/functionAppService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class FunctionAppService extends BaseService {

const armService = new ArmService(this.serverless, this.options);
const { armTemplate, type } = this.config.provider;
let deployment: ArmDeployment = armTemplate
const deployment: ArmDeployment = armTemplate
? await armService.createDeploymentFromConfig(armTemplate)
: await armService.createDeploymentFromType(type || "consumption");

Expand Down
2 changes: 1 addition & 1 deletion src/services/packageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class PackageService extends BaseService {
/**
* Creates the function.json binding files required for the serverless service
*/
public async createBindings(offlineMode: boolean = false): Promise<void> {
public async createBindings(offlineMode = false): Promise<void> {
const createEventsPromises = this.serverless.service.getAllFunctions()
.map(async (functionName) => {
const metaData = await Utils.getFunctionMetaData(functionName, this.serverless, offlineMode);
Expand Down
2 changes: 1 addition & 1 deletion src/services/rollbackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class RollbackService extends BaseService {
* Lists deployments if no timestamp is provided
*/
private async getDeployment(): Promise<DeploymentExtended> {
let timestamp = Utils.get(this.options, "timestamp");
const timestamp = Utils.get(this.options, "timestamp");
if (!timestamp) {
this.log("Need to specify a timestamp for rollback.\n\n" +
"Example usage:\n\nsls rollback -t 1562014362\n\n" +
Expand Down
6 changes: 3 additions & 3 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface ServerlessSpawnOptions {
}

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

Expand All @@ -211,7 +211,7 @@ export class Utils {
* Waits for the specified amount of time.
* @param time The amount of time to wait (default = 1000ms)
*/
public static wait(time: number = 1000) {
public static wait(time = 1000) {
return new Promise((resolve) => {
setTimeout(resolve, time);
});
Expand Down
38 changes: 19 additions & 19 deletions src/test/mockFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class MockFactory {
return functions;
}

public static createTestFunction(name: string = "TestFunction") {
public static createTestFunction(name = "TestFunction") {
return {
properties: {
name,
Expand All @@ -153,7 +153,7 @@ export class MockFactory {
return credentials;
}

public static createTestTokenCacheEntries(count: number = 1): TokenResponse[] {
public static createTestTokenCacheEntries(count = 1): TokenResponse[] {
const token: TokenResponse = {
tokenType: "Bearer",
accessToken: "ABC123",
Expand All @@ -164,7 +164,7 @@ export class MockFactory {
return result;
}

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

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

public static createTestDeployment(name?: string, second: number = 0): DeploymentExtended {
public static createTestDeployment(name?: string, second = 0): DeploymentExtended {
return {
name: name || `${constants.naming.suffix.deployment}1-t${MockFactory.createTestTimestamp()}`,
properties: {
Expand All @@ -215,7 +215,7 @@ export class MockFactory {
public static createTestAxiosResponse<T>(
config: AxiosRequestConfig,
responseJson: T,
statusCode: number = 200,
statusCode = 200,
): Promise<AxiosResponse> {
let statusText;
switch (statusCode) {
Expand All @@ -240,7 +240,7 @@ export class MockFactory {
return Promise.resolve(response);
}

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

public static createTestBlockBlobUrl(containerName: string, blobName: string, contents: string = "test") {
public static createTestBlockBlobUrl(containerName: string, blobName: string, contents = "test") {
return {
containerName,
blobName,
Expand All @@ -263,21 +263,21 @@ export class MockFactory {
}
}

public static createTestAzureBlobItems(id: number = 1, count: number = 5) {
public static createTestAzureBlobItems(id = 1, count = 5) {
const result = [];
for (let i = 0; i < count; i++) {
result.push(MockFactory.createTestAzureBlobItem(id, i));
}
return { segment: { blobItems: result } };
}

public static createTestAzureBlobItem(id: number = 1, index: number = 1, ext: string = ".zip") {
public static createTestAzureBlobItem(id = 1, index = 1, ext = ".zip") {
return {
name: `blob-${id}-${index}${ext}`
}
}

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

public static createTestApimConfig(generateName: boolean = false): ApiManagementConfig {
public static createTestApimConfig(generateName = false): ApiManagementConfig {
return {
name: generateName ? null : "test-apim-resource",
apis: [{
Expand Down Expand Up @@ -332,7 +332,7 @@ export class MockFactory {
};
}

public static createTestKeyVaultConfig(name: string = "testVault") {
public static createTestKeyVaultConfig(name = "testVault") {
return {
name: name,
resourceGroup: "testGroup",
Expand Down Expand Up @@ -422,7 +422,7 @@ export class MockFactory {
}
}

public static createTestSite(name: string = "Test"): Site {
public static createTestSite(name = "Test"): Site {
return {
id: "appId",
name: name,
Expand All @@ -435,7 +435,7 @@ export class MockFactory {
};
}

public static createTestFunctionEnvelope(name: string = "TestFunction"): FunctionEnvelope {
public static createTestFunctionEnvelope(name = "TestFunction"): FunctionEnvelope {
return {
name,
config: {
Expand Down Expand Up @@ -520,7 +520,7 @@ export class MockFactory {
}
}

public static createTestEventHubBinding(direction: string = "in") {
public static createTestEventHubBinding(direction = "in") {
return {
event: "eventHubTrigger",
direction,
Expand All @@ -530,7 +530,7 @@ export class MockFactory {
connection: "EventHubsConnection"
}
}
public static createTestBindingsObject(name: string = "index.js") {
public static createTestBindingsObject(name = "index.js") {
return {
scriptFile: name,
entryPoint: "handler",
Expand Down Expand Up @@ -578,7 +578,7 @@ export class MockFactory {
return apis;
}

public static createTestApimApi(index: number = 1): ApiContract {
public static createTestApimApi(index = 1): ApiContract {
return {
displayName: `API ${index}`,
description: `Description for API ${index}`,
Expand All @@ -597,7 +597,7 @@ export class MockFactory {
return backends;
}

public static createTestApimBackend(index: number = 1): BackendContract {
public static createTestApimBackend(index = 1): BackendContract {
return {
name: `backend-${index}`,
description: `Description for Backend ${index}`,
Expand Down
15 changes: 15 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"noEmit": false
},
"include": [
"./src",
"./src/**/*.json"
],
"exclude": [
"**/test",
"**/*.test.ts"
]
}
Loading

0 comments on commit 65560e4

Please sign in to comment.