Skip to content

Commit

Permalink
[#IP-402] Migrated tslint to eslint (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldisaro authored Sep 24, 2021
1 parent 5ef4bc2 commit 3594563
Show file tree
Hide file tree
Showing 82 changed files with 1,311 additions and 309 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"ignorePatterns": [
"node_modules",
"generated",
"**/__tests__/*",
"**/__mocks__/*",
"Dangerfile.*",
"*.d.ts",
"docker"
],
"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,3 +50,7 @@ coverage

yarn-error.log
generated/**/*

# eslint section
!.eslintrc.js
.eslintcache
2 changes: 1 addition & 1 deletion AbortUserDataProcessing/__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 {
UserDataProcessingStatus,
Expand Down
3 changes: 3 additions & 0 deletions AbortUserDataProcessing/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ type IAbortUserDataProcessingHandler = (
choice: UserDataProcessingChoice
) => Promise<IAbortUserDataProcessingHandlerResult>;

// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function AbortUserDataProcessingHandler(
userDataProcessingModel: UserDataProcessingModel
): IAbortUserDataProcessingHandler {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
return async (_, fiscalCode, choice) => {
const id = makeUserDataProcessingId(choice, fiscalCode);

Expand Down Expand Up @@ -136,6 +138,7 @@ export function AbortUserDataProcessingHandler(
/**
* Wraps an AbortUserDataProcessingDelete handler inside an Express request handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function AbortUserDataProcessing(
userDataProcessingModel: UserDataProcessingModel
): express.RequestHandler {
Expand Down
1 change: 1 addition & 0 deletions AbortUserDataProcessing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ app.delete(
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
4 changes: 2 additions & 2 deletions CreateProfile/__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 lolex from "lolex";

Expand All @@ -21,7 +21,7 @@ import {
import { OrchestratorInput as UpsertedProfileOrchestratorInput } from "../../UpsertedProfileOrchestratorV2/handler";
import { CreateProfileHandler } from "../handler";

// tslint:disable-next-line: no-let
// eslint-disable-next-line functional/no-let
let clock: any;
beforeEach(() => {
(df.getClient as any).mockClear();
Expand Down
3 changes: 3 additions & 0 deletions CreateProfile/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ type ICreateProfileHandler = (
| IResponseErrorConflict
>;

// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function CreateProfileHandler(
profileModel: ProfileModel,
optOutEmailSwitchDate: Date
): ICreateProfileHandler {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
return async (context, fiscalCode, createProfilePayload) => {
const logPrefix = `CreateProfileHandler|FISCAL_CODE=${fiscalCode}`;

Expand Down Expand Up @@ -121,6 +123,7 @@ export function CreateProfileHandler(
/**
* Wraps an CreateProfile handler inside an Express request handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function CreateProfile(
profileModel: ProfileModel,
optOutEmailSwitchDate: Date
Expand Down
1 change: 1 addition & 0 deletions CreateProfile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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
4 changes: 2 additions & 2 deletions CreateValidationTokenActivity/__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 lolex from "lolex";

Expand All @@ -17,7 +17,7 @@ import {
getCreateValidationTokenActivityHandler
} from "../handler";

// tslint:disable-next-line: no-let
// eslint-disable-next-line functional/no-let
let clock: any;
beforeEach(() => {
// We need to mock time to test token expiration.
Expand Down
1 change: 1 addition & 0 deletions CreateValidationTokenActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const getCreateValidationTokenActivityHandler = (
tokenInvalidAfterMS: Millisecond,
randomBytesGenerator: (size: number) => string,
hashCreator: (value: string) => string
// eslint-disable-next-line max-params
) => async (context: Context, input: unknown): Promise<unknown> => {
const logPrefix = `CreateValidationTokenActivity`;

Expand Down
3 changes: 1 addition & 2 deletions CreateValidationTokenActivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { Millisecond } from "@pagopa/ts-commons/lib/units";
import { VALIDATION_TOKEN_TABLE_NAME } from "@pagopa/io-functions-commons/dist/src/entities/validation_token";
import { ulidGenerator } from "@pagopa/io-functions-commons/dist/src/utils/strings";

import { getCreateValidationTokenActivityHandler } from "./handler";

import { getConfigOrThrow } from "../utils/config";
import { randomBytes, toHash } from "../utils/crypto";
import { getCreateValidationTokenActivityHandler } from "./handler";

const config = getConfigOrThrow();

Expand Down
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 "danger-plugin-digitalcitizenship";

checkDangers();
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 { context as contextMock } from "../../__mocks__/durable-functions";
import {
Expand Down
2 changes: 1 addition & 1 deletion EmailValidationProcessOrchestrator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const handler = function*(
const logPrefix = `EmailValidationProcessOrchestrator`;

const retryOptions = new df.RetryOptions(5000, 10);
// tslint:disable-next-line: no-object-mutation
// eslint-disable-next-line functional/immutable-data
retryOptions.backoffCoefficient = 1.5;

context.log.verbose(`${logPrefix}|Email validation process started`);
Expand Down
5 changes: 2 additions & 3 deletions EnqueueProfileCreationEventActivity/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe("GetEnqueueProfileCreationEventActivityHandler", () => {
mockQueueService
);
mockSendMessage.mockImplementation(() => Promise.resolve());
// tslint:disable-next-line: no-unused-expression
const result = await handler((context as unknown) as Context, {
fiscalCode: aFiscalCode,
queueName: aQueueName
Expand All @@ -46,7 +45,7 @@ describe("GetEnqueueProfileCreationEventActivityHandler", () => {
mockQueueService
);
mockSendMessage.mockImplementation(() => Promise.resolve());
// tslint:disable-next-line: no-unused-expression
// eslint-disable-next-line no-new, no-unused-expressions
const result = await handler((context as unknown) as Context, {
fiscalCode: aFiscalCode
});
Expand All @@ -62,7 +61,7 @@ describe("GetEnqueueProfileCreationEventActivityHandler", () => {
mockSendMessage.mockImplementationOnce(() =>
Promise.reject(new Error("Error"))
);
// tslint:disable-next-line: no-unused-expression
// eslint-disable-next-line no-new, no-unused-expressions
await expect(
handler((context as unknown) as Context, {
fiscalCode: aFiscalCode,
Expand Down
2 changes: 1 addition & 1 deletion GetMessage/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tslint:disable:no-any no-duplicate-string no-big-function
// eslint-disable @typescript-eslint/no-explicit-any, sonarjs/no-duplicate-string, sonar/sonar-max-lines-per-function

import { none, some } from "fp-ts/lib/Option";

Expand Down
4 changes: 3 additions & 1 deletion GetMessage/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type IGetMessageHandler = (
fiscalCode: FiscalCode,
messageId: string
) => Promise<
// tslint:disable-next-line:max-union-size
| IResponseSuccessJson<
MessageResponseWithContent | MessageResponseWithoutContent
>
Expand All @@ -65,10 +64,12 @@ type IGetMessageHandler = (
/**
* Handles requests for getting a single message for a recipient.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function GetMessageHandler(
messageModel: MessageModel,
blobService: BlobService
): IGetMessageHandler {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
return async (context, fiscalCode, messageId) => {
const [errorOrMaybeDocument, errorOrMaybeContent] = await Promise.all([
messageModel.findMessageForRecipient(
Expand Down Expand Up @@ -128,6 +129,7 @@ export function GetMessageHandler(
/**
* Wraps a GetMessage handler inside an Express request handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function GetMessage(
messageModel: MessageModel,
blobService: BlobService
Expand Down
4 changes: 2 additions & 2 deletions GetMessage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import { createBlobService } from "azure-storage";
import createAzureFunctionHandler from "@pagopa/express-azure-functions/dist/src/createAzureFunctionsHandler";

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

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

// Setup Express
const app = express();
Expand All @@ -40,6 +39,7 @@ app.get(
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
2 changes: 1 addition & 1 deletion GetMessages/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tslint:disable:no-any no-duplicate-string no-big-function
// eslint-disable @typescript-eslint/no-explicit-any, sonarjs/no-duplicate-string, sonar/sonar-max-lines-per-function

import * as E from "fp-ts/lib/Either";
import * as O from "fp-ts/lib/Option";
Expand Down
11 changes: 6 additions & 5 deletions GetMessages/handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// tslint:disable: ordered-imports
// eslint-disable-next-line prettier/prettier

import {
asyncIteratorToPageArray,
flattenAsyncIterator,
Expand Down Expand Up @@ -89,7 +90,7 @@ export const GetMessagesHandler = (
maybeEnrichResultData,
maybeMaximumId,
maybeMinimumId
) =>
): Promise<IGetMessagesHandlerResponse> =>
pipe(
TE.Do,
TE.bind("pageSize", () =>
Expand Down Expand Up @@ -159,11 +160,11 @@ export const GetMessagesHandler = (
/**
* Wraps a GetMessages handler inside an Express request handler.
*/
export function GetMessages(
export const GetMessages = (
messageModel: MessageModel,
serviceModel: ServiceModel,
blobService: BlobService
): express.RequestHandler {
): express.RequestHandler => {
const handler = GetMessagesHandler(messageModel, serviceModel, blobService);
const middlewaresWrap = withRequestMiddlewares(
FiscalCodeMiddleware,
Expand All @@ -173,4 +174,4 @@ export function GetMessages(
OptionalQueryParamMiddleware("minimum_id", NonEmptyString)
);
return wrapRequestHandler(middlewaresWrap(handler));
}
};
9 changes: 4 additions & 5 deletions GetMessages/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// tslint:disable: ordered-imports
import { Context } from "@azure/functions";

import * as express from "express";
Expand All @@ -13,15 +12,14 @@ import {

import createAzureFunctionHandler from "@pagopa/express-azure-functions/dist/src/createAzureFunctionsHandler";

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

import { getConfigOrThrow } from "../utils/config";
import {
ServiceModel,
SERVICE_COLLECTION_NAME
} from "@pagopa/io-functions-commons/dist/src/models/service";
import { createBlobService } from "azure-storage";
import { cosmosdbInstance } from "../utils/cosmosdb";
import { getConfigOrThrow } from "../utils/config";
import { GetMessages } from "./handler";

// Setup Express
const app = express();
Expand All @@ -48,6 +46,7 @@ app.get(
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
2 changes: 1 addition & 1 deletion GetProfile/__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 { none, some } from "fp-ts/lib/Option";
import * as TE from "fp-ts/lib/TaskEither";
Expand Down
4 changes: 4 additions & 0 deletions GetProfile/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ type IGetProfileHandler = (
/**
* Return a type safe GetProfile handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function GetProfileHandler(
profileModel: ProfileModel,
optOutEmailSwitchDate: Date,
isOptInEmailEnabled: boolean
): IGetProfileHandler {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, arrow-body-style
return async fiscalCode => {
return pipe(
profileModel.findLastVersionByModelId([fiscalCode]),
Expand All @@ -64,6 +66,7 @@ export function GetProfileHandler(
// this map is valid for ever so this check cannot be removed.
// Please note that cosmos timestamps are expressed in unix notation (in seconds), so we must transform
// it to a common Date representation.
// eslint-disable-next-line no-underscore-dangle
isOptInEmailEnabled && isBefore(_._ts, optOutEmailSwitchDate)
? { ..._, isEmailEnabled: false }
: _
Expand All @@ -87,6 +90,7 @@ export function GetProfileHandler(
/**
* Wraps a GetProfile handler inside an Express request handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function GetProfile(
profileModel: ProfileModel,
optOutEmailSwitchDate: Date,
Expand Down
1 change: 1 addition & 0 deletions GetProfile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ app.get(
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
2 changes: 1 addition & 1 deletion GetService/__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 { none, some } from "fp-ts/lib/Option";
import * as TE from "fp-ts/lib/TaskEither";

Expand Down
Loading

0 comments on commit 3594563

Please sign in to comment.