Skip to content

Commit

Permalink
Merge pull request #523 from mission-apprentissage/fix/lint-rework
Browse files Browse the repository at this point in the history
chore: remove prettier & enforce lint
  • Loading branch information
FaXaq authored Jan 7, 2025
2 parents 2b64117 + 9d70a24 commit b2a7988
Show file tree
Hide file tree
Showing 134 changed files with 2,438 additions and 2,464 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"plugins": ["react", "@typescript-eslint", "simple-import-sort", "import", "@dword-design/import-alias"],
"rules": {
"max-len": ["warn", { "code": 120 }],
"simple-import-sort/imports": "error",
"no-extra-semi": "error",
"semi": ["error", "always"],
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,3 @@ jobs:

- name: test
run: yarn test:ci

- name: prettier
run: yarn prettier:check
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"bierner.markdown-preview-github-styles",
"bierner.markdown-mermaid",
"christian-kohler.npm-intellisense",
"esbenp.prettier-vscode",
"yoavbls.pretty-ts-errors",
"pflannery.vscode-versionlens",
"vitest.explorer",
Expand Down
11 changes: 0 additions & 11 deletions docs/developpement/developpement.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
- [Opérations](#opérations)
- [Installation et Mise à jour des dépendences](#installation-et-mise-à-jour-des-dépendences)
- [Linter](#linter)
- [Prettier](#prettier)
- [Typescript](#typescript)
- [Arrêt des services](#arrêt-des-services)
- [Suppression des services](#suppression-des-services)
Expand Down Expand Up @@ -185,16 +184,6 @@ yarn lint

**Note:** eslint est run automatiquement à chaque commit

### Prettier

Prettier est mis en place dans le projet, pour le lancer :

```bash
yarn prettier:fix
```

**Note:** eslint est run automatiquement à chaque commit

### Typescript

L'application utilise TypeScript, pour vérifier que les erreurs liés au type veuillez lancer:
Expand Down
15 changes: 1 addition & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
"seed:update": ".bin/product seed:update",
"lint": "eslint --ignore-path .gitignore --cache --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "yarn lint --fix",
"prettier:fix": "prettier --write -u .",
"prettier:check": "prettier --check -u .",
"release": "semantic-release",
"release:interactive": ".bin/product release:interactive",
"release:manual": ".bin/product release:manual",
Expand Down Expand Up @@ -97,26 +95,15 @@
"exceljs": "^4.4.0",
"lint-staged": "^15.2.10",
"node-talisman": "^1.29.11",
"prettier": "^3.3.3",
"semantic-release": "22.0.12",
"semantic-release-slack-bot": "4.0.2",
"typescript": "^5.6.3",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^2.0.5"
},
"prettier": {
"printWidth": 120,
"bracketSpacing": true,
"trailingComma": "es5",
"arrowParens": "always"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --ignore-path .gitignore --cache --fix",
"prettier --write -u"
],
"*": [
"prettier --write -u"
"eslint --ignore-path .gitignore --cache --fix"
],
"yarn.lock": [
"yarn dedupe"
Expand Down
2 changes: 1 addition & 1 deletion server/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ program
.action(async () => {
console.log(path.join(__dirname(), "../src", "db/schema.ts"));
exec(
`DATABASE_URL="${config.psql.uri}" npx kysely-codegen --schema public --out-file=${path.join(__dirname(), "../src", "db/schema.ts")} --dialect postgres && yarn prettier:fix`
`DATABASE_URL="${config.psql.uri}" npx kysely-codegen --schema public --out-file=${path.join(__dirname(), "../src", "db/schema.ts")} --dialect postgres`
);
});

Expand Down
60 changes: 30 additions & 30 deletions server/src/modules/changelog/getChangelog/getChangelog.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,50 +146,50 @@ export const getChangelogFactory =
config,
}
) =>
async (dbId: string = deps.config.notion.dbChangelogId): Promise<Changelog> => {
const database = (await deps.getDatabaseRows(dbId)) as unknown as ChangelogDatabase;
const changelog: Changelog = [];
async (dbId: string = deps.config.notion.dbChangelogId): Promise<Changelog> => {
const database = (await deps.getDatabaseRows(dbId)) as unknown as ChangelogDatabase;
const changelog: Changelog = [];

database.results?.forEach((result) => {
const entry: Partial<ChangelogEntry> = {};
database.results?.forEach((result) => {
const entry: Partial<ChangelogEntry> = {};

entry.title = result.properties["Mise à jour"].title?.[0]?.plain_text ?? "";
entry.title = result.properties["Mise à jour"].title?.[0]?.plain_text ?? "";

if (!entry.title) {
return;
}
if (!entry.title) {
return;
}

entry.id = result.id;
entry.id = result.id;

entry.types =
entry.types =
result.properties.Type.multi_select?.map((type) => ({
label: type.name,
color: type.color,
})) ?? [];

entry.show = result.properties["A afficher"].checkbox;
entry.description = result.properties["Description"].rich_text?.[0]?.plain_text ?? "";
entry.deployed = result.properties["En Prod ?"].checkbox;
entry.show = result.properties["A afficher"].checkbox;
entry.description = result.properties["Description"].rich_text?.[0]?.plain_text ?? "";
entry.deployed = result.properties["En Prod ?"].checkbox;

if (result.properties.Date.type === "rich_text") {
entry.date = {
type: result.properties.Date.rich_text?.[0]?.type === "mention" ? "date" : "string",
value: result.properties.Date.rich_text?.[0]?.plain_text ?? "",
};
}
if (result.properties.Date.type === "rich_text") {
entry.date = {
type: result.properties.Date.rich_text?.[0]?.type === "mention" ? "date" : "string",
value: result.properties.Date.rich_text?.[0]?.plain_text ?? "",
};
}

changelog.push(entry as ChangelogEntry);
});
changelog.push(entry as ChangelogEntry);
});

changelog.sort((a, b) => {
if (a.date.type === "date" && b.date.type === "date") {
return new Date(b.date.value).getTime() - new Date(a.date.value).getTime();
}
changelog.sort((a, b) => {
if (a.date.type === "date" && b.date.type === "date") {
return new Date(b.date.value).getTime() - new Date(a.date.value).getTime();
}

return 0;
});
return 0;
});

return changelog;
};
return changelog;
};

export const getChangelog = getChangelogFactory();
24 changes: 12 additions & 12 deletions server/src/modules/core/services/notion/notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type CallbackFunction<K extends unknown[], T> = (...args: K) => Promise<T>;

const withNotionErrorHandling =
<K extends unknown[], T>(callback: CallbackFunction<K, T>) =>
async (...args: K): Promise<T> => {
try {
return await callback(...args);
} catch (error) {
if (isNotionClientError(error)) {
switch (error.code) {
async (...args: K): Promise<T> => {
try {
return await callback(...args);
} catch (error) {
if (isNotionClientError(error)) {
switch (error.code) {
case APIErrorCode.ObjectNotFound:
throw Boom.notFound("Base de donnée Notion introuvable");
case APIErrorCode.Unauthorized:
Expand All @@ -41,14 +41,14 @@ const withNotionErrorHandling =
error: error as Error,
...args,
});
}
}
}

throw Boom.badImplementation(
"Erreur lors de l'appel à Notion avec les parametres suivants " + JSON.stringify(args)
);
}
};
throw Boom.badImplementation(
"Erreur lors de l'appel à Notion avec les parametres suivants " + JSON.stringify(args)
);
}
};

const getDatabaseRowsFactory = (
deps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { getScopeFilterForUser } from "@/modules/core/utils/getScopeFilterForUse
export function canCreateUserInScope({ body, requestUser }: { body: BodySchema; requestUser: RequestUser }) {
const { scope, scopeFilter } = getScopeFilterForUser("users/ecriture", requestUser);
switch (scope) {
case "national":
return true;
case "region":
return body.codeRegion !== undefined && scopeFilter.includes(body.codeRegion);
default:
return false;
case "national":
return true;
case "region":
return body.codeRegion !== undefined && scopeFilter.includes(body.codeRegion);
default:
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { getScopeFilterForUser } from "@/modules/core/utils/getScopeFilterForUse
export function canEditUserInScope({ body, requestUser }: { body: BodySchema; requestUser: RequestUser }) {
const { scope, scopeFilter } = getScopeFilterForUser("users/ecriture", requestUser);
switch (scope) {
case "national":
return true;
case "region":
return body.codeRegion !== null && scopeFilter.includes(body.codeRegion);
default:
return false;
case "national":
return true;
case "region":
return body.codeRegion !== null && scopeFilter.includes(body.codeRegion);
default:
return false;
}
}
22 changes: 11 additions & 11 deletions server/src/modules/core/utils/getScopeFilterForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export const getScopeFilterForUser = (permission: Permission, user: RequestUser)
};

switch (scope) {
case "region":
if (user.codeRegion) {
scopeWithFilter.scopeFilter = [user.codeRegion];
}
break;
case "national":
case "uai":
case "role":
default:
scopeWithFilter.scopeFilter = [];
break;
case "region":
if (user.codeRegion) {
scopeWithFilter.scopeFilter = [user.codeRegion];
}
break;
case "national":
case "uai":
case "role":
default:
scopeWithFilter.scopeFilter = [];
break;
}

return scopeWithFilter;
Expand Down
16 changes: 8 additions & 8 deletions server/src/modules/core/utils/hasPermission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import type { Permission } from "shared/security/permissions";

export const hasPermissionHandler =
<P extends Permission>(permission: P) =>
(request: FastifyRequestType, _reply: FastifyReplyType, done: HookHandlerDoneFunction) => {
if (!request.user) throw Boom.unauthorized();
if (!request.user.role) throw Boom.forbidden();
if (!hasPermission(request.user.role, permission)) {
throw Boom.forbidden();
}
done();
};
(request: FastifyRequestType, _reply: FastifyReplyType, done: HookHandlerDoneFunction) => {
if (!request.user) throw Boom.unauthorized();
if (!request.user.role) throw Boom.forbidden();
if (!hasPermission(request.user.role, permission)) {
throw Boom.forbidden();
}
done();
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@ const getCorrectionsFactory =
getFiltersQuery,
}
) =>
async (activeFilters: ActiveFilters) => {
const campagne = await deps.getCurrentCampagneQuery();
const anneeCampagne = activeFilters?.campagne ?? campagne.annee;
const [stats, { count, corrections }, filters] = await Promise.all([
deps.getStatsCorrectionsQuery({
...activeFilters,
campagne: anneeCampagne,
}),
deps.getCorrectionsQuery({
...activeFilters,
campagne: anneeCampagne,
}),
deps.getFiltersQuery({
...activeFilters,
campagne: anneeCampagne,
}),
]);
async (activeFilters: ActiveFilters) => {
const campagne = await deps.getCurrentCampagneQuery();
const anneeCampagne = activeFilters?.campagne ?? campagne.annee;
const [stats, { count, corrections }, filters] = await Promise.all([
deps.getStatsCorrectionsQuery({
...activeFilters,
campagne: anneeCampagne,
}),
deps.getCorrectionsQuery({
...activeFilters,
campagne: anneeCampagne,
}),
deps.getFiltersQuery({
...activeFilters,
campagne: anneeCampagne,
}),
]);

return {
corrections,
count,
stats,
filters,
return {
corrections,
count,
stats,
filters,
};
};
};

export const getCorrectionsUsecase = getCorrectionsFactory();
Loading

0 comments on commit b2a7988

Please sign in to comment.