From 4d0d3e3207637ca3b34fd28b3a92795959f91872 Mon Sep 17 00:00:00 2001 From: Matt Ray Date: Sat, 17 Jun 2023 12:51:46 +1000 Subject: [PATCH] eslint --fix automatic fixes and corrections to make eslint happier Signed-off-by: Matt Ray --- .../components/AllocationChart/RangeChart.js | 6 +++--- .../components/AllocationChart/SummaryChart.js | 4 ++-- .../src/components/AllocationReport.js | 10 +++++----- .../src/components/Controls/Download.js | 4 ++-- .../OpenCostReport/OpenCostReport.tsx | 12 +++++------- .../opencost/src/components/SelectWindow.js | 18 +++++++++--------- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/plugins/opencost/src/components/AllocationChart/RangeChart.js b/plugins/opencost/src/components/AllocationChart/RangeChart.js index bacb255daa..0c74cccbda 100644 --- a/plugins/opencost/src/components/AllocationChart/RangeChart.js +++ b/plugins/opencost/src/components/AllocationChart/RangeChart.js @@ -36,7 +36,7 @@ const useStyles = makeStyles({ }) function toBarLabels(allocationRange) { - let keyToFill = {} + const keyToFill = {} let p = 0 let g = 0 let b = 0 @@ -79,7 +79,7 @@ function toBarLabels(allocationRange) { } } - let labels = [] + const labels = [] for (const key in keyToFill) { labels.push({ dataKey: key, @@ -127,7 +127,7 @@ const RangeChart = ({ data, currency, height }) => { const CustomTooltip = (params) => { const { active, payload } = params - if (!payload || payload.length == 0) { + if (!payload || payload.length === 0) { return null } diff --git a/plugins/opencost/src/components/AllocationChart/SummaryChart.js b/plugins/opencost/src/components/AllocationChart/SummaryChart.js index e73359e857..7431c7984c 100644 --- a/plugins/opencost/src/components/AllocationChart/SummaryChart.js +++ b/plugins/opencost/src/components/AllocationChart/SummaryChart.js @@ -20,7 +20,7 @@ import { primary, greyscale, browns } from '../../constants/colors'; import { toCurrency } from '../../util'; function toPieData(top, other, idle) { - let slices = [] + const slices = [] for (const i in top) { const allocation = top[i] @@ -70,7 +70,7 @@ const SummaryChart = ({ top, other, idle, currency, height }) => { const radius = outerRadius * 1.1 let x = cx + radius * Math.cos(-midAngle * RADIAN) x += x > cx ? 2 : -2 - let y = cy + radius * Math.sin(-midAngle * RADIAN) + const y = cy + radius * Math.sin(-midAngle * RADIAN) // y -= Math.min(Math.abs(2 / Math.cos(-midAngle * RADIAN)), 8) if (percent < 0.02) { diff --git a/plugins/opencost/src/components/AllocationReport.js b/plugins/opencost/src/components/AllocationReport.js index 9aad66c901..79a0121858 100644 --- a/plugins/opencost/src/components/AllocationReport.js +++ b/plugins/opencost/src/components/AllocationReport.js @@ -145,7 +145,7 @@ const AllocationReport = ({ allocationData, cumulativeData, totalData, currency > {cell.numeric ? (cell.label === 'Efficiency' - ? (totalData.totalEfficiency == 1.0 && totalData.cpuReqCoreHrs == 0 && totalData.ramReqByteHrs == 0) + ? (totalData.totalEfficiency === 1.0 && totalData.cpuReqCoreHrs === 0 && totalData.ramReqByteHrs === 0) ? "Inf%" : `${round(totalData.totalEfficiency*100, 1)}%` : toCurrency(totalData[cell.id], currency)) @@ -158,13 +158,13 @@ const AllocationReport = ({ allocationData, cumulativeData, totalData, currency row.name = "Unmounted PVs" } - let isIdle = row.name.indexOf("__idle__") >= 0 - let isUnallocated = row.name.indexOf("__unallocated__") >= 0 - let isUnmounted = row.name.indexOf("Unmounted PVs") >= 0 + const isIdle = row.name.indexOf("__idle__") >= 0 + const isUnallocated = row.name.indexOf("__unallocated__") >= 0 + const isUnmounted = row.name.indexOf("Unmounted PVs") >= 0 // Replace "efficiency" with Inf if there is usage w/o request let efficiency = round(row.totalEfficiency*100, 1) - if (row.totalEfficiency == 1.0 && row.cpuReqCoreHrs == 0 && row.ramReqByteHrs == 0) { + if (row.totalEfficiency === 1.0 && row.cpuReqCoreHrs === 0 && row.ramReqByteHrs === 0) { efficiency = "Inf" } diff --git a/plugins/opencost/src/components/Controls/Download.js b/plugins/opencost/src/components/Controls/Download.js index 35493b927b..527940924a 100644 --- a/plugins/opencost/src/components/Controls/Download.js +++ b/plugins/opencost/src/components/Controls/Download.js @@ -57,7 +57,7 @@ const columns = [ ] const toCSVLine = (datum) => { - let cols = [] + const cols = [] forEach(columns, c => { if (c.currency) { @@ -84,7 +84,7 @@ const DownloadControl = ({ // Create download link const a = document.createElement("a") a.href = URL.createObjectURL(new Blob([csv], { type: "text/csv" })) - const filename = title.toLowerCase().replace(/\s/gi, '-') + const filename = title.toLocaleLowerCase('en-US').replace(/\s/gi, '-') a.setAttribute("download", `${filename}-${Date.now()}.csv`) // Click the link diff --git a/plugins/opencost/src/components/OpenCostReport/OpenCostReport.tsx b/plugins/opencost/src/components/OpenCostReport/OpenCostReport.tsx index e85c2ccae6..2e93e64d98 100644 --- a/plugins/opencost/src/components/OpenCostReport/OpenCostReport.tsx +++ b/plugins/opencost/src/components/OpenCostReport/OpenCostReport.tsx @@ -81,12 +81,14 @@ function generateTitle({ window, aggregateBy, accumulate }) { if (checkCustomWindow(window)) { windowName = toVerboseTimeRange(window) } else { + /* eslint no-console: ["error", { allow: ["warn"] }] */ console.warn(`unknown window: ${window}`) } } - let aggregationName = get(find(aggregationOptions, { value: aggregateBy }), 'name', '').toLowerCase() + const aggregationName = get(find(aggregationOptions, { value: aggregateBy }), 'name', '').toLocaleLowerCase('en-US') if (aggregationName === '') { + /* eslint no-console: ["error", { allow: ["warn"] }] */ console.warn(`unknown aggregation: ${aggregateBy}`) } @@ -100,9 +102,6 @@ function generateTitle({ window, aggregateBy, accumulate }) { } export const OpenCostReport = () => { - console.log("get the URL from the config") - const baseUrl = "http://localhost:9003"; - const classes = useStyles() // Allocation data state const [allocationData, setAllocationData] = useState([]) @@ -169,12 +168,11 @@ export const OpenCostReport = () => { setErrors([]) try { - // get the baseUrl from the Basecamp config - console.log("get the baseUrl from the Basecamp config") + // TODO get the baseUrl from the Basecamp config + const baseUrl = "http://localhost:9003"; const resp = await AllocationService.fetchAllocation(baseUrl, window, aggregateBy, { accumulate }) if (resp.data && resp.data.length > 0) { const allocationRange = resp.data - console.log(allocationRange); for (const i in allocationRange) { // update cluster aggregations to use clusterName/clusterId names allocationRange[i] = sortBy(allocationRange[i], a => a.totalCost) diff --git a/plugins/opencost/src/components/SelectWindow.js b/plugins/opencost/src/components/SelectWindow.js index 3fd2ec8fca..a8eb00f03c 100644 --- a/plugins/opencost/src/components/SelectWindow.js +++ b/plugins/opencost/src/components/SelectWindow.js @@ -92,12 +92,12 @@ const SelectWindow = ({ windowOptions, window, setWindow }) => { useEffect(() => { if (startDate !== null && endDate !== null) { // Note: getTimezoneOffset() is calculated based on current system locale, NOT date object - let adjustedStartDate = new Date(startDate - startDate.getTimezoneOffset() * 60000) - let adjustedEndDate = new Date(endDate - endDate.getTimezoneOffset() * 60000) + const adjustedStartDate = new Date(startDate - startDate.getTimezoneOffset() * 60000) + const adjustedEndDate = new Date(endDate - endDate.getTimezoneOffset() * 60000) setIntervalString( - adjustedStartDate.toISOString().split('.')[0] + "Z" - + "," - + adjustedEndDate.toISOString().split('.')[0] + "Z" + `${adjustedStartDate.toISOString().split('.')[0] }Z` + + `,${ + adjustedEndDate.toISOString().split('.')[0] }Z` ) } }, [startDate, endDate]) @@ -138,7 +138,7 @@ const SelectWindow = ({ windowOptions, window, setWindow }) => { { /> {
{windowOptions.map(opt => - { > {opt.name} - + ) )}