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

refactor: eslint prettier husky configs & allias on imports #276

Merged
merged 7 commits into from
Dec 18, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Deploy Documentation
on:
push:
branches: ["main", "2.*"]
branches: ['main', '2.*']
paths:
- website/**

Expand All @@ -16,7 +16,7 @@ permissions:
id-token: write

concurrency:
group: "pages"
group: 'pages'
cancel-in-progress: false

jobs:
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn test && yarn lint-staged
11 changes: 4 additions & 7 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 80,
"tabWidth": 2,
"jsxSingleQuote": false,
"jsxBracketSameLine": false,
"arrowParens": "always",
"endOfLine": "lf"
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"importOrder": ["^react$", "^@/(.*)$", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
4 changes: 2 additions & 2 deletions build/remote-env.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ log.blue(`MFE manage env for remote (micro-frontend)`)

const nameOfMfeEnv = 'swEnv.js'
const entryScriptPath = path.resolve(
`${process.cwd()}/dist/assets/${process.argv[2]}`
`${process.cwd()}/dist/assets/${process.argv[2]}`,
)
const swEnvScriptPath = path.resolve(`${process.cwd()}/dist/${nameOfMfeEnv}`)

Expand All @@ -27,6 +27,6 @@ if (isSwEnvScriptExists && isEntryScriptExists) {
log.green(`✓ Added env file inside ${entryScriptPath}`)
} else {
log.red(
`x Nothing to do. Are you using vite-envs and federation plugin in your configuration vite.config.ts ?`
`x Nothing to do. Are you using vite-envs and federation plugin in your configuration vite.config.ts ?`,
)
}
53 changes: 34 additions & 19 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
import js from '@eslint/js'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import globals from 'globals'
import pluginJs from '@eslint/js'
import tseslint from 'typescript-eslint'
import pluginReact from 'eslint-plugin-react'
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'

export default [
{ files: ['**/*.{js,mjs,cjs,ts,jsx,tsx}'] },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
pluginReact.configs.flat['jsx-runtime'],
eslintPluginPrettierRecommended,
export default tseslint.config(
{
settings: { react: { version: '18.3' } },
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
},
ignores: ['dist', 'src/vite-env.d.ts'],
},
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['src/**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: {
...globals.browser,
...globals.worker,
importScripts: 'readonly',
workbox: 'readonly',
},
parserOptions: {
project: './tsconfig.json',
},
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
// see https://typescript-eslint.netlify.app/rules/no-unused-vars/
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' },
],
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-namespace': ['off'],
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
)
40 changes: 20 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="Collecte de questionnaire en face à face"
/>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<meta name="msapplication-TileColor" content="#3e69b1" />
<meta name="theme-color" content="#ffffff" />

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Collecte de questionnaire en face à face" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<meta name="msapplication-TileColor" content="#3e69b1">
<meta name="theme-color" content="#ffffff">
<title>Questionnaire enquêteur</title>
</head>


<title>Questionnaire enquêteur</title>
</head>

<body>
<div id="drama-queen"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

