Add typescript checker plugin for vite, fixed typing errors

This commit is contained in:
Dane Johnson 2023-02-14 23:16:52 -06:00
parent ffaef7419c
commit a7b56ebbf9
9 changed files with 735 additions and 133 deletions

View File

@ -20,27 +20,7 @@ module.exports = {
tsconfigRootDir: __dirname, tsconfigRootDir: __dirname,
}, },
plugins: ["react", "@typescript-eslint"], plugins: ["react", "@typescript-eslint"],
// typescript-eslint disables a bunch of rules that tsc would catch, but vite refuses to rules: {},
// add compiler errors to output, so here we are
rules: {
"constructor-super": "error",
"getter-return": "error",
"no-const-assign": "error",
"no-dupe-args": "error",
"no-dupe-class-members": "error",
"no-dupe-keys": "error",
"no-func-assign": "error",
"no-import-assign": "error",
"no-new-symbol": "error",
"no-obj-calls": "error",
"no-redeclare": "error",
"no-setter-return": "error",
"no-this-before-super": "error",
"no-undef": "error",
"no-unreachable": "error",
"no-unsafe-negation": "error",
"valid-typeof": "error",
},
settings: { settings: {
react: { react: {
version: "detect", version: "detect",

811
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,6 @@
"prettier": "^2.8.3", "prettier": "^2.8.3",
"typescript": "^4.9.5", "typescript": "^4.9.5",
"vite": "^4.0.0", "vite": "^4.0.0",
"vite-plugin-eslint": "^1.8.1" "vite-plugin-checker": "^0.5.5"
} }
} }

View File

@ -29,7 +29,7 @@ const Display = () => {
<Stack <Stack
direction="horizontal" direction="horizontal"
gap={10} gap={5}
className="position-absolute bottom-0 w-100 d-flex justify-content-center" className="position-absolute bottom-0 w-100 d-flex justify-content-center"
> >
{Object.entries(contestants).map(([sid, contestant]) => ( {Object.entries(contestants).map(([sid, contestant]) => (

View File

@ -15,11 +15,11 @@ const cursorPos = (e: PointerEvent<HTMLCanvasElement>) => {
}; };
const DrawPad = ({ height, lines, onUpdateImage, readonly = false }: Props) => { const DrawPad = ({ height, lines, onUpdateImage, readonly = false }: Props) => {
const parent = useRef<HTMLElement>(); const parent = useRef<HTMLDivElement>(null);
const canvas = useRef<HTMLCanvasElement>(); const canvas = useRef<HTMLCanvasElement>(null);
const [width, setWidth] = useState(0); const [width, setWidth] = useState(0);
const [down, setDown] = useState(false); const [down, setDown] = useState(false);
const [path, setPath] = useState([]); const [path, setPath] = useState<number[]>([]);
const pen = canvas.current?.getContext("2d"); const pen = canvas.current?.getContext("2d");
const render = () => { const render = () => {
@ -43,18 +43,18 @@ const DrawPad = ({ height, lines, onUpdateImage, readonly = false }: Props) => {
}; };
useEffect(() => { useEffect(() => {
setWidth(parent.current?.getBoundingClientRect().width); setWidth(parent.current?.getBoundingClientRect().width || 0);
render(); render();
}, [parent, pen, lines]); }, [parent, pen, lines]);
const beginLine = () => { const beginLine = () => {
if (readonly) return; if (readonly || !pen) return;
pen.beginPath(); pen.beginPath();
setDown(true); setDown(true);
}; };
const drawLine = (e: PointerEvent<HTMLCanvasElement>) => { const drawLine = (e: PointerEvent<HTMLCanvasElement>) => {
if (!down) return; if (!down || !pen) return;
const [x, y] = cursorPos(e); const [x, y] = cursorPos(e);
setPath([...path, x, y]); setPath([...path, x, y]);
pen.lineTo(x, y); pen.lineTo(x, y);

View File

@ -15,7 +15,7 @@ const ActiveClue = ({ activeClue }: Props) => {
return ( return (
<Container> <Container>
<p>{activeClue.question}</p> <p>{activeClue.question}</p>
<Stack gap="3" className="text-center"> <Stack gap={3} className="text-center">
<Button onClick={() => dispatch(setActiveClue(null))}> <Button onClick={() => dispatch(setActiveClue(null))}>
Start Timer Start Timer
</Button> </Button>

View File

@ -23,7 +23,7 @@ export const setup = () => {
} }
); );
socket.on("categories", (data: Record<string, Clue>) => { socket.on("categories", (data: Record<string, Clue[]>) => {
store.dispatch(setCategories(data)); store.dispatch(setCategories(data));
}); });

View File

@ -1,4 +1,6 @@
import { debounce as lodashDebounce } from "lodash"; import { debounce as lodashDebounce } from "lodash";
export const debounce = (fn: (...args: unknown[]) => unknown) => type DebounceableFunction = Parameters<typeof lodashDebounce>[0];
export const debounce = (fn: DebounceableFunction) =>
lodashDebounce(fn, 1000, { leading: true, trailing: false }); lodashDebounce(fn, 1000, { leading: true, trailing: false });

View File

@ -1,4 +1,5 @@
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import { checker } from "vite-plugin-checker";
import react from "@vitejs/plugin-react"; import react from "@vitejs/plugin-react";
import eslint from "vite-plugin-eslint"; import eslint from "vite-plugin-eslint";
@ -8,12 +9,14 @@ export default defineConfig({
host: true, host: true,
}, },
plugins: [ plugins: [
{ ...react(), ...eslint(), apply: "build" },
{ {
...react(), ...react(),
...eslint({ failOnWarning: false, failOnError: true }), ...checker({
apply: "serve", typescript: true,
enforce: "post", eslint: {
lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
},
}),
}, },
], ],
}); });