Skip to content

Commit

Permalink
feat: enable ESLint and Prettier on the CI (#261)
Browse files Browse the repository at this point in the history
* feat: enable ESLint

* fix: prettier (js file) conf for windows

please add  `"files.eol": "\n"` to your user setttings.json for vs-code

---------

Co-authored-by: Laurent Caouissin <[email protected]>
  • Loading branch information
EmmanuelDemey and laurentC35 authored Oct 31, 2024
1 parent 353cdc8 commit 3f8bc94
Show file tree
Hide file tree
Showing 19 changed files with 2,123 additions and 1,536 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: yarn
- run: npx lerna run format
- run: npx lerna run lint
- run: yarn build
- uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion drama-queen/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"tabWidth": 2,
"jsxSingleQuote": false,
"jsxBracketSameLine": false,
"arrowParens": "always"
"arrowParens": "always",
"endOfLine": "lf"
}
30 changes: 30 additions & 0 deletions drama-queen/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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,
{
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',
},
languageOptions: {
globals: {
importScripts: 'readonly',
workbox: 'readonly',
},
},
},
]
10 changes: 9 additions & 1 deletion drama-queen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"build": "tsc && vite build",
"postbuild": "node build/remote-env.cjs remoteEntry.js",
"preview": "vite preview --port 5001 --strictPort",
"_format": "prettier '**/*.{ts,tsx,json,md}'",
"_format": "prettier 'src/**/*.{ts,tsx,js,jsx,json,md}'",
"format": "npm run _format -- --write",
"lint": "eslint src/",
"format:check": "npm run _format -- --list-different"
},
"dependencies": {
Expand Down Expand Up @@ -42,15 +43,22 @@
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
"@eslint/js": "^9.13.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",
"globals": "^15.11.0",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.8",
"vite-envs": "^4.4.5",
"vite-plugin-pwa": "^0.19.8",
Expand Down
18 changes: 9 additions & 9 deletions drama-queen/src/core/adapters/queenApi/default.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import axios, { Axios, AxiosError } from 'axios'
import type { QueenApi } from 'core/ports/QueenApi'
import {
campaignSchema,
idAndQuestionnaireIdSchema,
nomenclatureSchema,
requiredNomenclaturesSchema,
surveyUnitSchema,
} from './parserSchema'
import axios, { AxiosError } from 'axios'
import type {
Campaign,
IdAndQuestionnaireId,
Expand All @@ -15,7 +7,15 @@ import type {
RequiredNomenclatures,
SurveyUnit,
} from 'core/model'
import type { QueenApi } from 'core/ports/QueenApi'
import { handleAxiosError } from 'core/tools/axiosError'
import {
campaignSchema,
idAndQuestionnaireIdSchema,
nomenclatureSchema,
requiredNomenclaturesSchema,
surveyUnitSchema,
} from './parserSchema'

export function createApiClient(params: {
apiUrl: string
Expand Down
4 changes: 2 additions & 2 deletions drama-queen/src/core/adapters/queenApi/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { SurveyUnit } from 'core/model'

export function createApiClient(): QueenApi {
return {
getSurveyUnitsIdsAndQuestionnaireIdsByCampaign: (_idCampaign) =>
getSurveyUnitsIdsAndQuestionnaireIdsByCampaign: () =>
Promise.resolve([{ id: 'id', questionnaireId: 'questionnaireId' }]),
getSurveyUnits: () =>
Promise.resolve([
Expand All @@ -30,7 +30,7 @@ export function createApiClient(): QueenApi {
questionnaireIds: ['questionnaireIds'],
},
]),
getQuestionnaire: (_idSurvey) => Promise.resolve(surveySample),
getQuestionnaire: () => Promise.resolve(surveySample),
getRequiredNomenclaturesByCampaign: () => Promise.resolve([]),
getNomenclature: (idNomenclature) =>
Promise.resolve([{ id: `${idNomenclature}`, label: 'label' }]),
Expand Down
2 changes: 1 addition & 1 deletion drama-queen/src/core/usecases/synchronizeData/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export const thunks = {
}
dispatch(actions.uploadCompleted())
dispatch(thunks.download())
} catch (error) {
} catch {
localSyncStorage.addError(true)
dispatch(actions.uploadError())
}
Expand Down
6 changes: 1 addition & 5 deletions drama-queen/src/queen-service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ const getDramaQueenUrlRegex = (url) => {
.concat('/(.*)((.js)|(.png)|(.svg)|(.css))')
}

const getDramaQueenUrlRegexJson = (url) => {
return url.replace('http', '^http').concat('/(.*)(.json)')
}

const getQuestionnaireUrlRegex = () => '^http.*/api/questionnaire/(.){1,}'

const getResourceUrlRegex = () => '^http.*/api/nomenclature/(.){1,}'
Expand Down Expand Up @@ -98,6 +94,6 @@ self.addEventListener('install', (event) => {
event.waitUntil(dramaPrecacheController())
})

self.addEventListener('activate', (event) => {
self.addEventListener('activate', () => {
console.log('Drama Queen sw : activating ...')
})
2 changes: 1 addition & 1 deletion drama-queen/src/ui/components/appVersion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const AppVersion = () => {
)
}

const useStyles = tss.create(({}) => ({
const useStyles = tss.create(() => ({
footer: {
backgroundColor: '#f5f5f5',
borderTop: '1px solid black',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type BreadCrumbProps = {
}

export function BreadCrumb(props: BreadCrumbProps) {
const { sequence, subSequence, iteration, goToPage } = props
const { sequence, subSequence, goToPage } = props
const { classes, cx } = useStyles()
const { t } = useTranslation('navigationMessage')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function StopNavigation(props: StopNavigationProps) {
)
}

const useStyles = tss.create(({ theme }) => ({
const useStyles = tss.create(() => ({
navigationContainer: { gap: '1.5em' },
typography: {
lineHeight: '1.5em',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export function SubSequenceNavigation(props: subSequenceNavigationProps) {
)
}

const useStyles = tss.create(({}) => ({
const useStyles = tss.create(() => ({
navigationContainer: { gap: '1.5em' },
}))
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function ShortCut(props: ShortCutProps) {
key={shortCutKey}
keyName={shortCutKey}
onKeyDown={handleShortCut}
filter={(event) => true}
filter={() => true}
></ReactHotkeys>
)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import ArrowRightAltIcon from '@mui/icons-material/ArrowRightAlt'
import SkipNext from '@mui/icons-material/SkipNext'
import { SHORTCUT_FAST_FORWARD, SHORTCUT_NEXT } from 'ui/constants'
import type { GoNextPage, GoPreviousPage, GoToPage } from '../lunaticType'
import { getTranslation } from 'i18n'
import type { PageTag } from 'core/model'
import { SHORTCUT_NEXT } from 'ui/constants'
import type { GoNextPage, GoPreviousPage } from '../lunaticType'

const { t } = getTranslation('navigationMessage')

Expand Down
1 change: 0 additions & 1 deletion drama-queen/src/ui/routing/createRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export function createRouter({
strategy = 'memory',
initialPathname = '/',
}: CreateRouterProps) {

if (strategy === 'browser') {
return createBrowserRouter(routes, { basename: '/queen' })
}
Expand Down
1 change: 0 additions & 1 deletion drama-queen/src/ui/routing/loader/protectedLoader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { prCore } from 'createCore'
import type { LoaderFunctionArgs } from 'react-router-dom'

export async function protectedRouteLoader() {
const { userAuthentication } = (await prCore).functions
Expand Down
5 changes: 1 addition & 4 deletions drama-queen/src/ui/routing/loader/surveyUnitLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { prCore } from 'createCore'
import { redirect, type LoaderFunctionArgs } from 'react-router-dom'
import { assert } from 'tsafe'

export async function surveyUnitLoader({
request,
params,
}: LoaderFunctionArgs) {
export async function surveyUnitLoader({ params }: LoaderFunctionArgs) {
const { collectSurvey } = (await prCore).functions

const { surveyUnitId } = params
Expand Down
1 change: 1 addition & 0 deletions drama-queen/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

type ImportMetaEnv = {
// Auto-generated by `npx vite-envs update-types` and hot-reloaded by the `vite-env` plugin
// You probably want to add `/src/vite-env.d.ts` to your .prettierignore
VITE_QUEEN_API_URL: string
VITE_EXTERNAL_RESOURCES_URL: string
VITE_OIDC_ISSUER: string
Expand Down
Loading

0 comments on commit 3f8bc94

Please sign in to comment.