</html>
<body>
<div id="drama-queen"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
33 changes: 22 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
"type": "module",
"scripts": {
"dev": "vite --port 5001 --strictPort",
"test": "vitest",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest --coverage",
"build": "tsc && vite build",
"postbuild": "node build/remote-env.cjs remoteEntry.js",
"preview": "vite preview --port 5001 --strictPort",
"_format": "prettier 'src/**/*.{ts,tsx,js,jsx,json,md}'",
"_format": "prettier --ignore-unknown .",
"format": "npm run _format -- --write",
"lint": "eslint src/",
"format:check": "npm run _format -- --list-different",
"stop": "kill-port --port 5000,5001,5002"
"lint": "eslint ./src",
"stop": "kill-port --port 5000,5001,5002",
"prepare": "husky"
},
"dependencies": {
"@emotion/react": "^11.11.4",
Expand All @@ -41,31 +43,40 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@eslint/js": "^9.16.0",
"@originjs/vite-plugin-federation": "^1.2.3",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
"@eslint/js": "^9.13.0",
"@trivago/prettier-plugin-sort-imports": "^5.2.0",
"@types/node": "^20.16.10",
"@types/react": "^18.3.10",
"@types/react-dom": "^18.2.22",
"@vitejs/plugin-react": "^4.3.2",
"@vitest/coverage-v8": "^2.1.3",
"jsdom": "^25.0.1",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint": "^9.16.0",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.11.0",
"husky": "^9.1.7",
"jsdom": "^25.0.1",
"kill-port": "^2.0.1",
"lint-staged": "^15.2.11",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"typescript-eslint": "^8.11.0",
"typescript-eslint": "^8.18.0",
"vite": "^5.4.8",
"vite-envs": "^4.4.5",
"vite-plugin-pwa": "^0.19.8",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.1.3"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix",
"prettier --write --list-different"
],
"!(*.js|*.jsx|*.ts|*.tsx)": "prettier --write --ignore-unknown --list-different"
}
}
11 changes: 6 additions & 5 deletions src/bootstrap.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createRoot } from 'react-dom/client'
import { RouterProvider } from 'react-router-dom'
import { unsubscribeOldSW } from 'unsubscribe_old_sw'
import { CoreProvider } from 'createCore'
import { createRouter, type RoutingStrategy } from 'ui/routing/createRouter'
import { CenteredSpinner } from 'ui/components/CenteredSpinner'

import { CoreProvider } from '@/createCore'
import { CenteredSpinner } from '@/ui/components/CenteredSpinner'
import { type RoutingStrategy, createRouter } from '@/ui/routing/createRouter'
import { unsubscribeOldSW } from '@/unsubscribe_old_sw'

