From 944ddf6b8684d8c1509d93f01ea82dad14742078 Mon Sep 17 00:00:00 2001 From: Mantra Date: Wed, 13 Nov 2024 22:21:18 +0000 Subject: [PATCH] add basic eslint rules back in and make types better --- app/static/eslint.config.js | 9 ++++-- app/static/src/apiService.ts | 19 +++++++----- .../src/components/VerticalCollapse.vue | 1 + app/static/src/components/WodinPlot.vue | 9 +++--- app/static/src/components/WodinSession.vue | 1 + app/static/src/components/WodinTabs.vue | 1 + .../components/graphConfig/GraphConfig.vue | 1 + .../components/options/ParameterSetView.vue | 7 +++-- .../components/options/SensitivityOptions.vue | 1 + .../SensitivitySummaryDownload.vue | 1 + app/static/src/directives/tooltip.ts | 10 +++---- app/static/src/excel/wodinExcelDownload.ts | 1 + app/static/src/store/basic/basic.ts | 4 +-- app/static/src/store/fit/fit.ts | 4 +-- app/static/src/store/stochastic/stochastic.ts | 4 +-- app/static/src/types/utilTypes.ts | 3 +- app/static/src/utils.ts | 6 ++-- .../translationPackage/directive/translate.ts | 30 +++++++++---------- .../translationPackage/store/actions.ts | 2 +- 19 files changed, 66 insertions(+), 48 deletions(-) diff --git a/app/static/eslint.config.js b/app/static/eslint.config.js index 82b0022a..cf333985 100644 --- a/app/static/eslint.config.js +++ b/app/static/eslint.config.js @@ -23,16 +23,19 @@ export default [ }, { - files: ["**/*.ts", "**/*.vue"], + files: ["src/**/*.ts", "src/**/*.vue"], rules: { - "@typescript-eslint/no-explicit-any": "off" + "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/no-unused-vars": "error", + "vue/no-setup-props-destructure": "error", } }, { files: ["**/tests/**/*.ts"], rules: { - "vitest/expect-expect": "off" + "vitest/expect-expect": "off", + "@typescript-eslint/no-explicit-any": "off", } }, diff --git a/app/static/src/apiService.ts b/app/static/src/apiService.ts index e84f679b..8ce8d394 100644 --- a/app/static/src/apiService.ts +++ b/app/static/src/apiService.ts @@ -10,16 +10,21 @@ export interface ResponseWithType extends ResponseSuccess { data: T; } -export function isAPIError(object: any): object is WodinError { - return typeof object.error === "string" && (object.details === undefined || typeof object.details === "string"); +function isObject(object: unknown): object is Record { + return typeof object === "object" && !Array.isArray(object) && object !== null; } -export function isAPIResponseFailure(object: any): object is ResponseFailure { - return ( +export function isAPIError(object: unknown): object is WodinError { + return isObject(object) && typeof object.error === "string" && (object.detail === undefined || typeof object.detail === "string"); +} + +export function isAPIResponseFailure(object: unknown): object is ResponseFailure { + return !!( object && + isObject(object) && object.status === "failure" && Array.isArray(object.errors) && - object.errors.every((e: any) => isAPIError(e)) + object.errors.every(e => isAPIError(e)) ); } @@ -101,7 +106,7 @@ export class APIService implements API }; withSuccess = (type: S, root = false) => { - this._onSuccess = (data: any) => { + this._onSuccess = (data: unknown) => { const finalData = this._freezeResponse ? freezer.deepFreeze(data) : data; try { this._commit(type, finalData, { root }); @@ -175,7 +180,7 @@ export class APIService implements API return this._handleAxiosResponse(axios.get(fullUrl)); } - async post(url: string, body: any, contentType = "application/json"): Promise> { + async post(url: string, body: unknown, contentType = "application/json"): Promise> { this._verifyHandlers(url); const headers = { "Content-Type": contentType }; const fullUrl = this._fullUrl(url); diff --git a/app/static/src/components/VerticalCollapse.vue b/app/static/src/components/VerticalCollapse.vue index c67223f3..c4a2ca10 100644 --- a/app/static/src/components/VerticalCollapse.vue +++ b/app/static/src/components/VerticalCollapse.vue @@ -37,6 +37,7 @@ export default defineComponent({ VueFeather }, setup(props) { + // eslint-disable-next-line vue/no-setup-props-destructure const collapsed = ref(props.collapsedDefault); const toggleCollapse = () => { diff --git a/app/static/src/components/WodinPlot.vue b/app/static/src/components/WodinPlot.vue index 698681a9..7dcca4cc 100644 --- a/app/static/src/components/WodinPlot.vue +++ b/app/static/src/components/WodinPlot.vue @@ -21,7 +21,8 @@ import { AxisType, Layout, Config, - LayoutAxis + LayoutAxis, + PlotlyHTMLElement } from "plotly.js-basic-dist-min"; import { WodinPlotData, fadePlotStyle, margin, config } from "../plot"; import WodinPlotDataSummary from "./WodinPlotDataSummary.vue"; @@ -46,7 +47,7 @@ export default defineComponent({ // Only used as an indicator that redraw is required when this changes - the data to display is calculated by // plotData function using these solutions redrawWatches: { - type: Array as PropType, + type: Array as PropType, required: true }, recalculateOnRelayout: { @@ -83,7 +84,7 @@ export default defineComponent({ const startTime = 0; - const plot = ref(null); // Picks up the element with 'plot' ref in the template + const plot = ref(null); // Picks up the element with 'plot' ref in the template const baseData = ref([]); const nPoints = 1000; // TODO: appropriate value could be derived from width of element @@ -101,7 +102,7 @@ export default defineComponent({ const lastYAxisFromZoom: Ref | null> = ref(null); const commitYAxisRange = () => { - const plotLayout = (plot.value as any).layout; + const plotLayout = plot.value!.layout; const yRange = plotLayout.yaxis?.range; if (plotLayout) { if (props.fitPlot) { diff --git a/app/static/src/components/WodinSession.vue b/app/static/src/components/WodinSession.vue index 8b2a821b..6b71484a 100644 --- a/app/static/src/components/WodinSession.vue +++ b/app/static/src/components/WodinSession.vue @@ -34,6 +34,7 @@ export default defineComponent({ const appInitialised = computed(() => !!store.state.config && !!store.state.sessions.sessionsMetadata); // These props won't change as provided by server + // eslint-disable-next-line vue/no-setup-props-destructure const { appName, baseUrl, loadSessionId, appsPath, enableI18n, defaultLanguage } = props; store.dispatch(AppStateAction.InitialiseApp, { diff --git a/app/static/src/components/WodinTabs.vue b/app/static/src/components/WodinTabs.vue index 4d981091..b555cf4f 100644 --- a/app/static/src/components/WodinTabs.vue +++ b/app/static/src/components/WodinTabs.vue @@ -33,6 +33,7 @@ export default defineComponent({ }, emits: ["tabSelected"], setup(props: Props, { emit }) { + // eslint-disable-next-line vue/no-setup-props-destructure const selectedTabName = ref(props.tabNames[0]); const tabSelected = (tabName: string) => { diff --git a/app/static/src/components/graphConfig/GraphConfig.vue b/app/static/src/components/graphConfig/GraphConfig.vue index f519e8f2..24d3b3d2 100644 --- a/app/static/src/components/graphConfig/GraphConfig.vue +++ b/app/static/src/components/graphConfig/GraphConfig.vue @@ -59,6 +59,7 @@ export default defineComponent({ }, setup(props, { emit }) { const store = useStore(); + // eslint-disable-next-line vue/no-setup-props-destructure const { startDrag, endDrag, onDrop, removeVariable } = SelectVariables(store, emit, false, props.graphIndex); const selectedVariables = computed( () => store.state.graphs.config[props.graphIndex].selectedVariables diff --git a/app/static/src/components/options/ParameterSetView.vue b/app/static/src/components/options/ParameterSetView.vue index 49d91ccd..96b18d9e 100644 --- a/app/static/src/components/options/ParameterSetView.vue +++ b/app/static/src/components/options/ParameterSetView.vue @@ -97,7 +97,7 @@