Skip to content

Commit 5b46242

Browse files
committed
ui: Add eslint and prettier config with fixes
1 parent 821c5fb commit 5b46242

File tree

13 files changed

+130
-66
lines changed

13 files changed

+130
-66
lines changed

ui/.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
node_modules/
3+
src/client/
4+
public/

ui/.eslintrc.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Parse all files with TypeScript.
2+
extends:
3+
- 'standard-with-typescript'
4+
- 'prettier'
5+
6+
parserOptions:
7+
project: './tsconfig.json'
8+
createDefaultProgram: true
9+
10+
plugins:
11+
- prettier
12+
- react
13+
- '@typescript-eslint'
14+
- react-hooks
15+
16+
settings:
17+
react:
18+
version: detect
19+
20+
env:
21+
browser: true
22+
23+
rules:
24+
react-hooks/rules-of-hooks: error
25+
react-hooks/exhaustive-deps: error
26+
27+
no-unused-vars: 0
28+
'@typescript-eslint/no-unused-vars':
29+
- error
30+
- varsIgnorePattern: _
31+
argsIgnorePattern: _
32+
33+
no-labels: [error, {allowLoop: true}]
34+
no-void: 0
35+
# TODO fix these in follow ups
36+
'@typescript-eslint/explicit-function-return-type': 'off'
37+
#'@typescript-eslint/member-delimiter-style':
38+
# - error
39+
# - singleline:
40+
# delimiter: 'semi'
41+
# requireLast: false

ui/.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
node_modules/
3+
src/client/
4+
public/

ui/.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true,
4+
"bracketSpacing": false,
5+
"arrowParens": "avoid"
6+
}

ui/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ export const parseDuration = (durationStr: string): number | null => {
104104
return 0;
105105
}
106106

107-
const durationRE = new RegExp('^(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?$');
107+
const durationRE = /^(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?$/
108108
const matches = durationStr.match(durationRE);
109-
if (!matches) {
109+
if (matches === null) {
110110
return null;
111111
}
112112

ui/src/components/AlertsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const AlertsTable = ({ objective, grouping }: AlertsTableProps): JSX.Element =>
2020
useEffect(() => {
2121
const controller = new AbortController()
2222

23-
api.getMultiBurnrateAlerts({
23+
void api.getMultiBurnrateAlerts({
2424
expr: labelsString(objective.labels),
2525
grouping: labelsString(grouping),
2626
inactive: true

ui/src/components/graphs/ErrorBudgetGraph.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const ErrorBudgetGraph = ({ api, labels, grouping, timeRange, uPlotCursor }: Err
2929
const [width, setWidth] = useState<number>(1000)
3030

3131
const setWidthFromContainer = () => {
32-
if (targetRef !== undefined && targetRef.current) {
32+
if (targetRef !== undefined) {
3333
setWidth(targetRef.current.offsetWidth)
3434
}
3535
}
@@ -82,8 +82,8 @@ const ErrorBudgetGraph = ({ api, labels, grouping, timeRange, uPlotCursor }: Err
8282
const budgetGradient = (u: uPlot) => {
8383
const width = u.ctx.canvas.width
8484
const height = u.ctx.canvas.height
85-
const min = u.scales['y'].min
86-
const max = u.scales['y'].max
85+
const min = u.scales.y.min
86+
const max = u.scales.y.max
8787

8888
if (min == null || max == null) {
8989
return '#fff'

ui/src/components/graphs/ErrorsGraph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const ErrorsGraph = ({ api, labels, grouping, timeRange, uPlotCursor }: ErrorsGr
3030
const [width, setWidth] = useState<number>(500)
3131

3232
const setWidthFromContainer = () => {
33-
if (targetRef !== undefined && targetRef.current) {
33+
if (targetRef !== undefined) {
3434
setWidth(targetRef.current.offsetWidth)
3535
}
3636
}

ui/src/components/graphs/RequestsGraph.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const RequestsGraph = ({ api, labels, grouping, timeRange, uPlotCursor }: Reques
3030
const [width, setWidth] = useState<number>(500)
3131

3232
const setWidthFromContainer = () => {
33-
if (targetRef !== undefined && targetRef.current) {
33+
if (targetRef !== undefined) {
3434
setWidth(targetRef.current.offsetWidth)
3535
}
3636
}
@@ -49,7 +49,7 @@ const RequestsGraph = ({ api, labels, grouping, timeRange, uPlotCursor }: Reques
4949
api.getREDRequests({ expr: labelsString(labels), grouping: labelsString(grouping), start, end })
5050
.then((r: QueryRange) => {
5151
const [x, ...ys] = r.values
52-
let data: AlignedData = [x, ...ys] // explicitly give it the x then the rest of ys
52+
const data: AlignedData = [x, ...ys] // explicitly give it the x then the rest of ys
5353

5454
setRequestsLabels(r.labels)
5555
setRequestsQuery(r.query)
@@ -66,7 +66,7 @@ const RequestsGraph = ({ api, labels, grouping, timeRange, uPlotCursor }: Reques
6666
}, [api, labels, grouping, timeRange])
6767

6868
// small state used while picking colors to reuse as little as possible
69-
let pickedColors = {
69+
const pickedColors = {
7070
'greens': 0,
7171
'yellows': 0,
7272
'blues': 0,
@@ -144,24 +144,24 @@ const RequestsGraph = ({ api, labels, grouping, timeRange, uPlotCursor }: Reques
144144
const labelColor = (picked: { [color: string]: number }, label: string): string => {
145145
let color = ''
146146
if (label === '{}') {
147-
color = greens[picked['greens'] % greens.length]
148-
picked['greens']++
147+
color = greens[picked.greens % greens.length]
148+
picked.greens++
149149
}
150150
if (label.match(/"(2\d{2}|OK)"/) != null) {
151-
color = greens[picked['greens'] % greens.length]
152-
picked['greens']++
151+
color = greens[picked.greens % greens.length]
152+
picked.greens++
153153
}
154154
if (label.match(/"(3\d{2})"/) != null) {
155-
color = yellows[picked['yellows'] % yellows.length]
156-
picked['yellows']++
155+
color = yellows[picked.yellows % yellows.length]
156+
picked.yellows++
157157
}
158158
if (label.match(/"(4\d{2}|Canceled|InvalidArgument|NotFound|AlreadyExists|PermissionDenied|Unauthenticated|ResourceExhausted|FailedPrecondition|Aborted|OutOfRange)"/) != null) {
159-
color = blues[picked['blues'] % blues.length]
160-
picked['blues']++
159+
color = blues[picked.blues % blues.length]
160+
picked.blues++
161161
}
162162
if (label.match(/"(5\d{2}|Unknown|DeadlineExceeded|Unimplemented|Internal|Unavailable|DataLoss)"/) != null) {
163-
color = reds[picked['reds'] % reds.length]
164-
picked['reds']++
163+
color = reds[picked.reds % reds.length]
164+
picked.reds++
165165
}
166166
return color
167167
}

ui/src/components/graphs/gaps.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export const seriesGaps = (start: number, end: number) => (u: uPlot, seriesID: n
77
delta = (2 * (end - start) / 1000)
88
}
99

10-
let gaps: uPlot.Series.Gaps = []
10+
const gaps: uPlot.Series.Gaps = []
1111

12-
let xData = u.data[0]
12+
const xData = u.data[0]
1313
for (let i = startIdx + 1; i <= endIdx; i++) {
1414
if (xData[i] - xData[i - 1] > delta) {
1515
uPlot.addGap(

0 commit comments

Comments
 (0)