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

fix(frontend): amélioration des linters, correction d'un bug sur Safari #2938

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prepare": "husky install"
},
"devDependencies": {
"@commitlint/cli": "^17.2.0",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.2.0",
"@socialgouv/sre-secrets": "^1.13.9",
"husky": "^8.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
"plugin:promise/recommended"
],
"root": true,
"rules": {
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.29.0",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.0.0",
"jest": "^29.3.1",
"lint-staged": "^14.0.0",
"nodemon": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ async function resetUsagers(structure: StructureLight): Promise<void> {
}

async function deleteStructureDocuments(structure: StructureLight) {
const structureDocsPath = join(
domifaConfig().upload.basePath,
"structure-documents",
`${structure.id}`
);
await rm(structureDocsPath, {
recursive: true,
force: true,
maxRetries: 2,
});

const oldUsagerFolder = join(
domifaConfig().upload.basePath,
`${structure.id}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class UsagerDocsController {
file: Express.Multer.File,
callback: (error: Error | null, destination: string) => void
) => {
return callback(null, randomName(file));
callback(null, randomName(file));
},
}),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class UsagerStructureDocsController {
structureId: user.structureId,
docPath: doc.path,
});

return res.status(HttpStatus.OK).sendFile(output);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ export function buildCustomDoc({
extraParameters?: { [name: string]: string };
}): StructureCustomDocTags {
// Adresse courrier active
const isDifferentAddress =
structure.adresseCourrier !== null && structure.adresseCourrier?.actif;
const isDifferentAddress = structure.adresseCourrier?.actif;
// Adresse
let adresseStructure = ucFirst(structure.adresse);

Expand Down
10 changes: 9 additions & 1 deletion packages/backend/src/users/dto/user-edit.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { ApiProperty } from "@nestjs/swagger";
import { Transform, TransformFnParams } from "class-transformer";
import { IsEmail, IsNotEmpty, MaxLength, MinLength } from "class-validator";
import {
IsEmail,
IsNotEmpty,
IsString,
MaxLength,
MinLength,
} from "class-validator";

export class UserEditDto {
@ApiProperty({
Expand All @@ -10,6 +16,7 @@ export class UserEditDto {
@MinLength(2)
@MaxLength(100)
@IsNotEmpty()
@IsString()
@Transform(({ value }: TransformFnParams) => {
return value.toString().trim();
})
Expand All @@ -22,6 +29,7 @@ export class UserEditDto {
@MinLength(2)
@MaxLength(100)
@IsNotEmpty()
@IsString()
@Transform(({ value }: TransformFnParams) => {
return value.toString().trim();
})
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/users/dto/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
IsEmail,
IsEmpty,
IsNotEmpty,
IsString,
MaxLength,
MinLength,
} from "class-validator";
Expand All @@ -13,6 +14,7 @@ export class UserDto {
@MinLength(2)
@MaxLength(100)
@IsNotEmpty()
@IsString()
@Transform(({ value }: TransformFnParams) => {
return value.toString().trim();
})
Expand All @@ -21,6 +23,7 @@ export class UserDto {
@MinLength(2)
@MaxLength(100)
@IsNotEmpty()
@IsString()
@Transform(({ value }: TransformFnParams) => {
return value.toString().trim();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function sendExcelWorkbook({
await workbook.xlsx
.write(res)
.then(() => {
res.end();
return res.end();
})
.catch((err) => {
appLogger.error("Unexpected export error", err);
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"plugin:@typescript-eslint/recommended",
"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates",
"plugin:prettier/recommended" // <--- here we inherit from the recommended setup from eslint-plugin-prettier for TS
"plugin:no-lookahead-lookbehind-regexp/recommended",
"prettier"
],
"rules": {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
"eslint-config-standard-with-typescript": "^39.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-no-lookahead-lookbehind-regexp": "^0.3.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.0.0",
"jest": "^29.3.1",
"jest-preset-angular": "^13.0.0",
"lint-staged": "^14.0.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/app/modules/shared/directives/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @index('./*.directive.ts', f => `export * from '${f.path}'`)
export * from "./clean-str.directive";
export * from "./date-fr.directive";
export * from "./str-caps-alpha.directive";
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { FormatBigNumberPipe } from "./format-big-number.pipe";

describe("FormatBigNumberPipe", () => {
let pipe: FormatBigNumberPipe;

beforeEach(() => {
pipe = new FormatBigNumberPipe();
});

it("should create an instance", () => {
expect(pipe).toBeTruthy();
});

it("should correctly format big numbers", () => {
expect(pipe.transform(1234567890)).toEqual("1 234 567 890");
expect(pipe.transform(100000)).toEqual("100 000");
});

it("should handle zero", () => {
expect(pipe.transform(0)).toEqual("0");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { Pipe, PipeTransform } from "@angular/core";
@Pipe({ name: "formatBigNumber" })
export class FormatBigNumberPipe implements PipeTransform {
public transform(nb: number): string {
return nb ? nb.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ") : "0";
let strNb = nb.toString();
const chunks = [];

while (strNb.length > 0) {
chunks.unshift(strNb.slice(-3));
strNb = strNb.slice(0, -3);
}

return chunks.join(" ");
}
}
4 changes: 2 additions & 2 deletions packages/frontend/src/app/modules/shared/pipes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./formatBigNumber.pipe";
// @index('./*.pipe.ts', f => `export * from '${f.path}'`)
export * from "./format-big-number.pipe";
export * from "./nl2br.pipe";
export * from "./usager-nom-complet.pipe";
17 changes: 11 additions & 6 deletions packages/frontend/src/app/modules/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { ReplaceLineBreaks } from "./pipes/nl2br.pipe";

import { CommonModule } from "@angular/common";
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from "@angular/core";
import {
FaIconLibrary,
FontAwesomeModule,
} from "@fortawesome/angular-fontawesome";
import { FA_ICONS } from "./constants/FA_ICONS.const";
import { CleanStrDirective } from "./directives/clean-str.directive";
import { DateFrDirective } from "./directives/date-fr.directive";

import { CustomToastrComponent } from "./components/custom-toastr/custom-toastr.component";
import { StrCapsAlphaDirective } from "./directives/str-caps-alpha.directive";
import { UsagerNomCompletPipe, FormatBigNumberPipe } from "./pipes";

import {
UsagerNomCompletPipe,
FormatBigNumberPipe,
ReplaceLineBreaks,
} from "./pipes";
import { DisplayTableImageComponent } from "./components/display-table-image/display-table-image.component";
import {
DateFrDirective,
CleanStrDirective,
StrCapsAlphaDirective,
} from "./directives";

@NgModule({
declarations: [
Expand Down
10 changes: 7 additions & 3 deletions packages/portail-admins/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
"createDefaultProgram": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@angular-eslint/recommended",
// This is required if you use inline templates in Components
"plugin:@angular-eslint/template/process-inline-templates"
"plugin:@angular-eslint/template/process-inline-templates",
"plugin:no-lookahead-lookbehind-regexp/recommended",
"prettier"
],
"rules": {
/**
Expand All @@ -32,7 +35,8 @@
"prefix": "app",
"style": "kebab-case"
}
]
],
"@typescript-eslint/no-explicit-any": "off"
}
},
{
Expand Down
7 changes: 4 additions & 3 deletions packages/portail-admins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@
"@types/node": "^20.3.3",
"@typescript-eslint/eslint-plugin": "6.5.0",
"@typescript-eslint/parser": "6.5.0",
"eslint": "^8.29.0",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-no-lookahead-lookbehind-regexp": "^0.3.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.3.1",
"jest-preset-angular": "^13.0.0",
Expand All @@ -76,7 +77,7 @@
"source-map-explorer": "^2.5.2",
"tslib": "^2.3.0",
"typescript": "~4.9.5",
"webpack-bundle-analyzer": "^4.4.2"
"webpack-bundle-analyzer": "^4.9.1"
},
"lint-staged": {
"*!(.ts)": "prettier --ignore-unknown -w",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { FormatBigNumberPipe } from "./format-big-number.pipe";

describe("FormatBigNumberPipe", () => {
let pipe: FormatBigNumberPipe;

beforeEach(() => {
pipe = new FormatBigNumberPipe();
});

it("should create an instance", () => {
expect(pipe).toBeTruthy();
});

it("should correctly format big numbers", () => {
expect(pipe.transform(1234567890)).toEqual("1 234 567 890");
expect(pipe.transform(100000)).toEqual("100 000");
});

it("should handle zero", () => {
expect(pipe.transform(0)).toEqual("0");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Pipe, PipeTransform } from "@angular/core";

@Pipe({ name: "formatBigNumber" })
export class FormatBigNumberPipe implements PipeTransform {
public transform(nb: number): string {
let strNb = nb.toString();
const chunks = [];

while (strNb.length > 0) {
chunks.unshift(strNb.slice(-3));
strNb = strNb.slice(0, -3);
}

return chunks.join(" ");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FormatPhoneNumberPipe } from "./format-phone-number.pipe";

describe("FormatPhoneNumberPipe", () => {
let pipe: FormatPhoneNumberPipe;

beforeEach(() => {
pipe = new FormatPhoneNumberPipe();
});

it("should format French mobile numbers correctly", () => {
expect(pipe.transform("+33612345678")).toBe("06 12 34 56 78");
expect(pipe.transform("0612345678")).toBe("06 12 34 56 78");
expect(pipe.transform("06.12.34.56.78")).toBe("06 12 34 56 78");
});

it("should format French landline numbers correctly", () => {
expect(pipe.transform("+33123456789")).toBe("01 23 45 67 89");
expect(pipe.transform("0123456789")).toBe("01 23 45 67 89");
expect(pipe.transform("01.23.45.67.89")).toBe("01 23 45 67 89");
});

// Cas limites
it("should handle edge cases", () => {
expect(pipe.transform("")).toBe("");
expect(pipe.transform("1234")).toBe("12 34");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Pipe, PipeTransform } from "@angular/core";

@Pipe({ name: "formatPhoneNumber" })
export class FormatPhoneNumberPipe implements PipeTransform {
public transform(phoneNumber: string): string {
if (!phoneNumber) return "";

phoneNumber = phoneNumber.replace(/^\+33/, "0").replace(/\./g, "").trim();

const chunks = [];
while (phoneNumber.length > 0) {
chunks.unshift(phoneNumber.slice(-2));
phoneNumber = phoneNumber.slice(0, -2);
}

return chunks.join(" ");
}
}

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions packages/portail-admins/src/app/modules/shared/pipes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @index('./*.pipe.ts', f => `export * from '${f.path}'`)
export * from "./admin-nom-complet.pipe";
export * from "./format-big-number.pipe";
export * from "./format-phone-number.pipe";
Loading
Loading