Skip to content
Snippets Groups Projects
Commit 1f7a5a32 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

chore(lint): enable more rules & fix exhaustive switch cases

parent 603dbe6f
No related branches found
No related tags found
1 merge request!1248chore(lint): enable more rules & fix exhaustive switch cases
......@@ -31,6 +31,12 @@ module.exports = {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/default-param-last': 'error',
'@typescript-eslint/prefer-for-of': 'warn',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
// causes a build error and has a lot of effects on components
'@typescript-eslint/prefer-nullish-coalescing': 'off',
......
......@@ -112,6 +112,8 @@ const FluidChart = ({ fluidType }: { fluidType: FluidType }) => {
case FluidType.WATER:
dispatch(setShowOfflineData(false))
break
default:
throw new Error('Unexpected fluid type')
}
}
......
......@@ -18,16 +18,21 @@ const Loader = ({ color = 'gold', fluidType, text }: LoaderProps) => {
const { t } = useI18n()
let variant = color
switch (fluidType) {
case FluidType.ELECTRICITY:
variant = 'elec'
break
case FluidType.GAS:
variant = 'gaz'
break
case FluidType.WATER:
variant = 'water'
break
if (fluidType !== undefined) {
switch (fluidType) {
case FluidType.ELECTRICITY:
variant = 'elec'
break
case FluidType.GAS:
variant = 'gaz'
break
case FluidType.WATER:
variant = 'water'
break
case FluidType.MULTIFLUID:
variant = 'gold'
break
}
}
return (
......
......@@ -7,6 +7,7 @@ import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
import { FluidType } from 'enums'
import React from 'react'
import { getFluidLabel } from 'utils/utils'
import './partnerIssueModal.scss'
interface PartnerIssueModalProps {
......@@ -22,17 +23,6 @@ const PartnerIssueModal = ({
}: PartnerIssueModalProps) => {
const { t } = useI18n()
const getFluidTypeLabel = () => {
switch (issuedFluid) {
case FluidType.ELECTRICITY:
return 'elec'
case FluidType.WATER:
return 'water'
case FluidType.GAS:
return 'gaz'
}
}
return (
<Dialog
open={open}
......@@ -66,7 +56,9 @@ const PartnerIssueModal = ({
className="partner-issue-content text-16-normal"
dangerouslySetInnerHTML={{
__html: t(
`consumption.partner_issue_modal.error_connect_${getFluidTypeLabel()}`
`consumption.partner_issue_modal.error_connect_${getFluidLabel(
issuedFluid
)}`
),
}}
/>
......
......@@ -167,6 +167,8 @@ export async function migrate(
}
switch (result.type) {
case MIGRATION_RESULT_FAILED:
throw new Error('Migration failed')
case MIGRATION_RESULT_NOOP:
case MIGRATION_RESULT_COMPLETE:
await updateSchemaVersion(_client, migration.targetSchemaVersion)
......
......@@ -250,6 +250,8 @@ export default class QueryRunner {
},
}
break
case TimeStep.HOUR:
throw new Error('Unexpected time step')
}
return predicate
}
......
......@@ -347,6 +347,10 @@ export default class QuizService {
let endTime = today
const isPeriod = Object.keys(period).length !== 0
switch (interval) {
case TimeStep.HALF_AN_HOUR:
case TimeStep.HOUR:
case TimeStep.DAY:
throw new Error('Unexpected time step')
case TimeStep.WEEK:
startTime = isPeriod
? DateTime.fromObject(period).startOf('week')
......
......@@ -13,6 +13,7 @@ import {
formatOffPeakHours,
formatTwoDigits,
getChallengeTitleWithLineReturn,
getFluidLabel,
getFluidName,
getFluidTypeTranslation,
getFluidUnit,
......@@ -262,6 +263,21 @@ describe('utils test', () => {
})
})
describe('getFluidLabel', () => {
it('should return elec', () => {
expect(getFluidLabel(FluidType.ELECTRICITY)).toBe('elec')
})
it('should return gas', () => {
expect(getFluidLabel(FluidType.GAS)).toBe('gaz')
})
it('should return water', () => {
expect(getFluidLabel(FluidType.WATER)).toBe('water')
})
it('should return multi', () => {
expect(getFluidLabel(FluidType.MULTIFLUID)).toBe('multi')
})
})
describe('formatListWithAnd', () => {
it('should return empty string', () => {
expect(formatListWithAnd([])).toBe('')
......
......@@ -64,6 +64,19 @@ export const getPartnerKey = (fluidType: FluidType) => {
}
}
export const getFluidLabel = (fluidType: FluidType) => {
switch (fluidType) {
case FluidType.ELECTRICITY:
return 'elec'
case FluidType.GAS:
return 'gaz'
case FluidType.WATER:
return 'water'
case FluidType.MULTIFLUID:
return 'multi'
}
}
export function getKonnectorUpdateError(type: string) {
switch (type.toUpperCase()) {
case 'USER_ACTION_NEEDED.OAUTH_OUTDATED':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment