diff --git a/.eslintrc.json b/.eslintrc.json index 8856216be..b37f81adf 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,15 +3,21 @@ "browser": true, "es2021": true }, - "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:@typescript-eslint/recommended" + ], "overrides": [], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": "latest", "sourceType": "module" }, - "plugins": ["@typescript-eslint"], + "plugins": ["react", "@typescript-eslint"], "rules": { + "react/react-in-jsx-scope": 0, + "react/no-unknown-property": ["error", { "ignore": ["directory"] }], "@typescript-eslint/no-unused-vars": [ "error", { @@ -19,5 +25,10 @@ "destructuredArrayIgnorePattern": "^_" } ] + }, + "settings": { + "react": { + "version": "detect" + } } } diff --git a/components/.eslintrc.json b/components/.eslintrc.json deleted file mode 100644 index 3871b4d70..000000000 --- a/components/.eslintrc.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "env": { - "browser": true, - "es2021": true - }, - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:@typescript-eslint/recommended" - ], - "overrides": [], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "plugins": ["react", "@typescript-eslint"], - "rules": { - "react/react-in-jsx-scope": 0 - }, - "settings": { - "react": { - "version": "detect" - } - } -} diff --git a/package-lock.json b/package-lock.json index f258b0841..4743a0c92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,6 +23,7 @@ "@typescript-eslint/parser": "^5.40.0", "esbuild": "^0.15.11", "eslint": "^8.25.0", + "eslint-plugin-react": "^7.31.10", "prettier": "^2.7.1", "typescript": "^4.8.4" } @@ -20820,10 +20821,6 @@ "@types/react": "^18.0.14", "@types/react-dom": "^18.0.5", "@types/vscode": "^1.72.0", - "@typescript-eslint/eslint-plugin": "^5.40.0", - "@typescript-eslint/parser": "^5.40.0", - "eslint": "^8.25.0", - "eslint-plugin-react": "^7.31.10", "gh-pages": "^4.0.0", "immer": "^9.0.15", "make-plural": "^7.1.0", @@ -22231,10 +22228,6 @@ "@types/react": "^18.0.14", "@types/react-dom": "^18.0.5", "@types/vscode": "^1.72.0", - "@typescript-eslint/eslint-plugin": "^5.40.0", - "@typescript-eslint/parser": "^5.40.0", - "eslint": "^8.25.0", - "eslint-plugin-react": "^7.31.10", "gh-pages": "^4.0.0", "immer": "^9.0.15", "make-plural": "^7.1.0", diff --git a/package.json b/package.json index 20c2b480b..d49915953 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ci": "CI=true npm run check && CI=true npm run test", "precheck": "npm -w web run extract && npm -w web run lingui", "check": "npm run check:format && npm run check:types && npm run check:lint", - "clean": "rm -rf cli/build components/build extension/build projects/build runner/build simulator/build web", + "clean": "rm -rf cli/build components/build extension/build projects/build runner/build simulator/build web/build", "format": "prettier --write cli/src components/src extension/src projects/src runner/src simulator/src web/src web/public", "fix": "eslint --fix cli/src components/src extension/src projects/src runner/src simulator/src web/src web/public", "check:format": "prettier --ignore-unknown --check cli/src components/src extension/src projects/src runner/src simulator/src web/src web/public", @@ -36,6 +36,7 @@ "@typescript-eslint/parser": "^5.40.0", "esbuild": "^0.15.11", "eslint": "^8.25.0", + "eslint-plugin-react": "^7.31.10", "prettier": "^2.7.1", "typescript": "^4.8.4" }, diff --git a/simulator/src/languages/tst.test.ts b/simulator/src/languages/tst.test.ts index d0563d602..33a0671d3 100644 --- a/simulator/src/languages/tst.test.ts +++ b/simulator/src/languages/tst.test.ts @@ -463,7 +463,7 @@ describe("tst language", () => { start: 0, end: 21, }, - ops: [{ op: "load", file: "Max.hack" }], + ops: [{ op: "loadRom", file: "Max.hack" }], }, ], }); diff --git a/tsconfig.json b/tsconfig.json index 7430a607a..bf9e623b1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,11 @@ { "references": [ - { "path": "./cli/tsconfig.json" }, - { "path": "./components/tsconfig.json" }, - { "path": "./extension/tsconfig.json" }, { "path": "./projects/tsconfig.json" }, { "path": "./runner/tsconfig.json" }, { "path": "./simulator/tsconfig.json" }, + { "path": "./cli/tsconfig.json" }, + { "path": "./components/tsconfig.json" }, + { "path": "./extension/tsconfig.json" }, { "path": "./web/tsconfig.json" } ], "files": [] diff --git a/web/.eslintrc.json b/web/.eslintrc.json index 3871b4d70..31fccfd71 100644 --- a/web/.eslintrc.json +++ b/web/.eslintrc.json @@ -1,7 +1,9 @@ { "env": { "browser": true, - "es2021": true + "es2021": true, + "jest": true, + "node": true }, "extends": [ "eslint:recommended", diff --git a/web/package.json b/web/package.json index 9c8100d92..08504e024 100644 --- a/web/package.json +++ b/web/package.json @@ -25,10 +25,6 @@ "@types/react": "^18.0.14", "@types/react-dom": "^18.0.5", "@types/vscode": "^1.72.0", - "@typescript-eslint/eslint-plugin": "^5.40.0", - "@typescript-eslint/parser": "^5.40.0", - "eslint": "^8.25.0", - "eslint-plugin-react": "^7.31.10", "gh-pages": "^4.0.0", "immer": "^9.0.15", "make-plural": "^7.1.0", diff --git a/web/src/pages/home.tsx b/web/src/pages/home.tsx index be4f31f72..34d559d72 100644 --- a/web/src/pages/home.tsx +++ b/web/src/pages/home.tsx @@ -1,20 +1,15 @@ -import { Assignments } from "@computron5k/simulator/projects/index.js"; +import { useBaseContext } from "@computron5k/components/stores/base.context"; +import { DiffTable } from "@computron5k/components/difftable"; +import { Assignments } from "@computron5k/projects/index.js"; import { runTests } from "@computron5k/simulator/projects/runner.js"; import { Trans } from "@lingui/macro"; -import { ChangeEventHandler, useCallback, useContext, useState } from "react"; -import { AppContext } from "../App.context"; -import { DiffTable } from "../components/difftable"; - -function splitFile(file: File) { - const { name, ext } = file.name.match( - /(.*\/)?(?[^/]+)\.(?[^./]+)$/ - )?.groups as { name: string; ext: string }; - return { name, ext }; -} +import { ChangeEventHandler, useCallback, useState } from "react"; +import { parse, ParsedPath } from "node:path"; function hasTest({ name, ext }: { name: string; ext: string }) { return ( - Assignments[name as keyof typeof Assignments] !== undefined && ext === "hdl" + Assignments[name as keyof typeof Assignments] !== undefined && + ext === ".hdl" ); } @@ -42,20 +37,21 @@ const TestResult = (props: { ); -async function loadAssignment(pfile: Promise<{ name: string; hdl: string }>) { - const file = await pfile; +async function loadAssignment(file: ParsedPath & { file?: File }) { const assignment = Assignments[file.name as keyof typeof Assignments]; + const hdl = (await file.file?.text()) ?? ""; const tst = assignment[ `${file.name}.tst` as keyof typeof assignment ] as string; const cmp = assignment[ `${file.name}.cmp` as keyof typeof assignment ] as string; - return { ...file, tst, cmp }; + return { ...file, hdl, tst, cmp }; } declare module "react" { - interface HTMLAttributes extends AriaAttributes, DOMAttributes { + // eslint-disable-next-line + interface HTMLAttributes { // extends React's HTMLAttributes directory?: string; webkitdirectory?: string; @@ -66,27 +62,29 @@ const Home = () => { const [tests, setTests] = useState( [] as Array[0]> ); - const { fs } = useContext(AppContext); + const { fs } = useBaseContext(); const onChange = useCallback>( async ({ target }) => { - const files = [...(target.files ?? [])] - .map((file) => { - console.log(file.webkitRelativePath); - return file; - }) - .filter((file) => file.name.endsWith(".hdl")) - .map((file) => ({ file, ...splitFile(file) })) - .filter(hasTest) - .map(async (file) => { - const hdl = await file.file.text(); - return { ...file, hdl }; - }); + const files = await Promise.all( + [...(target.files ?? [])] + .map((file) => { + console.log(file.webkitRelativePath); + return file; + }) + .filter((file) => file.name.endsWith(".hdl")) + .map((file) => ({ ...parse(file.name), file })) + .filter(hasTest) + .map(async (file) => { + const hdl = await file.file.text(); + return { ...file, hdl }; + }) + ); - const tests = runTests(files, loadAssignment, fs); + const tests = await runTests(files, loadAssignment, fs, ""); fs.pushd("/samples"); - setTests(await Promise.all(tests)); + setTests(tests); fs.popd(); }, [setTests, fs] @@ -101,8 +99,8 @@ const Home = () => {