Skip to content

Commit 5e744a0

Browse files
authored
Merge pull request #344 from flatironinstitute/update-eslint
Update eslint config, check in CI
2 parents e007795 + 7d4fad5 commit 5e744a0

File tree

17 files changed

+638
-346
lines changed

17 files changed

+638
-346
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
cache-dependency-path: gui/yarn.lock
3030
- name: Install dependencies
3131
run: cd gui; yarn
32+
- name: Lint
33+
run: cd gui; yarn format --check && yarn lint
3234
- name: Test
3335
run: cd gui; yarn test
3436
- name: Upload coverage reports to Codecov

gui/.eslintrc.cjs

Lines changed: 0 additions & 25 deletions
This file was deleted.

gui/eslint.config.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
4+
import tseslint from "typescript-eslint";
5+
import pluginReact from "eslint-plugin-react";
6+
import reactHooks from "eslint-plugin-react-hooks";
7+
8+
import { defineConfig } from "eslint/config";
9+
10+
export default defineConfig([
11+
{
12+
files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
13+
plugins: { js },
14+
extends: ["js/recommended"],
15+
languageOptions: { globals: globals.browser },
16+
},
17+
tseslint.configs.recommended,
18+
pluginReact.configs.flat.recommended,
19+
pluginReact.configs.flat["jsx-runtime"],
20+
reactHooks.configs.flat.recommended,
21+
{
22+
settings: {
23+
react: {
24+
version: "19",
25+
},
26+
},
27+
},
28+
{
29+
rules: {
30+
"react-hooks/set-state-in-effect": "off",
31+
"@typescript-eslint/no-explicit-any": "off",
32+
"@typescript-eslint/no-unused-vars": [
33+
"error",
34+
{
35+
args: "all",
36+
argsIgnorePattern: "^_",
37+
caughtErrors: "all",
38+
caughtErrorsIgnorePattern: "^_",
39+
destructuredArrayIgnorePattern: "^_",
40+
varsIgnorePattern: "^_",
41+
ignoreRestSiblings: true,
42+
},
43+
],
44+
},
45+
},
46+
]);

gui/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dev": "vite --port 3000",
1515
"build": "tsc && vite build",
1616
"format": "prettier --write .",
17-
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
17+
"lint": "eslint src/",
1818
"preview": "vite preview",
1919
"test": "vitest run",
2020
"test-watch": "vitest"
@@ -44,6 +44,7 @@
4444
},
4545
"devDependencies": {
4646
"@codecov/vite-plugin": "^1.9.0",
47+
"@eslint/js": "^10.0.1",
4748
"@testing-library/dom": "^10.1.0",
4849
"@testing-library/react": "^16.0.0",
4950
"@types/node": "^20.12.11",
@@ -56,14 +57,15 @@
5657
"@vitejs/plugin-react": "^4.3.4",
5758
"@vitest/coverage-v8": "^3.0.7",
5859
"@vitest/web-worker": "^3.0.7",
59-
"eslint": "^8.45.0",
60-
"eslint-plugin-react": "^7.32.2",
61-
"eslint-plugin-react-hooks": "^4.6.0",
62-
"eslint-plugin-react-refresh": "^0.4.3",
60+
"eslint": "^10.0.0",
61+
"eslint-plugin-react": "^7.37.5",
62+
"eslint-plugin-react-hooks": "^7.0.1",
63+
"globals": "^17.3.0",
6364
"jsdom": "^26.1.0",
6465
"monaco-editor": "^0.52.2",
6566
"prettier": "^3.3.2",
6667
"typescript": "^5.9.3",
68+
"typescript-eslint": "^8.55.0",
6769
"vite": "^6.4.1",
6870
"vite-tsconfig-paths": "^5.1.4",
6971
"vitest": "^3.0.7"

gui/src/app/areas/ControlArea/SamplingArea/ResultsArea/AnalysisArea/useAnalysisState.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,17 @@ const useAnalysisState = (samplerState: SamplerState) => {
4141
}, [samplerStatus, draws, numChains, paramNames]);
4242

4343
const [status, setStatus] = useState<InterpreterStatus>("idle");
44-
45-
const [runnable, setRunnable] = useState<boolean>(true);
46-
const [notRunnableReason, setNotRunnableReason] = useState<string>("");
47-
4844
const isDataDefined = useMemo(() => spData !== undefined, [spData]);
45+
const runnable = isDataDefined && !isInterpreterBusy(status);
46+
const notRunnableReason = !isDataDefined ? "Run sampler first." : "";
4947

