Expected a default case
260 const filterListExclude: JSX.Element[] = []
261
262 for (const [i, filter] of Object.entries(form.values)) {
263 switch (filter.filterType) {264 case 'INCLUDE': {265 filterListInclude.push(266 <Checkbox267 // className={classes.itemChild}268 label={t(filter.tsKey, { ns: 'attribute' })}269 key={filter.id}270 {...form.getInputProps(`${i}.checked`, { type: 'checkbox' })}271 />272 )273 break274 }275 case 'EXCLUDE': {276 filterListExclude.push(277 <Checkbox278 className={classes.itemChild}279 label={t(filter.tsKey, { ns: 'attribute' })}280 key={filter.id}281 {...form.getInputProps(`${i}.checked`, { type: 'checkbox' })}282 />283 )284 break285 }286 }287 }
288
289 const selectedItems = (function () {
Expected a default case
41 if (typeof onClick === 'function') return onClick(e)
42
43 if (option === 'back') {
44 switch (backTo) { 45 case 'search': { 46 if (searchParams) { 47 const { searchState } = searchParams 48 if (searchState) 49 router.push({ 50 pathname: '/search/[...params]', 51 query: searchState, 52 }) 53 } 54 break 55 } 56 case 'dynamicText': { 57 if (router.pathname.startsWith('/org/[slug]/[orgLocationId]')) { 58 const { orgLocationId, slug } = router.query 59 if (isString(slug, orgLocationId)) { 60 router.push({ 61 pathname: router.pathname.endsWith('/edit') ? '/org/[slug]/edit' : '/org/[slug]', 62 query: { slug }, 63 }) 64 } 65 } 66 } 67 } 68 }
69 }
70
Expected a default case
96
97 useEffect(
98 () => {
99 switch (true) {100 case !compare(searchParams.searchState.a, filteredAttributes) &&101 !compare(searchParams.searchState.s, filteredServices): {102 routeActions.setSearchState({103 ...searchParams.searchState,104 a: filteredAttributes,105 s: filteredServices,106 })107 break108 }109 case !compare(searchParams.searchState.a, filteredAttributes): {110 routeActions.setAttributes(filteredAttributes)111 break112 }113114 case !compare(searchParams.searchState.s, filteredServices): {115 routeActions.setServices(filteredServices)116 break117 }118 }119 },
120 // eslint-disable-next-line react-hooks/exhaustive-deps
121 [filteredAttributes, filteredServices]
Description
Some code conventions require that all switch statements have a default case, even if the default case is empty. The idea is to always explicitly state what the default behavior should be so that it's clear that the developer didn't forget to handle the default fallback case.
Bad Practice
switch (a) {
case 1:
/* code */
break;
}
Recommended
switch (a) {
case 1:
/* code */
break;
default:
/* code */
break;
}
switch (a) {
case 1:
/* code */
break;
// no default
}
switch (a) {
case 1:
/* code */
break;
// No Default
}