const mount = ({
mountPoint,
Expand All @@ -24,7 +25,7 @@ const mount = ({
root.render(
<CoreProvider fallback={<CenteredSpinner />}>
<RouterProvider router={router} />
</CoreProvider>
</CoreProvider>,
)

return () => queueMicrotask(() => root.unmount())
Expand Down
5 changes: 3 additions & 2 deletions src/core/adapters/datastore/default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Paradata, SurveyUnit } from 'core/model'
import type { DataStore } from 'core/ports/DataStore'
import Dexie, { type Table } from 'dexie'

import type { Paradata, SurveyUnit } from '@/core/model'
import type { DataStore } from '@/core/ports/DataStore'

type Tables = {
surveyUnit: Table<SurveyUnit, string>
paradata: Table<Paradata>
Expand Down
3 changes: 2 additions & 1 deletion src/core/adapters/localSyncStorage/default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {
LocalStorageObject,
LocalSyncStorage,
} from 'core/ports/LocalSyncStorage'
} from '@/core/ports/LocalSyncStorage'

import { localStorageObjectSchema } from './parser/localSyncObjectSchema'

export function createLocalSyncStorage(params: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, it } from 'vitest'

import { localStorageObjectSchema } from './localSyncObjectSchema'

describe('localStorageObjectSchema', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { LocalStorageObject } from 'core/ports/LocalSyncStorage'
import { type Equals, assert } from 'tsafe'
import { z } from 'zod'

import type { LocalStorageObject } from '@/core/ports/LocalSyncStorage'

export const localStorageObjectSchema = z.object({
error: z.boolean(),
surveyUnitsSuccess: z.array(z.string()),
Expand Down
4 changes: 3 additions & 1 deletion src/core/adapters/oidc/default.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Oidc } from 'core/ports/Oidc'
import { createOidc as createOidcSpa } from 'oidc-spa'

import type { Oidc } from '@/core/ports/Oidc'

import { getMockedOidc } from './mock'

export function createOidc(params: {
Expand Down
3 changes: 2 additions & 1 deletion src/core/adapters/oidc/mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Oidc } from 'core/ports/Oidc'
import { id } from 'tsafe/id'

import type { Oidc } from '@/core/ports/Oidc'

export function createOidc(params: {
isUserLoggedIn: boolean
}): () => Promise<Oidc> {
Expand Down
16 changes: 9 additions & 7 deletions src/core/adapters/queenApi/default.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import axios, { AxiosError } from 'axios'

import type {
Campaign,
IdAndQuestionnaireId,
Nomenclature,
Questionnaire,
RequiredNomenclatures,
SurveyUnit,
} from 'core/model'
import type { QueenApi } from 'core/ports/QueenApi'
import { handleAxiosError } from 'core/tools/axiosError'
} from '@/core/model'
import type { QueenApi } from '@/core/ports/QueenApi'
import { handleAxiosError } from '@/core/tools/axiosError'

import {
campaignSchema,
idAndQuestionnaireIdSchema,
Expand Down Expand Up @@ -50,7 +52,7 @@ export function createApiClient(params: {
return Promise.reject(error)
}
return Promise.reject(handleAxiosError(error))
}
},
)
return { axiosInstance }
})()
Expand All @@ -65,14 +67,14 @@ export function createApiClient(params: {
axiosInstance
.get<SurveyUnit[]>(`/api/survey-units/interviewer`)
.then(({ data }) =>
data.map((surveyUnit) => surveyUnitSchema.parse(surveyUnit))
data.map((surveyUnit) => surveyUnitSchema.parse(surveyUnit)),
),

getSurveyUnit: (idSurveyUnit) =>
axiosInstance
.get<Omit<SurveyUnit, 'id'>>(`/api/survey-unit/${idSurveyUnit}`)
.then(({ data }) =>
surveyUnitSchema.parse({ id: idSurveyUnit, ...data })
surveyUnitSchema.parse({ id: idSurveyUnit, ...data }),
),
putSurveyUnit: (surveyUnit) =>
axiosInstance
Expand Down Expand Up @@ -100,7 +102,7 @@ export function createApiClient(params: {
getRequiredNomenclaturesByCampaign: (idNomenclature) =>
axiosInstance
.get<RequiredNomenclatures>(
`/api/questionnaire/${idNomenclature}/required-nomenclatures`
`/api/questionnaire/${idNomenclature}/required-nomenclatures`,
)
.then(({ data }) => requiredNomenclaturesSchema.parse(data)),

Expand Down
9 changes: 5 additions & 4 deletions src/core/adapters/queenApi/mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { QueenApi } from 'core/ports/QueenApi'
import type { SurveyUnit } from '@/core/model'
import type { QueenApi } from '@/core/ports/QueenApi'

import { surveySample } from './mockData/surveySample'
import type { SurveyUnit } from 'core/model'

export function createApiClient(): QueenApi {
return {
Expand All @@ -15,13 +16,13 @@ export function createApiClient(): QueenApi {
Promise.resolve(createSUMocked({ idSu: idSurveyUnit })),
putSurveyUnit: (surveyUnit) =>
Promise.resolve(
console.log('putSurveyUnit', `id: ${surveyUnit.id}`, surveyUnit)
console.log('putSurveyUnit', `id: ${surveyUnit.id}`, surveyUnit),
),
putSurveyUnitsData: (surveyUnitsData) =>
Promise.resolve(console.table(surveyUnitsData)),
postSurveyUnitInTemp: (surveyUnit) =>
Promise.resolve(
console.log('postSurveyUnitInTemp', `id: ${surveyUnit.id}`, surveyUnit)
console.log('postSurveyUnitInTemp', `id: ${surveyUnit.id}`, surveyUnit),
),
getCampaigns: () =>
Promise.resolve([
Expand Down
2 changes: 1 addition & 1 deletion src/core/adapters/queenApi/mockData/surveySample.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Questionnaire } from 'core/model/Questionnaire'
import type { Questionnaire } from '@/core/model/Questionnaire'

export const surveySample = {
componentType: 'Questionnaire',
Expand Down
Loading
Loading