Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#IP-86] tslint to eslint migration #14

Merged
merged 24 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"ignorePatterns": [
"node_modules",
"generated",
"**/__tests__/*",
"**/__mocks__/*",
"Dangerfile.*",
"*.d.ts"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"extends": [
"@pagopa/eslint-config/strong",
],
"rules": {}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ generated
*.zip

*.js
!.eslintrc.js
michaeldisaro marked this conversation as resolved.
Show resolved Hide resolved
!jest.config.js
!.release-it.js


azure-functions-core-tools

# Exclude ESLint cache file
.eslintcache
2 changes: 1 addition & 1 deletion Dangerfile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import custom DangerJS rules
// see http://danger.systems/js
// see https://github.com/teamdigitale/danger-plugin-digitalcitizenship/
// tslint:disable-next-line:prettier
// eslint-disable-next-line prettier/prettier
import checkDangers from "@pagopa/danger-custom-rules";

checkDangers();
5 changes: 2 additions & 3 deletions HandleNHNotificationCall/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// tslint:disable:no-any

/* eslint-disable @typescript-eslint/no-explicit-any */
import * as df from "durable-functions";
import { DurableOrchestrationClient } from "durable-functions/lib/src/durableorchestrationclient";
import { NonEmptyString } from "italia-ts-commons/lib/strings";
Expand Down Expand Up @@ -92,7 +91,7 @@ describe("HandleNHNotificationCall", () => {
// kind: "WrongMessage" as any
// };

// // tslint:disable-next-line: no-let
// // eslint-disable-next-line
// let hasError = false;
// try {
// await HandleNHNotificationCall(context as any, aWrongMessage);
Expand Down
9 changes: 5 additions & 4 deletions HandleNHNotificationCall/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { KindEnum as CreateOrUpdateKind } from "../generated/notifications/Creat
import { KindEnum as DeleteKind } from "../generated/notifications/DeleteInstallationMessage";
import { KindEnum as NotifyKind } from "../generated/notifications/NotifyMessage";

export const NotificationMessage = t.union([
export const notificationMessage = t.union([
NotifyMessage,
CreateOrUpdateInstallationMessage,
DeleteInstallationMessage
]);

export type NotificationHubMessage = t.TypeOf<typeof NotificationMessage>;
export type NotificationHubMessage = t.TypeOf<typeof notificationMessage>;

const assertNever = (x: never): never => {
throw new Error(`Unexpected object: ${toString(x)}`);
Expand All @@ -31,18 +31,19 @@ export const getHandler = () => async (
): Promise<void> => {
const client = df.getClient(context);
switch (notificationHubMessage.kind) {
// eslint-disable-next-line sonarjs/no-duplicated-branches
case DeleteKind.DeleteInstallation:
await client.startNew("HandleNHNotificationCallOrchestrator", undefined, {
message: notificationHubMessage
});
break;
// eslint-disable-next-line sonarjs/no-duplicated-branches
case CreateOrUpdateKind.CreateOrUpdateInstallation:
// tslint:disable-next-line: no-duplicated-branches
await client.startNew("HandleNHNotificationCallOrchestrator", undefined, {
message: notificationHubMessage
});
break;
// tslint:disable-next-line: no-duplicated-branches
// eslint-disable-next-line sonarjs/no-duplicated-branches
case NotifyKind.Notify:
await client.startNew("HandleNHNotificationCallOrchestrator", undefined, {
message: notificationHubMessage
Expand Down
9 changes: 4 additions & 5 deletions HandleNHNotificationCallActivity/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/* tslint:disable: no-any */
// tslint:disable-next-line: no-object-mutation
/* eslint-disable @typescript-eslint/no-explicit-any */
import { NonEmptyString } from "italia-ts-commons/lib/strings";
import { context as contextMock } from "../../__mocks__/durable-functions";
import { PlatformEnum } from "../../generated/backend/Platform";
import { CreateOrUpdateInstallationMessage } from "../../generated/notifications/CreateOrUpdateInstallationMessage";
import { getCallNHServiceActivityHandler } from "../handler";
import { HandleNHNotificationCallActivityInput as NHServiceActivityInput } from "../handler";
import { handleNHNotificationCallActivityInput as NHServiceActivityInput } from "../handler";

import * as azure from "azure-sb";
import { DeleteInstallationMessage } from "../../generated/notifications/DeleteInstallationMessage";
import { NotifyMessage } from "../../generated/notifications/NotifyMessage";

import * as notificationhubServicePartition from "../../utils/notificationhubServicePartition";
import { NotificationHubConfig } from "../../utils/notificationhubServicePartition";
import { notificationHubConfig, NotificationHubConfig } from "../../utils/notificationhubServicePartition";

import { envConfig } from "../../__mocks__/env-config.mock";
import { NotificationHubService } from "azure-sb";
Expand Down Expand Up @@ -60,7 +59,7 @@ const aDeleteInStalltionMessage: DeleteInstallationMessage = {
kind: "DeleteInstallation" as any
};

const aNHConfig = NotificationHubConfig.decode({
const aNHConfig = notificationHubConfig.decode({
AZURE_NH_ENDPOINT: envConfig.AZURE_NH_ENDPOINT,
AZURE_NH_HUB_NAME: envConfig.AZURE_NH_HUB_NAME
}).getOrElseL(() => {
Expand Down
104 changes: 56 additions & 48 deletions HandleNHNotificationCallActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as t from "io-ts";

import { Context } from "@azure/functions";
import { identity, toString } from "fp-ts/lib/function";
import { fromEither, taskEither } from "fp-ts/lib/TaskEither";
import { fromEither, taskEither, TaskEither } from "fp-ts/lib/TaskEither";

import { readableReport } from "italia-ts-commons/lib/reporters";

import { KindEnum as CreateOrUpdateKind } from "../generated/notifications/CreateOrUpdateInstallationMessage";
import { KindEnum as DeleteKind } from "../generated/notifications/DeleteInstallationMessage";
import { KindEnum as NotifyKind } from "../generated/notifications/NotifyMessage";
import { NotificationMessage } from "../HandleNHNotificationCall/handler";
import { notificationMessage } from "../HandleNHNotificationCall/handler";
import {
createOrUpdateInstallation,
deleteInstallation,
Expand All @@ -26,17 +26,17 @@ import {
import { initTelemetryClient } from "../utils/appinsights";
import {
buildNHService,
NotificationHubConfig
notificationHubConfig
} from "../utils/notificationhubServicePartition";

// Activity input
export const HandleNHNotificationCallActivityInput = t.interface({
message: NotificationMessage,
notificationHubConfig: NotificationHubConfig
export const handleNHNotificationCallActivityInput = t.interface({
message: notificationMessage,
notificationHubConfig
});

export type HandleNHNotificationCallActivityInput = t.TypeOf<
typeof HandleNHNotificationCallActivityInput
typeof handleNHNotificationCallActivityInput
>;

const assertNever = (x: never): never => {
Expand All @@ -49,59 +49,67 @@ const assertNever = (x: never): never => {
export const getCallNHServiceActivityHandler = (
telemetryClient: ReturnType<typeof initTelemetryClient>,
logPrefix = "NHCallServiceActivity"
) => async (context: Context, input: unknown) => {
) => async (context: Context, input: unknown): Promise<ActivityResult> => {
const failure = failActivity(context, logPrefix);
return fromEither(HandleNHNotificationCallActivityInput.decode(input))
return fromEither(handleNHNotificationCallActivityInput.decode(input))
.mapLeft(errs =>
failure("Error decoding activity input", readableReport(errs))
)
.chain<ActivityResultSuccess>(({ message, notificationHubConfig }) => {
context.log.info(
`${logPrefix}|${message.kind}|INSTALLATION_ID=${message.installationId}`
);
.chain<ActivityResultSuccess>(
({
message,
// eslint-disable-next-line @typescript-eslint/no-shadow
notificationHubConfig
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}): TaskEither<any, ActivityResultSuccess> => {
context.log.info(
`${logPrefix}|${message.kind}|INSTALLATION_ID=${message.installationId}`
);

const nhService = buildNHService(notificationHubConfig);
const nhService = buildNHService(notificationHubConfig);

switch (message.kind) {
case CreateOrUpdateKind.CreateOrUpdateInstallation:
return createOrUpdateInstallation(
nhService,
message.installationId,
message.platform,
message.pushChannel,
message.tags
).mapLeft(e =>
retryActivity(context, `${logPrefix}|ERROR=${toString(e)}`)
);
case NotifyKind.Notify:
return notify(nhService, message.installationId, message.payload)
.mapLeft(e =>
switch (message.kind) {
case CreateOrUpdateKind.CreateOrUpdateInstallation:
return createOrUpdateInstallation(
nhService,
message.installationId,
message.platform,
message.pushChannel,
message.tags
).mapLeft(e =>
retryActivity(context, `${logPrefix}|ERROR=${toString(e)}`)
)
.chainFirst(
taskEither.of(
telemetryClient.trackEvent({
name: "api.messages.notification.push.sent",
properties: {
isSuccess: "true",
messageId: message.payload.message_id
},
tagOverrides: { samplingEnabled: "false" }
})
)
);
case DeleteKind.DeleteInstallation:
return deleteInstallation(nhService, message.installationId).mapLeft(
e => {
case NotifyKind.Notify:
return notify(nhService, message.installationId, message.payload)
.mapLeft(e =>
retryActivity(context, `${logPrefix}|ERROR=${toString(e)}`)
)
.chainFirst(
taskEither.of(
telemetryClient.trackEvent({
name: "api.messages.notification.push.sent",
properties: {
isSuccess: "true",
messageId: message.payload.message_id
},
tagOverrides: { samplingEnabled: "false" }
})
)
);
case DeleteKind.DeleteInstallation:
return deleteInstallation(
nhService,
message.installationId
).mapLeft(e => {
// do not trigger a retry as delete may fail in case of 404
context.log.error(`${logPrefix}|ERROR=${toString(e)}`);
return failure(e.message);
}
);
default:
assertNever(message);
});
default:
assertNever(message);
}
}
})
)
.fold<ActivityResult>(identity, success)
.run();
};
11 changes: 5 additions & 6 deletions HandleNHNotificationCallOrchestrator/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* tslint:disable:no-any */
// tslint:disable-next-line: no-object-mutation
/* eslint-disable @typescript-eslint/no-explicit-any */
import { NonEmptyString } from "italia-ts-commons/lib/strings";
import { context as contextMock } from "../../__mocks__/durable-functions";
import { PlatformEnum } from "../../generated/backend/Platform";
import {
CreateOrUpdateInstallationMessage,
KindEnum as CreateOrUpdateInstallationKind
} from "../../generated/notifications/CreateOrUpdateInstallationMessage";
import { HandleNHNotificationCallActivityInput } from "../../HandleNHNotificationCallActivity/handler";
import { NhNotificationOrchestratorInput, getHandler } from "../handler";
import { handleNHNotificationCallActivityInput } from "../../HandleNHNotificationCallActivity/handler";
import { nhNotificationOrchestratorInput, getHandler } from "../handler";
import { success } from "../../utils/activity";

import { envConfig } from "../../__mocks__/env-config.mock";
Expand All @@ -32,7 +31,7 @@ const callNHServiceActivitySuccessResult = success();

describe("HandleNHNotificationCallOrchestrator", () => {
it("should start the activities with the right inputs", async () => {
const nhCallOrchestratorInput = NhNotificationOrchestratorInput.encode({
const nhCallOrchestratorInput = nhNotificationOrchestratorInput.encode({
message: aNotificationHubMessage
});

Expand All @@ -53,7 +52,7 @@ describe("HandleNHNotificationCallOrchestrator", () => {
expect(contextMockWithDf.df.callActivityWithRetry).toBeCalledWith(
"HandleNHNotificationCallActivity",
retryOptions,
HandleNHNotificationCallActivityInput.encode({
handleNHNotificationCallActivityInput.encode({
message: aNotificationHubMessage,
notificationHubConfig: {
AZURE_NH_ENDPOINT: envConfig.AZURE_NH_ENDPOINT,
Expand Down
10 changes: 5 additions & 5 deletions HandleNHNotificationCallOrchestrator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import * as t from "io-ts";

import { readableReport } from "italia-ts-commons/lib/reporters";

import { NotificationMessage } from "../HandleNHNotificationCall/handler";
import { notificationMessage } from "../HandleNHNotificationCall/handler";
import { HandleNHNotificationCallActivityInput } from "../HandleNHNotificationCallActivity/handler";
import { IConfig } from "../utils/config";
import { getNHLegacyConfig } from "../utils/notificationhubServicePartition";

/**
* Carries information about Notification Hub Message payload
*/
export const NhNotificationOrchestratorInput = t.interface({
message: NotificationMessage
export const nhNotificationOrchestratorInput = t.interface({
message: notificationMessage
});

export type NhNotificationOrchestratorInput = t.TypeOf<
typeof NhNotificationOrchestratorInput
typeof nhNotificationOrchestratorInput
>;

export const getHandler = (envConfig: IConfig) =>
Expand All @@ -33,7 +33,7 @@ export const getHandler = (envConfig: IConfig) =>

// Get and decode orchestrator input
const input = context.df.getInput();
const errorOrNHCallOrchestratorInput = NhNotificationOrchestratorInput.decode(
const errorOrNHCallOrchestratorInput = nhNotificationOrchestratorInput.decode(
input
);

Expand Down
6 changes: 3 additions & 3 deletions Info/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fromLeft, taskEither } from "fp-ts/lib/TaskEither";
import { HealthCheck, HealthProblem } from "../../utils/healthcheck";
import { InfoHandler } from "../handler";
import { infoHandler } from "../handler";

afterEach(() => {
jest.clearAllMocks();
Expand All @@ -12,7 +12,7 @@ describe("InfoHandler", () => {
"failure 1" as HealthProblem<"Config">,
"failure 2" as HealthProblem<"Config">
]);
const handler = InfoHandler(healthCheck);
const handler = infoHandler(healthCheck);

const response = await handler();

Expand All @@ -21,7 +21,7 @@ describe("InfoHandler", () => {

it("should return a success if the application is healthy", async () => {
const healthCheck: HealthCheck = taskEither.of(true);
const handler = InfoHandler(healthCheck);
const handler = infoHandler(healthCheck);

const response = await handler();

Expand Down
Loading