diff --git a/.changeset/beige-ravens-find.md b/.changeset/beige-ravens-find.md new file mode 100644 index 0000000000..f56cad6040 --- /dev/null +++ b/.changeset/beige-ravens-find.md @@ -0,0 +1,8 @@ +--- +"@cloudoperators/juno-ui-components": patch +"@cloudoperators/juno-app-greenhouse": patch +"@cloudoperators/juno-app-supernova": patch +"@cloudoperators/juno-app-doop": patch +--- + +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. diff --git a/apps/doop/src/components/Highlighter.tsx b/apps/doop/src/components/Highlighter.tsx index 4ab3faf521..e2bbaef02c 100644 --- a/apps/doop/src/components/Highlighter.tsx +++ b/apps/doop/src/components/Highlighter.tsx @@ -120,8 +120,7 @@ const Highlighter = () => { React.useEffect(() => { const observers = createObservers((mutations: any) => { for (const mutation of mutations) { - // @ts-expect-error TS(2367) FIXME: This condition will always return 'false' since th... Remove this comment to see the full error message - if (!mutation.type === "childList") continue + if (mutation.type !== "childList") continue // ignore changes to search nodes const addedOrRemovedNodes = Array.from(mutation.addedNodes).concat(Array.from(mutation.removedNodes)) diff --git a/apps/doop/src/lib/filterViolations.ts b/apps/doop/src/lib/filterViolations.ts index 05f462f351..ce82cf9ce6 100644 --- a/apps/doop/src/lib/filterViolations.ts +++ b/apps/doop/src/lib/filterViolations.ts @@ -85,7 +85,7 @@ const filterByActiveFilters = (violationGroups: any[], clusterIdentities: any[], true ) ) - found = found && constraint.violation_groups?.length > 0 + found = (constraint.violation_groups?.length ?? 0) > 0 } // ############ CLUSTER FILTERS ############ diff --git a/apps/greenhouse/src/components/core-apps/org-admin/components/clusters/components/ClusterEdit.tsx b/apps/greenhouse/src/components/core-apps/org-admin/components/clusters/components/ClusterEdit.tsx index ccc3bcf644..00b238682c 100644 --- a/apps/greenhouse/src/components/core-apps/org-admin/components/clusters/components/ClusterEdit.tsx +++ b/apps/greenhouse/src/components/core-apps/org-admin/components/clusters/components/ClusterEdit.tsx @@ -23,7 +23,6 @@ import { useClusterApi } from "../hooks/useClusterApi" const ClusterEdit: React.FC = () => { const clusterInEdit = useStore((state: any) => state.clusterInEdit) - clusterInEdit?.spec const setClusterInEdit = useStore((state: any) => state.setClusterInEdit) const [submitMessage, setSubmitResultMessage] = React.useState({ message: "", ok: false }) diff --git a/apps/greenhouse/src/components/core-apps/org-admin/components/plugins/plugin-edit/OptionInput.tsx b/apps/greenhouse/src/components/core-apps/org-admin/components/plugins/plugin-edit/OptionInput.tsx index cdae7a4e3e..741b90904c 100644 --- a/apps/greenhouse/src/components/core-apps/org-admin/components/plugins/plugin-edit/OptionInput.tsx +++ b/apps/greenhouse/src/components/core-apps/org-admin/components/plugins/plugin-edit/OptionInput.tsx @@ -21,9 +21,8 @@ export const OptionInput: React.FC = (props: OptionInputProps) const [errortext, setErrorText] = useState("") const handleJsonValidation = (value: string) => { - let object try { - object = JSON.parse(value) + JSON.parse(value) } catch (e) { setValid(false) setErrorText("Invalid JSON") diff --git a/apps/greenhouse/src/components/core-apps/org-admin/components/teams/lib/store.ts b/apps/greenhouse/src/components/core-apps/org-admin/components/teams/lib/store.ts index 78930aef18..1bf5a08b42 100644 --- a/apps/greenhouse/src/components/core-apps/org-admin/components/teams/lib/store.ts +++ b/apps/greenhouse/src/components/core-apps/org-admin/components/teams/lib/store.ts @@ -14,8 +14,6 @@ export default () => currentTeam: "", defaultTeam: "", teamMemberships: [], - // @ts-expect-error TS(1117): An object literal cannot have multiple properties ... Remove this comment to see the full error message - namespace: "", actions: { initialize: (endpoint: any, token: any, namespace: any, userGroup: any) => diff --git a/apps/greenhouse/src/lib/helpers.ts b/apps/greenhouse/src/lib/helpers.ts index e8b5244893..5b5e42ade0 100644 --- a/apps/greenhouse/src/lib/helpers.ts +++ b/apps/greenhouse/src/lib/helpers.ts @@ -4,18 +4,15 @@ */ export const parseError = (error: any) => { + let errMsg: string if (error?.message) { - // @ts-expect-error TS(2304): Cannot find name 'errMsg'. errMsg = error?.message try { - // @ts-expect-error TS(2304): Cannot find name 'errMsg'. errMsg = JSON.parse(error?.message).msg } catch (error) { console.debug(error) } - // @ts-expect-error TS(2304): Cannot find name 'errMsg'. } else errMsg = error.toString() - // @ts-expect-error TS(2304): Cannot find name 'errMsg'. return errMsg } diff --git a/apps/supernova/src/components/alerts/AlertStatus.tsx b/apps/supernova/src/components/alerts/AlertStatus.tsx index 12cc4e1941..8e0566cfab 100644 --- a/apps/supernova/src/components/alerts/AlertStatus.tsx +++ b/apps/supernova/src/components/alerts/AlertStatus.tsx @@ -41,7 +41,7 @@ const AlertStatus = ({ alert }: any) => { return (
- {alert && {alert?.status?.state}} + {alert?.status?.state && {alert.status.state}} {inhibitor && (
diff --git a/apps/supernova/src/lib/createFiltersSlice.tsx b/apps/supernova/src/lib/createFiltersSlice.tsx index 9e77feee97..ff9e3b299d 100644 --- a/apps/supernova/src/lib/createFiltersSlice.tsx +++ b/apps/supernova/src/lib/createFiltersSlice.tsx @@ -66,18 +66,20 @@ const parsePredefinedFilters = (predefinedFilters: any[]): FilterState["predefin } const parseInitialFilters = ( - initialFilters: Record, + initialFilters: Record | null | undefined, filterLabels: string[] ): Record => { if (!initialFilters) return {} - if (typeof initialFilters !== "object" || initialFilters === null) { + if (typeof initialFilters !== "object" || Array.isArray(initialFilters)) { console.warn("[supernova]::parseInitialFilters: initialFilters object is not an object") return {} } + const validatedFilters: Record = initialFilters + // Check if all values are arrays - initialFilters = Object.entries(initialFilters).reduce((acc: any, [key, value]) => { + const filteredByType = Object.entries(validatedFilters).reduce((acc: Record, [key, value]) => { if (Array.isArray(value)) { acc[key] = value // valid key-value pair } else { @@ -87,25 +89,25 @@ const parseInitialFilters = ( }, {}) // Check if all keys are in filterLabelValues - if (!Object.keys(initialFilters).every((key) => filterLabels.includes(key))) { + if (!Object.keys(filteredByType).every((key) => filterLabels.includes(key))) { console.warn( "[supernova]::parseInitialFilters: Some keys of the initialFilters object are not valid filter labels. They must be configured as filterLabels first. Using only valid keys." ) // filter out the keys that are not in filterLabels, return the rest // this will ensure that at least the valid keys are used as initial filters - const filtered = Object.keys(initialFilters) + const filtered = Object.keys(filteredByType) .filter((key) => filterLabels.includes(key)) - .reduce((obj, key) => { + .reduce>((obj, key) => { return { ...obj, - [key]: initialFilters[key], + [key]: filteredByType[key], } }, {}) return filtered } - return initialFilters + return filteredByType } const parseActivePredefinedFilter = (predefinedFilters: any): string | null => { diff --git a/apps/supernova/src/lib/createSilencesSlice.tsx b/apps/supernova/src/lib/createSilencesSlice.tsx index 47d689f092..c48fa9d461 100644 --- a/apps/supernova/src/lib/createSilencesSlice.tsx +++ b/apps/supernova/src/lib/createSilencesSlice.tsx @@ -163,14 +163,16 @@ const createSilencesSlice: (options?: Record) => StateCreator { if (!items) return - ;(set((state: any) => ({ - silences: { - ...state.silences, - items: items, - updatedAt: Date.now(), - }, - })), - false) + set( + (state: any) => ({ + silences: { + ...state.silences, + items: items, + updatedAt: Date.now(), + }, + }), + false + ) }, /* diff --git a/packages/ui-components/src/components/ComboBox/ComboBox.test.tsx b/packages/ui-components/src/components/ComboBox/ComboBox.test.tsx index 0c1e6a133a..8af34e19fe 100644 --- a/packages/ui-components/src/components/ComboBox/ComboBox.test.tsx +++ b/packages/ui-components/src/components/ComboBox/ComboBox.test.tsx @@ -107,12 +107,12 @@ describe("ComboBox", () => { await waitFor(() => render( - + ) ) expect(screen.getByRole("combobox")).toBeInTheDocument() - expect(screen.getByRole("combobox")).toHaveAttribute("id", "My Id") + expect(screen.getByRole("combobox")).toHaveAttribute("id", "my-id") }) test("renders the id of the ComboBox input as the for attribute of the label", async () => { diff --git a/packages/ui-components/src/components/Message/Message.test.tsx b/packages/ui-components/src/components/Message/Message.test.tsx index 96b23a049a..d923650ac6 100644 --- a/packages/ui-components/src/components/Message/Message.test.tsx +++ b/packages/ui-components/src/components/Message/Message.test.tsx @@ -49,8 +49,8 @@ describe("Message component", () => { }) test("renders the component with all provided props", () => { - render() - expect(screen.getByTestId("my-message")).toHaveAttribute("id", "My shiny little Message") + render() + expect(screen.getByTestId("my-message")).toHaveAttribute("id", "my-shiny-little-message") }) }) diff --git a/packages/ui-components/src/components/Toast/Toast.test.tsx b/packages/ui-components/src/components/Toast/Toast.test.tsx index d5fad6f4b8..ff31bc82d5 100644 --- a/packages/ui-components/src/components/Toast/Toast.test.tsx +++ b/packages/ui-components/src/components/Toast/Toast.test.tsx @@ -91,7 +91,7 @@ describe("Toast", () => { }) test("renders all props as passed", () => { - render() - expect(screen.getByTestId("my-toast")).toHaveAttribute("id", "My shiny little Message") + render() + expect(screen.getByTestId("my-toast")).toHaveAttribute("id", "my-shiny-little-message") }) })