Skip to content

Commit 4f6e77f

Browse files
committed
refactor: explicit number casting
1 parent c1a0bb1 commit 4f6e77f

File tree

20 files changed

+54
-48
lines changed

20 files changed

+54
-48
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ module.exports = {
8585
ignoreCase: true,
8686
}],
8787
'multiline-ternary': 'off',
88+
'no-implicit-coercion': ['error', { boolean: false }],
8889

8990
'sonarjs/cognitive-complexity': 'off',
9091
'sonarjs/no-duplicate-string': 'off',

packages/docs/src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@
125125
document.body.append(copy)
126126
127127
;(copy.querySelectorAll('[data-scroll-x], [data-scroll-y]') as NodeListOf<HTMLElement>).forEach(el => {
128-
el.scrollLeft = +el.dataset.scrollX!
129-
el.scrollTop = +el.dataset.scrollY!
128+
el.scrollLeft = Number(el.dataset.scrollX)
129+
el.scrollTop = Number(el.dataset.scrollY)
130130
})
131131
132132
function onTransitionend (e: TransitionEvent) {

packages/vuetify/src/components/VBadge/VBadge.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ export const VBadge = genericComponent<VBadgeSlots>()({
7373
: (props.dot ? 8 : 12)
7474

7575
return base + (
76-
['top', 'bottom'].includes(side) ? +(props.offsetY ?? 0)
77-
: ['left', 'right'].includes(side) ? +(props.offsetX ?? 0)
76+
['top', 'bottom'].includes(side) ? Number(props.offsetY ?? 0)
77+
: ['left', 'right'].includes(side) ? Number(props.offsetX ?? 0)
7878
: 0
7979
)
8080
})
8181

8282
useRender(() => {
8383
const value = Number(props.content)
8484
const content = (!props.max || isNaN(value)) ? props.content
85-
: value <= +props.max ? value
85+
: value <= Number(props.max) ? value
8686
: `${props.max}+`
8787

8888
const [badgeAttrs, attrs] = pickWithRest(ctx.attrs as Record<string, any>, [

packages/vuetify/src/components/VCarousel/VCarousel.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ export const VCarousel = genericComponent<new <T>(
9494
function startTimeout () {
9595
if (!props.cycle || !windowRef.value) return
9696

97-
slideTimeout = window.setTimeout(windowRef.value.group.next, +props.interval > 0 ? +props.interval : 6000)
97+
slideTimeout = window.setTimeout(
98+
windowRef.value.group.next,
99+
Number(props.interval) > 0 ? Number(props.interval) : 6000
100+
)
98101
}
99102

100103
function restartTimeout () {

packages/vuetify/src/components/VDataTable/composables/headers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ function parseFixedColumns (items: InternalDataTableHeader[]) {
115115
} else {
116116
if (!seenFixed) {
117117
item.lastFixed = true
118-
} else if (isNaN(+item.width!)) {
118+
} else if (isNaN(Number(item.width))) {
119119
consoleError(`Multiple fixed columns should have a static width (key: ${item.key})`)
120120
} else {
121-
item.minWidth = Math.max(+item.width! || 0, +item.minWidth! || 0)
121+
item.minWidth = Math.max(Number(item.width) || 0, Number(item.minWidth) || 0)
122122
}
123123
seenFixed = true
124124
}

packages/vuetify/src/components/VDataTable/composables/paginate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ type PaginationProps = {
4343
}
4444

4545
export function createPagination (props: PaginationProps) {
46-
const page = useProxiedModel(props, 'page', undefined, value => +(value ?? 1))
47-
const itemsPerPage = useProxiedModel(props, 'itemsPerPage', undefined, value => +(value ?? 10))
46+
const page = useProxiedModel(props, 'page', undefined, value => Number(value ?? 1))
47+
const itemsPerPage = useProxiedModel(props, 'itemsPerPage', undefined, value => Number(value ?? 10))
4848

4949
return { page, itemsPerPage }
5050
}

packages/vuetify/src/components/VPagination/VPagination.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export const VPagination = genericComponent<VPaginationSlots>()({
183183
const minButtons = props.showFirstLastPage ? 5 : 3
184184
return Math.max(0, Math.floor(
185185
// Round to two decimal places to avoid floating point errors
186-
+((totalWidth - itemWidth * minButtons) / itemWidth).toFixed(2)
186+
Number(((totalWidth - itemWidth * minButtons) / itemWidth).toFixed(2))
187187
))
188188
}
189189

@@ -262,7 +262,7 @@ export const VPagination = genericComponent<VPaginationSlots>()({
262262
ref,
263263
ellipsis: false,
264264
icon: true,
265-
disabled: !!props.disabled || +props.length < 2,
265+
disabled: !!props.disabled || Number(props.length) < 2,
266266
color: isActive ? props.activeColor : props.color,
267267
'aria-current': isActive,
268268
'aria-label': t(isActive ? props.currentPageAriaLabel : props.pageAriaLabel, item),
@@ -315,7 +315,7 @@ export const VPagination = genericComponent<VPaginationSlots>()({
315315
}
316316

317317
function onKeydown (e: KeyboardEvent) {
318-
if (e.key === keyValues.left && !props.disabled && page.value > +props.start) {
318+
if (e.key === keyValues.left && !props.disabled && page.value > Number(props.start)) {
319319
page.value = page.value - 1
320320
nextTick(updateFocus)
321321
} else if (e.key === keyValues.right && !props.disabled && page.value < start.value + length.value - 1) {

packages/vuetify/src/components/VParallax/VParallax.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const VParallax = genericComponent<VImgSlots>()({
6666
watch(() => contentRect.value?.height, onScroll)
6767

6868
const scale = computed(() => {
69-
return 1 - clamp(+props.scale)
69+
return 1 - clamp(Number(props.scale))
7070
})
7171

7272
let frame = -1

packages/vuetify/src/components/VRating/VRating.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const VRating = genericComponent<VRatingSlots>()({
101101
const { t } = useLocale()
102102
const { themeClasses } = provideTheme(props)
103103
const rating = useProxiedModel(props, 'modelValue')
104-
const normalizedValue = computed(() => clamp(parseFloat(rating.value), 0, +props.length))
104+
const normalizedValue = computed(() => clamp(parseFloat(rating.value), 0, Number(props.length)))
105105

106106
const range = computed(() => createRange(Number(props.length), 1))
107107
const increments = computed(() => range.value.flatMap(v => props.halfIncrements ? [v - 0.5, v] : [v]))

packages/vuetify/src/components/VSlider/slider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ type SliderData = {
149149
export const useSteps = (props: SliderProps) => {
150150
const min = computed(() => parseFloat(props.min))
151151
const max = computed(() => parseFloat(props.max))
152-
const step = computed(() => +props.step > 0 ? parseFloat(props.step) : 0)
152+
const step = computed(() => Number(props.step) > 0 ? parseFloat(props.step) : 0)
153153
const decimals = computed(() => Math.max(getDecimals(step.value), getDecimals(min.value)))
154154

155155
function roundValue (value: string | number) {

0 commit comments

Comments
 (0)