✅ Code style improvments, to pass SonarCloud review
This commit is contained in:
@@ -28,7 +28,7 @@ export default {
|
||||
/* Number of days worth of history to fetch and display */
|
||||
numDays() {
|
||||
const userChoice = this.options.numDays;
|
||||
if (!Number.isNaN(userChoice) && userChoice < 30 && userChoice > 0.15) {
|
||||
if (typeof usersChoice === 'number' && userChoice < 30 && userChoice > 0.15) {
|
||||
return userChoice;
|
||||
}
|
||||
return 7;
|
||||
@@ -42,7 +42,7 @@ export default {
|
||||
/* The number of data points to render on the chart */
|
||||
dataPoints() {
|
||||
const userChoice = this.options.dataPoints;
|
||||
if (!Number.isNaN(userChoice) && userChoice < 100 && userChoice > 5) {
|
||||
if (typeof usersChoice === 'number' && userChoice < 100 && userChoice > 5) {
|
||||
return userChoice;
|
||||
}
|
||||
return 30;
|
||||
|
||||
@@ -141,8 +141,8 @@ export default {
|
||||
return 'fg-grey';
|
||||
},
|
||||
makeScoreColor(inputScore) {
|
||||
if (!inputScore || Number.isNaN(parseFloat(inputScore, 10))) return 'bg-grey';
|
||||
const score = parseFloat(inputScore, 10);
|
||||
if (!inputScore || Number.isNaN(parseFloat(inputScore))) return 'bg-grey';
|
||||
const score = parseFloat(inputScore);
|
||||
if (score >= 9) return 'bg-red';
|
||||
if (score >= 7) return 'bg-orange';
|
||||
if (score >= 4) return 'bg-yellow';
|
||||
|
||||
@@ -36,7 +36,7 @@ export default {
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.eventListener) {
|
||||
document.removeEventListener(this.eventListener);
|
||||
window.removeEventListener(this.eventListener);
|
||||
}
|
||||
},
|
||||
data: () => ({
|
||||
|
||||
@@ -148,7 +148,6 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
.repo-stats {}
|
||||
&:not(:last-child) {
|
||||
border-bottom: 1px dashed var(--widget-text-color);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export default {
|
||||
},
|
||||
count() {
|
||||
const usersChoice = this.options.count;
|
||||
if (usersChoice && !Number.isNaN(usersChoice)) return usersChoice;
|
||||
if (usersChoice && typeof usersChoice === 'number') return usersChoice;
|
||||
return 10;
|
||||
},
|
||||
endpoint() {
|
||||
|
||||
@@ -80,8 +80,7 @@ export default {
|
||||
formatDate(timestamp) {
|
||||
const localFormat = navigator.language;
|
||||
const dateFormat = { weekday: 'short', day: 'numeric', month: 'short' };
|
||||
const date = new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
||||
return date;
|
||||
return new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
||||
},
|
||||
formatAuthor(author) {
|
||||
return author ? `by ${author}` : '';
|
||||
@@ -162,7 +161,6 @@ export default {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-decoration: none;
|
||||
.post-title-wrap {}
|
||||
p.post-title {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
|
||||
@@ -40,7 +40,7 @@ export default {
|
||||
/* The number of data points to render on the chart */
|
||||
dataPoints() {
|
||||
const userChoice = this.options.dataPoints;
|
||||
if (!Number.isNaN(userChoice) && userChoice < 100 && userChoice > 5) {
|
||||
if (typeof usersChoice === 'number' && userChoice < 100 && userChoice > 5) {
|
||||
return userChoice;
|
||||
}
|
||||
return 30;
|
||||
@@ -137,8 +137,7 @@ export default {
|
||||
formatDate(timestamp) {
|
||||
const localFormat = navigator.language;
|
||||
const dateFormat = { weekday: 'short', day: 'numeric', month: 'short' };
|
||||
const date = new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
||||
return date;
|
||||
return new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
||||
},
|
||||
/* Format the price, rounding to given number of decimal places */
|
||||
formatPrice(priceStr) {
|
||||
|
||||
@@ -320,7 +320,7 @@ export default {
|
||||
/* Returns either `false` or a number in ms to continuously update widget data */
|
||||
updateInterval() {
|
||||
const usersInterval = this.widget.updateInterval;
|
||||
if (!usersInterval) return false;
|
||||
if (!usersInterval) return 0;
|
||||
// If set to `true`, then default to 30 seconds
|
||||
if (typeof usersInterval === 'boolean') return 30 * 1000;
|
||||
// If set to a number, and within valid range, return user choice
|
||||
@@ -329,7 +329,7 @@ export default {
|
||||
&& usersInterval < 7200) {
|
||||
return usersInterval * 1000;
|
||||
}
|
||||
return false;
|
||||
return 0;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<template>
|
||||
<div class="widget-error"></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: 'WidgetError',
|
||||
props: {
|
||||
errorMessage: String,
|
||||
},
|
||||
computed: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.widget-error {}
|
||||
</style>
|
||||
@@ -31,10 +31,8 @@ export default {
|
||||
return 'latest';
|
||||
} else if (usersChoice === 'random') {
|
||||
return Math.abs(Math.floor(Math.random() * (1 - 2553)));
|
||||
} else if (usersChoice) {
|
||||
return usersChoice;
|
||||
}
|
||||
return 'latest';
|
||||
return usersChoice;
|
||||
},
|
||||
endpoint() {
|
||||
return `${widgetApiEndpoints.xkcdComic}?comic=${this.comicNumber}`;
|
||||
|
||||
Reference in New Issue
Block a user