5048
const files = useMemo(() => {
5149
if (samplingOpts?.data === undefined) {
5250
return undefined;
5351
} else {
5452
return [encodeTextFile(FileNames.DATAFILE, samplingOpts.data)];
5553
}
56-
}, [samplingOpts?.data]);
57-
58-
useEffect(() => {
59-
if (!isDataDefined) {
60-
setRunnable(false);
61-
setNotRunnableReason("Run sampler first.");
62-
} else if (isInterpreterBusy(status)) {
63-
setRunnable(false);
64-
setNotRunnableReason("");
65-
} else {
66-
setRunnable(true);
67-
setNotRunnableReason("");
68-
}
69-
}, [isDataDefined, status]);
54+
}, [samplingOpts]);
7055

7156
return {
7257
consoleRef,

gui/src/app/areas/ControlArea/SamplingArea/ResultsArea/SamplerOutputArea/ScatterPlotsPanel.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
useCallback,
3-
useEffect,
4-
useMemo,
5-
useState,
6-
type FunctionComponent,
7-
} from "react";
1+
import { useCallback, useMemo, useState, type FunctionComponent } from "react";
82

93
import type { StanDraw } from "../SamplerOutputArea";
104

@@ -83,10 +77,7 @@ const VariableSelection: FunctionComponent<SelectionProps> = ({
8377
[hitLimit, value],
8478
);
8579

86-
const [showCheckbox, setShowCheckbox] = useState(false);
87-
useEffect(() => {
88-
setShowCheckbox(value.length === 3);
89-
}, [value.length]);
80+
const showCheckbox = value.length === 3;
9081

9182
return (
9283
<Stack

gui/src/app/areas/ControlArea/SamplingArea/RunArea/CompileButton.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import Tooltip from "@mui/material/Tooltip";
77
import { CompileContext } from "@SpCore/Compilation/CompileContextProvider";
88
import { ProjectContext } from "@SpCore/Project/ProjectContextProvider";
99

10-
type CompileButtonProps = {
11-
// No props
12-
};
13-
14-
const CompileButton: FunctionComponent<CompileButtonProps> = () => {
10+
const CompileButton: FunctionComponent = () => {
1511
const { data: projectData } = use(ProjectContext);
1612

1713
const { compile, compileStatus, validSyntax, isConnected } =

gui/src/app/areas/ControlArea/SamplingArea/RunArea/SamplingOptsPanel.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ const SamplingOptsPanel: FunctionComponent<SamplingOptsPanelProps> = ({
3636
}) => {
3737
const readOnly = !setSamplingOpts;
3838

39-
const handleReset = useCallback(() => {
40-
setSamplingOpts && setSamplingOpts(defaultSamplingOpts);
41-
}, [setSamplingOpts]);
39+
const handleReset = useCallback(
40+
() => setSamplingOpts && setSamplingOpts(defaultSamplingOpts),
41+
[setSamplingOpts],
42+
);
4243

4344
return (
4445
<Stack direction={direction} spacing={1}>

gui/src/app/components/TabWidget.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const TabWidget: FunctionComponent<TabWidgetProps> = ({
1919
}
2020

2121
const [index, setIndex] = useState(forcedSelection ?? 0);
22+
const [tabsThatHaveBeenViewed, setTabsThatHaveBeenViewed] = useState<
23+
number[]
24+
>([index]);
2225

2326
useEffect(() => {
2427
if (forcedSelection !== undefined) {
@@ -32,10 +35,6 @@ const TabWidget: FunctionComponent<TabWidgetProps> = ({
3235
}
3336
}, [forcedSelection]);
3437

35-
const [tabsThatHaveBeenViewed, setTabsThatHaveBeenViewed] = useState<
36-
number[]
37-
>([index]);
38-
3938
const handleChange = (_: React.SyntheticEvent, newValue: number) => {
4039
setTabsThatHaveBeenViewed((prev) => {
4140
if (!prev.includes(newValue)) {

gui/src/app/core/Compilation/CompileContextProvider.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ export const CompileContext = createContext<CompileContextType>({
4343
retryConnection: () => {},
4444
});
4545

46-
type CompileContextProviderProps = {
47-
// none
48-
};
49-
5046
const useIsConnected = (stanWasmServerUrl: string) => {
5147
const probeUrl = `${stanWasmServerUrl}/probe`;
5248
const [isConnected, setIsConnected] = useState<boolean>(false);
@@ -67,7 +63,7 @@ const useIsConnected = (stanWasmServerUrl: string) => {
6763
if (response.status === 200) {
6864
setIsConnected(true);
6965
}
70-
} catch (err) {
66+
} catch {
7167
setIsConnected(false);
7268
}
7369
})();
@@ -98,9 +94,9 @@ const showOneTimeMessage = (url: string) => {
9894
return false;
9995
};
10096

101-
const CompileContextProvider: FunctionComponent<
102-
PropsWithChildren<CompileContextProviderProps>
103-
> = ({ children }) => {
97+
const CompileContextProvider: FunctionComponent<PropsWithChildren> = ({
98+
children,
99+
}) => {
104100
const { data } = use(ProjectContext);
105101
const [compileStatus, setCompileStatus] = useState<CompileStatus>("");
106102
const [

0 commit comments

Comments
 (0)