Skip to content

Commit

Permalink
[#IP-86] tslint to eslint migration (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldisaro committed Apr 9, 2021
1 parent 3d6b1ce commit 1246c3d
Show file tree
Hide file tree
Showing 70 changed files with 1,597 additions and 364 deletions.
26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 @@ -49,3 +49,7 @@ generated
docker*
azure-functions-core-tools/**/*


# eslint section
!.eslintrc.js
.eslintcache
4 changes: 2 additions & 2 deletions CreateMessage/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* tslint:disable: no-any */
/* eslint-disable @typescript-eslint/no-explicit-any */

import * as fc from "fast-check";

Expand Down Expand Up @@ -214,7 +214,7 @@ describe("forkOrchestrator", () => {
};
const getDfClient = jest.fn(() => mockDfClient);
const response = await forkOrchestrator(
// tslint:disable-next-line: no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getDfClient as any,
newMessage.content,
service,
Expand Down
24 changes: 18 additions & 6 deletions CreateMessage/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ import {
import { NonEmptyString } from "italia-ts-commons/lib/strings";
import { PromiseType } from "italia-ts-commons/lib/types";

// eslint-disable-next-line @typescript-eslint/naming-convention
const ApiNewMessageWithDefaults = t.intersection([
ApiNewMessage,
// eslint-disable-next-line @typescript-eslint/naming-convention
t.interface({ time_to_live: TimeToLiveSeconds })
]);
export type ApiNewMessageWithDefaults = t.TypeOf<
Expand All @@ -89,17 +91,18 @@ export type ApiNewMessageWithDefaults = t.TypeOf<
/**
* A request middleware that validates the Message payload.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export const MessagePayloadMiddleware: IRequestMiddleware<
"IResponseErrorValidation",
ApiNewMessageWithDefaults
> = request =>
new Promise(resolve => {
return resolve(
new Promise(resolve =>
resolve(
ApiNewMessageWithDefaults.decode(request.body).mapLeft(
ResponseErrorFromValidationErrors(ApiNewMessageWithDefaults)
)
);
});
)
);

/**
* Type of a CreateMessage handler.
Expand All @@ -117,7 +120,7 @@ type ICreateMessageHandler = (
messagePayload: ApiNewMessageWithDefaults,
maybeFiscalCode: Option<FiscalCode>
) => Promise<
// tslint:disable-next-line:max-union-size
// eslint-disable-next-line @typescript-eslint/ban-types
| IResponseSuccessRedirectToResource<Message, {}>
| IResponseErrorInternal
| IResponseErrorQuery
Expand Down Expand Up @@ -221,6 +224,7 @@ export const createMessageDocument = (
): TaskEither<
IResponseErrorInternal | IResponseErrorQuery,
NewMessageWithoutContent
// eslint-disable-next-line max-params
> => {
// create a new message from the payload
// this object contains only the message metadata, the content of the
Expand Down Expand Up @@ -298,7 +302,8 @@ export const forkOrchestrator = (

// queue the message to the created messages queue by setting
// the message to the output binding of this function
// tslint:disable-next-line:no-object-mutation
// eslint-disable-next-line functional/immutable-data
// eslint-disable-next-line extra-rules/no-commented-out-code
// context.bindings.createdMessage = createdMessageEventOrError.value;
const dfClient = getDfClient();
return tryCatch(
Expand All @@ -317,6 +322,7 @@ export const forkOrchestrator = (
*/
const redirectToNewMessage = (
newMessageWithoutContent: NewMessageWithoutContent
// eslint-disable-next-line @typescript-eslint/ban-types
): IResponseSuccessRedirectToResource<Message, {}> =>
ResponseSuccessRedirectToResource(
newMessageWithoutContent,
Expand All @@ -327,18 +333,21 @@ const redirectToNewMessage = (
/**
* Returns a type safe CreateMessage handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function CreateMessageHandler(
telemetryClient: ReturnType<typeof initAppInsights>,
messageModel: MessageModel,
generateObjectId: ObjectIdGenerator
): ICreateMessageHandler {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
return async (
context,
auth,
__,
userAttributes,
messagePayload,
maybeFiscalCodeInPath
// eslint-disable-next-line max-params
) => {
const maybeFiscalCodeInPayload = fromNullable(messagePayload.fiscal_code);

Expand Down Expand Up @@ -378,6 +387,7 @@ export function CreateMessageHandler(
properties: {
error: isSuccess ? undefined : r.kind,
hasDefaultEmail: Boolean(
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
messagePayload.default_addresses &&
messagePayload.default_addresses.email
).toString(),
Expand Down Expand Up @@ -464,6 +474,7 @@ export function CreateMessageHandler(
/**
* Wraps a CreateMessage handler inside an Express request handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function CreateMessage(
telemetryClient: ReturnType<typeof initAppInsights>,
serviceModel: ServiceModel,
Expand Down Expand Up @@ -492,6 +503,7 @@ export function CreateMessage(
);
return wrapRequestHandler(
middlewaresWrap(
// eslint-disable-next-line @typescript-eslint/naming-convention, max-params
checkSourceIpForHandler(handler, (_, __, c, u, ___, ____) =>
ipTuple(c, u)
)
Expand Down
5 changes: 3 additions & 2 deletions CreateMessage/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Context } from "@azure/functions";
import { cosmosdbInstance } from "../utils/cosmosdb";

import * as cors from "cors";
import * as express from "express";
Expand All @@ -18,10 +17,11 @@ import { setAppContext } from "@pagopa/io-functions-commons/dist/src/utils/middl
import createAzureFunctionHandler from "io-functions-express/dist/src/createAzureFunctionsHandler";

import { withAppInsightsContext } from "@pagopa/io-functions-commons/dist/src/utils/application_insights";
import { cosmosdbInstance } from "../utils/cosmosdb";
import { initTelemetryClient } from "../utils/appinsights";
import { CreateMessage } from "./handler";

import { getConfigOrThrow } from "../utils/config";
import { CreateMessage } from "./handler";

const config = getConfigOrThrow();

Expand Down Expand Up @@ -53,6 +53,7 @@ app.post(
const azureFunctionHandler = createAzureFunctionHandler(app);

// Binds the express app to an Azure Function handler
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
function httpStart(context: Context): void {
setAppContext(app, context);
withAppInsightsContext(context, () => azureFunctionHandler(context));
Expand Down
5 changes: 5 additions & 0 deletions CreateNotificationActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const getEmailAddressFromProfile = (
/**
* Try to create (save) a new notification
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
async function createNotification(
lNotificationModel: NotificationModel,
senderMetadata: CreatedMessageEventSenderMetadata,
Expand Down Expand Up @@ -73,6 +74,7 @@ async function createNotification(
};
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export const CreateNotificationActivityInput = t.interface({
createdMessageEvent: CreatedMessageEvent,
storeMessageContentActivityResult: SuccessfulStoreMessageContentActivityResult
Expand All @@ -82,6 +84,7 @@ export type CreateNotificationActivityInput = t.TypeOf<
typeof CreateNotificationActivityInput
>;

// eslint-disable-next-line @typescript-eslint/naming-convention
const CreateNotificationActivitySomeResult = t.interface({
hasEmail: t.boolean,
hasWebhook: t.boolean,
Expand All @@ -93,6 +96,7 @@ type CreateNotificationActivitySomeResult = t.TypeOf<
typeof CreateNotificationActivitySomeResult
>;

// eslint-disable-next-line @typescript-eslint/naming-convention
const CreateNotificationActivityNoneResult = t.interface({
kind: t.literal("none")
});
Expand All @@ -101,6 +105,7 @@ type CreateNotificationActivityNoneResult = t.TypeOf<
typeof CreateNotificationActivityNoneResult
>;

// eslint-disable-next-line @typescript-eslint/naming-convention
export const CreateNotificationActivityResult = t.taggedUnion("kind", [
CreateNotificationActivitySomeResult,
CreateNotificationActivityNoneResult
Expand Down
5 changes: 2 additions & 3 deletions CreateNotificationActivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* function app in Kudu
*/
import { AzureFunction } from "@azure/functions";
import { cosmosdbInstance } from "../utils/cosmosdb";

import { FiscalCode } from "@pagopa/io-functions-commons/dist/generated/definitions/FiscalCode";
import { HttpsUrl } from "@pagopa/io-functions-commons/dist/generated/definitions/HttpsUrl";
Expand All @@ -18,10 +17,10 @@ import {
NOTIFICATION_COLLECTION_NAME,
NotificationModel
} from "@pagopa/io-functions-commons/dist/src/models/notification";

import { getCreateNotificationActivityHandler } from "./handler";
import { cosmosdbInstance } from "../utils/cosmosdb";

import { getConfigOrThrow } from "../utils/config";
import { getCreateNotificationActivityHandler } from "./handler";

const config = getConfigOrThrow();

Expand Down
10 changes: 5 additions & 5 deletions CreateService/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* tslint:disable:no-any */
/* tslint:disable:no-duplicate-string */
/* tslint:disable:no-big-function */
/* tslint:disable: no-identical-functions */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable sonarjs/no-duplicate-string */
/* eslint-disable sonar/sonar-max-lines-per-function */
/* eslint-disable sonarjs/no-identical-functions */

import {
IAzureApiAuthorization,
Expand All @@ -28,7 +28,7 @@ import { ServicePayload } from "../../generated/definitions/ServicePayload";
import { CreateServiceHandler } from "../handler";

const mockContext = {
// tslint:disable: no-console
// eslint-disable no-console
log: {
error: console.error,
info: console.log
Expand Down
13 changes: 13 additions & 0 deletions CreateService/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ const createSubscriptionTask = (
() =>
apiClient.createSubscription({
body: {
// eslint-disable-next-line @typescript-eslint/naming-convention
product_name: productName
},
email: userEmail,
// eslint-disable-next-line @typescript-eslint/naming-convention
subscription_id: subscriptionId
}),
200
Expand All @@ -123,17 +125,22 @@ const createServiceTask = (
subscriptionId: NonEmptyString,
sandboxFiscalCode: FiscalCode,
adb2cTokenName: NonEmptyString
// eslint-disable-next-line max-params
): TaskEither<ErrorResponses, Service> =>
withApiRequestWrapper(
logger,
() =>
apiClient.createService({
body: {
...servicePayload,
// eslint-disable-next-line @typescript-eslint/naming-convention
authorized_recipients: [sandboxFiscalCode],
// eslint-disable-next-line @typescript-eslint/naming-convention
service_id: subscriptionId,
// eslint-disable-next-line @typescript-eslint/naming-convention
service_metadata: {
...servicePayload.service_metadata,
// eslint-disable-next-line @typescript-eslint/naming-convention
token_name: adb2cTokenName
}
}
Expand All @@ -144,13 +151,15 @@ const createServiceTask = (
/**
* Handles requests for create a service by a Service Payload.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function CreateServiceHandler(
telemetryClient: ReturnType<typeof initAppInsights>,
apiClient: APIClient,
generateObjectId: ObjectIdGenerator,
productName: NonEmptyString,
sandboxFiscalCode: NonEmptyString
): ICreateServiceHandler {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention
return (context, __, ___, userAttributes, servicePayload) => {
const subscriptionId = generateObjectId();
context.log.info(
Expand Down Expand Up @@ -187,7 +196,9 @@ export function CreateServiceHandler(
});
return ResponseSuccessJson({
...service,
// eslint-disable-next-line @typescript-eslint/naming-convention
primary_key: subscription.primary_key,
// eslint-disable-next-line @typescript-eslint/naming-convention
secondary_key: subscription.secondary_key
});
})
Expand All @@ -201,6 +212,7 @@ export function CreateServiceHandler(
/**
* Wraps a CreateService handler inside an Express request handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function CreateService(
telemetryClient: ReturnType<typeof initAppInsights>,
serviceModel: ServiceModel,
Expand All @@ -224,6 +236,7 @@ export function CreateService(
);
return wrapRequestHandler(
middlewaresWrap(
// eslint-disable-next-line @typescript-eslint/naming-convention
checkSourceIpForHandler(handler, (_, __, c, u, ___) => ipTuple(c, u))
)
);
Expand Down
5 changes: 3 additions & 2 deletions CreateService/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Context } from "@azure/functions";
import * as cors from "cors";
import * as express from "express";
import { cosmosdbInstance } from "../utils/cosmosdb";

import {
SERVICE_COLLECTION_NAME,
Expand All @@ -11,12 +10,13 @@ import { secureExpressApp } from "@pagopa/io-functions-commons/dist/src/utils/ex
import { setAppContext } from "@pagopa/io-functions-commons/dist/src/utils/middlewares/context_middleware";

import createAzureFunctionHandler from "io-functions-express/dist/src/createAzureFunctionsHandler";
import { cosmosdbInstance } from "../utils/cosmosdb";

import { apiClient } from "../clients/admin";
import { CreateService } from "./handler";

import { initTelemetryClient } from "../utils/appinsights";
import { getConfigOrThrow } from "../utils/config";
import { CreateService } from "./handler";

const config = getConfigOrThrow();

Expand Down Expand Up @@ -49,6 +49,7 @@ app.post(
const azureFunctionHandler = createAzureFunctionHandler(app);

// Binds the express app to an Azure Function handler
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
function httpStart(context: Context): void {
setAppContext(app, context);
azureFunctionHandler(context);
Expand Down
3 changes: 2 additions & 1 deletion CreatedMessageOrchestrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { MessageProcessingEventNames, trackMessageProcessing } from "./utils";
* See https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-checkpointing-and-replay
*
*/
// tslint:disable-next-line: cognitive-complexity no-big-function
// eslint-disable-next-line sonarjs/cognitive-complexity, max-lines-per-function
function* handler(context: IOrchestrationFunctionContext): Generator<unknown> {
const input = context.df.getInput();

Expand Down Expand Up @@ -70,6 +70,7 @@ function* handler(context: IOrchestrationFunctionContext): Generator<unknown> {

context.log.verbose(`${logPrefix}|Starting`);

// eslint-disable-next-line extra-rules/no-commented-out-code
// TODO: customize + backoff
// see https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-error-handling#javascript-functions-2x-only-1
const retryOptions = new df.RetryOptions(5000, 10);
Expand Down

0 comments on commit 1246c3d

Please sign in to comment.