Skip to content

Commit b7becbc

Browse files
authored
fix(apps): resolve CodeQL static analysis warnings across codebase (#1557)
* chore(apps): fix comparison between inconvertible types * chore(apps): fix comparison between inconvertible types * chore(apps): fix implicit operand conversion * fix(apps): remove redundant conditional expressions * fix(apps): remove useless expressions and fix zustand set call syntax * fix(apps): remove duplicate namespace property in teams store * fix(apps): declare errMsg as local variable in parseError function * fix(greenhouse): remove unused variable in JSON validation function * chore(ci): adds changeset * chore(apps): fix link * chore(supernova): fix lint * chore(ui): fix test * chore(supernova): fix comparation * chore(ci): adapt changeset * chore(supernova): remove as
1 parent 25237e6 commit b7becbc

13 files changed

Lines changed: 39 additions & 35 deletions

File tree

.changeset/beige-ravens-find.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@cloudoperators/juno-ui-components": patch
3+
"@cloudoperators/juno-app-greenhouse": patch
4+
"@cloudoperators/juno-app-supernova": patch
5+
"@cloudoperators/juno-app-doop": patch
6+
---
7+
8+
Resolves all CodeQL static analysis warnings to improve code quality, reliability, and maintainability. These fixes address potential bugs, redundant code, and anti-patterns detected by automated code scanning.

apps/doop/src/components/Highlighter.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ const Highlighter = () => {
120120
React.useEffect(() => {
121121
const observers = createObservers((mutations: any) => {
122122
for (const mutation of mutations) {
123-
// @ts-expect-error TS(2367) FIXME: This condition will always return 'false' since th... Remove this comment to see the full error message
124-
if (!mutation.type === "childList") continue
123+
if (mutation.type !== "childList") continue
125124

126125
// ignore changes to search nodes
127126
const addedOrRemovedNodes = Array.from(mutation.addedNodes).concat(Array.from(mutation.removedNodes))

apps/doop/src/lib/filterViolations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const filterByActiveFilters = (violationGroups: any[], clusterIdentities: any[],
8585
true
8686
)
8787
)
88-
found = found && constraint.violation_groups?.length > 0
88+
found = (constraint.violation_groups?.length ?? 0) > 0
8989
}
9090

9191
// ############ CLUSTER FILTERS ############

apps/greenhouse/src/components/core-apps/org-admin/components/clusters/components/ClusterEdit.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { useClusterApi } from "../hooks/useClusterApi"
2323

2424
const ClusterEdit: React.FC<any> = () => {
2525
const clusterInEdit = useStore((state: any) => state.clusterInEdit)
26-
clusterInEdit?.spec
2726
const setClusterInEdit = useStore((state: any) => state.setClusterInEdit)
2827

2928
const [submitMessage, setSubmitResultMessage] = React.useState<ResultMessage>({ message: "", ok: false })

apps/greenhouse/src/components/core-apps/org-admin/components/plugins/plugin-edit/OptionInput.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ export const OptionInput: React.FC<OptionInputProps> = (props: OptionInputProps)
2121
const [errortext, setErrorText] = useState<string>("")
2222

2323
const handleJsonValidation = (value: string) => {
24-
let object
2524
try {
26-
object = JSON.parse(value)
25+
JSON.parse(value)
2726
} catch (e) {
2827
setValid(false)
2928
setErrorText("Invalid JSON")

apps/greenhouse/src/components/core-apps/org-admin/components/teams/lib/store.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export default () =>
1414
currentTeam: "",
1515
defaultTeam: "",
1616
teamMemberships: [],
17-
// @ts-expect-error TS(1117): An object literal cannot have multiple properties ... Remove this comment to see the full error message
18-
namespace: "",
1917

2018
actions: {
2119
initialize: (endpoint: any, token: any, namespace: any, userGroup: any) =>

apps/greenhouse/src/lib/helpers.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
*/
55

66
export const parseError = (error: any) => {
7+
let errMsg: string
78
if (error?.message) {
8-
// @ts-expect-error TS(2304): Cannot find name 'errMsg'.
99
errMsg = error?.message
1010
try {
11-
// @ts-expect-error TS(2304): Cannot find name 'errMsg'.
1211
errMsg = JSON.parse(error?.message).msg
1312
} catch (error) {
1413
console.debug(error)
1514
}
16-
// @ts-expect-error TS(2304): Cannot find name 'errMsg'.
1715
} else errMsg = error.toString()
18-
// @ts-expect-error TS(2304): Cannot find name 'errMsg'.
1916
return errMsg
2017
}
2118

apps/supernova/src/components/alerts/AlertStatus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const AlertStatus = ({ alert }: any) => {
4141

4242
return (
4343
<div className="cursor-default">
44-
{alert && <span>{alert?.status?.state}</span>}
44+
{alert?.status?.state && <span>{alert.status.state}</span>}
4545
{inhibitor && (
4646
<div className="text-xs mt-2">
4747
<Stack direction="vertical">

apps/supernova/src/lib/createFiltersSlice.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@ const parsePredefinedFilters = (predefinedFilters: any[]): FilterState["predefin
6666
}
6767

6868
const parseInitialFilters = (
69-
initialFilters: Record<string, string[]>,
69+
initialFilters: Record<string, string[]> | null | undefined,
7070
filterLabels: string[]
7171
): Record<string, string[]> => {
7272
if (!initialFilters) return {}
7373

74-
if (typeof initialFilters !== "object" || initialFilters === null) {
74+
if (typeof initialFilters !== "object" || Array.isArray(initialFilters)) {
7575
console.warn("[supernova]::parseInitialFilters: initialFilters object is not an object")
7676
return {}
7777
}
7878

79+
const validatedFilters: Record<string, string[]> = initialFilters
80+
7981
// Check if all values are arrays
80-
initialFilters = Object.entries(initialFilters).reduce((acc: any, [key, value]) => {
82+
const filteredByType = Object.entries(validatedFilters).reduce((acc: Record<string, string[]>, [key, value]) => {
8183
if (Array.isArray(value)) {
8284
acc[key] = value // valid key-value pair
8385
} else {
@@ -87,25 +89,25 @@ const parseInitialFilters = (
8789
}, {})
8890

8991
// Check if all keys are in filterLabelValues
90-
if (!Object.keys(initialFilters).every((key) => filterLabels.includes(key))) {
92+
if (!Object.keys(filteredByType).every((key) => filterLabels.includes(key))) {
9193
console.warn(
9294
"[supernova]::parseInitialFilters: Some keys of the initialFilters object are not valid filter labels. They must be configured as filterLabels first. Using only valid keys."
9395
)
9496

9597
// filter out the keys that are not in filterLabels, return the rest
9698
// this will ensure that at least the valid keys are used as initial filters
97-
const filtered = Object.keys(initialFilters)
99+
const filtered = Object.keys(filteredByType)
98100
.filter((key) => filterLabels.includes(key))
99-
.reduce((obj, key) => {
101+
.reduce<Record<string, string[]>>((obj, key) => {
100102
return {
101103
...obj,
102-
[key]: initialFilters[key],
104+
[key]: filteredByType[key],
103105
}
104106
}, {})
105107
return filtered
106108
}
107109

108-
return initialFilters
110+
return filteredByType
109111
}
110112

111113
const parseActivePredefinedFilter = (predefinedFilters: any): string | null => {

apps/supernova/src/lib/createSilencesSlice.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,16 @@ const createSilencesSlice: (options?: Record<string, any>) => StateCreator<AppSt
163163

164164
setSilences: ({ items }) => {
165165
if (!items) return
166-
;(set((state: any) => ({
167-
silences: {
168-
...state.silences,
169-
items: items,
170-
updatedAt: Date.now(),
171-
},
172-
})),
173-
false)
166+
set(
167+
(state: any) => ({
168+
silences: {
169+
...state.silences,
170+
items: items,
171+
updatedAt: Date.now(),
172+
},
173+
}),
174+
false
175+
)
174176
},
175177

176178
/*

0 commit comments

Comments
 (0)