diff --git a/.babelrc b/.babelrc deleted file mode 100644 index df011461b..000000000 --- a/.babelrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "presets": [ - "@babel/preset-react", - "@babel/preset-env", - "@babel/preset-typescript" - ], - "plugins": [ - "@babel/plugin-transform-runtime" - ] -} diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 0a937f351..000000000 --- a/.eslintrc +++ /dev/null @@ -1,31 +0,0 @@ -{ - "parser": "@typescript-eslint/parser", - "rules": { - "react/jsx-uses-react": "error", - "react/jsx-uses-vars": "error", - "react/react-in-jsx-scope": "error", - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": [ - "error", - { "vars": "all", "args": "none", "varsIgnorePattern": "^_" } - ], - "no-console": "off" - }, - "globals": { - "Generator": true - }, - "env": { - "es6": true, - "browser": true, - "node": true - }, - "extends": ["prettier"], - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module", - "ecmaFeatures": { - "jsx": true - } - }, - "plugins": ["react", "@typescript-eslint/eslint-plugin"] -} diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 000000000..aa5893a2b --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,36 @@ +module.exports = { + "root": true, + "parser": "@typescript-eslint/parser", + "ignorePatterns": ["dist", ".eslintrc.cjs"], + "env": { "browser": true, "es2020": true }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:react-hooks/recommended", + "prettier" + ], + "plugins": ["@typescript-eslint/eslint-plugin"], + "rules": { + // *** + // TODO: turn these rules on progressively + "prefer-const": "off", + "no-var": "off", + "react-hooks/exhaustive-deps": "off", + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/ban-ts-comment": "off", + // *** + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { "vars": "all", "args": "none", "varsIgnorePattern": "^_" } + ], + "no-console": "off" + }, + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module", + "project": ["./tsconfig.json", "./tsconfig.node.json"], + "tsconfigRootDir": __dirname, + } +} diff --git a/__mocks__/kinto-http.js b/__mocks__/kinto-http.ts similarity index 100% rename from __mocks__/kinto-http.js rename to __mocks__/kinto-http.ts diff --git a/package-lock.json b/package-lock.json index d64132edb..f3c24a617 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,8 +46,9 @@ "@typescript-eslint/parser": "^6.19.0", "@vitejs/plugin-react": "^4.2.1", "eslint": "^8.56.0", - "eslint-config-prettier": "^9.0.0", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react-hooks": "^4.6.0", "gh-pages": "^6.0.0", "prettier": "^3.0.2", "toctoc": "^0.4.0", @@ -3965,12 +3966,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/deep-equal/node_modules/isarray": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", - "dev": true - }, "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -4190,12 +4185,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/es-get-iterator/node_modules/isarray": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", - "dev": true - }, "node_modules/es-iterator-helpers": { "version": "1.0.15", "resolved": "https://registry.npmjs.org/es-iterator-helpers/-/es-iterator-helpers-1.0.15.tgz", @@ -4411,6 +4400,18 @@ "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8" } }, + "node_modules/eslint-plugin-react-hooks": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz", + "integrity": "sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==", + "dev": true, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" + } + }, "node_modules/eslint-plugin-react/node_modules/doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", @@ -5890,6 +5891,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/isarray": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", + "dev": true + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -7762,12 +7769,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/safe-array-concat/node_modules/isarray": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", - "dev": true - }, "node_modules/safe-regex-test": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.2.tgz", @@ -9021,12 +9022,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/which-builtin-type/node_modules/isarray": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", - "dev": true - }, "node_modules/which-collection": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/which-collection/-/which-collection-1.0.1.tgz", diff --git a/package.json b/package.json index 949328f13..e23d9fe18 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build:kinto-single": "ASSET_PATH=/v1/admin KINTO_ADMIN_SINGLE_SERVER=1 vite build", "cs-check": "prettier -l \"{src,test}/**/*.{js,jsx,ts,tsx}\"", "cs-format": "prettier \"{src,test}/**/*.{js,jsx,ts,tsx}\" --write", - "lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\" \"test/**/*.{js,jsx,ts,tsx}\"", + "lint": "eslint . --ext ts,tsx", "preview": "vite preview", "publish-to-gh-pages": "ASSET_PATH=/kinto-admin/ npm run build && gh-pages --add --dist build/", "start": "vite", @@ -61,8 +61,9 @@ "@typescript-eslint/parser": "^6.19.0", "@vitejs/plugin-react": "^4.2.1", "eslint": "^8.56.0", - "eslint-config-prettier": "^9.0.0", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react-hooks": "^4.6.0", "gh-pages": "^6.0.0", "prettier": "^3.0.2", "toctoc": "^0.4.0", diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index f76910dc5..000000000 --- a/test/.eslintrc +++ /dev/null @@ -1,16 +0,0 @@ -{ - "env": { - "mocha": true - }, - "globals": { - d: true - }, - "rules": { - "no-unused-vars": [ - 2, - { - "varsIgnorePattern": "^d$" - } - ] - } -} diff --git a/test/components/AuthForm_test.jsx b/test/components/AuthForm_test.tsx similarity index 100% rename from test/components/AuthForm_test.jsx rename to test/components/AuthForm_test.tsx diff --git a/test/components/BaseForm_test.jsx b/test/components/BaseForm_test.tsx similarity index 100% rename from test/components/BaseForm_test.jsx rename to test/components/BaseForm_test.tsx diff --git a/test/components/CollectionForm_test.jsx b/test/components/CollectionForm_test.tsx similarity index 100% rename from test/components/CollectionForm_test.jsx rename to test/components/CollectionForm_test.tsx diff --git a/test/components/CollectionRecords_test.jsx b/test/components/CollectionRecords_test.tsx similarity index 100% rename from test/components/CollectionRecords_test.jsx rename to test/components/CollectionRecords_test.tsx diff --git a/test/components/HistoryTable_test.jsx b/test/components/HistoryTable_test.tsx similarity index 100% rename from test/components/HistoryTable_test.jsx rename to test/components/HistoryTable_test.tsx diff --git a/test/components/Homepage_test.jsx b/test/components/Homepage_test.tsx similarity index 100% rename from test/components/Homepage_test.jsx rename to test/components/Homepage_test.tsx diff --git a/test/components/Layout_test.jsx b/test/components/Layout_test.tsx similarity index 100% rename from test/components/Layout_test.jsx rename to test/components/Layout_test.tsx diff --git a/test/components/Notifications_test.jsx b/test/components/Notifications_test.tsx similarity index 100% rename from test/components/Notifications_test.jsx rename to test/components/Notifications_test.tsx diff --git a/test/components/RecordAttributes_test.jsx b/test/components/RecordAttributes_test.tsx similarity index 100% rename from test/components/RecordAttributes_test.jsx rename to test/components/RecordAttributes_test.tsx diff --git a/test/components/RecordBulk_test.jsx b/test/components/RecordBulk_test.tsx similarity index 100% rename from test/components/RecordBulk_test.jsx rename to test/components/RecordBulk_test.tsx diff --git a/test/components/RecordCreate_test.jsx b/test/components/RecordCreate_test.tsx similarity index 100% rename from test/components/RecordCreate_test.jsx rename to test/components/RecordCreate_test.tsx diff --git a/test/components/Sidebar_test.jsx b/test/components/Sidebar_test.tsx similarity index 100% rename from test/components/Sidebar_test.jsx rename to test/components/Sidebar_test.tsx diff --git a/test/components/TagsField_test.jsx b/test/components/TagsField_test.tsx similarity index 100% rename from test/components/TagsField_test.jsx rename to test/components/TagsField_test.tsx diff --git a/test/components/bucket/CollectionDataList_test.jsx b/test/components/bucket/CollectionDataList_test.tsx similarity index 100% rename from test/components/bucket/CollectionDataList_test.jsx rename to test/components/bucket/CollectionDataList_test.tsx diff --git a/test/components/bucket/GroupDataList_test.jsx b/test/components/bucket/GroupDataList_test.tsx similarity index 100% rename from test/components/bucket/GroupDataList_test.jsx rename to test/components/bucket/GroupDataList_test.tsx diff --git a/test/components/record/JSONRecordForm_test.jsx b/test/components/record/JSONRecordForm_test.tsx similarity index 100% rename from test/components/record/JSONRecordForm_test.jsx rename to test/components/record/JSONRecordForm_test.tsx diff --git a/test/components/record/RecordForm_test.jsx b/test/components/record/RecordForm_test.tsx similarity index 100% rename from test/components/record/RecordForm_test.jsx rename to test/components/record/RecordForm_test.tsx diff --git a/test/components/record/RecordPermissions_test.jsx b/test/components/record/RecordPermissions_test.tsx similarity index 100% rename from test/components/record/RecordPermissions_test.jsx rename to test/components/record/RecordPermissions_test.tsx diff --git a/test/components/signoff/CommentDialog_test.jsx b/test/components/signoff/CommentDialog_test.tsx similarity index 100% rename from test/components/signoff/CommentDialog_test.jsx rename to test/components/signoff/CommentDialog_test.tsx diff --git a/test/components/signoff/SimpleReview/PerRecordDiffView_test.jsx b/test/components/signoff/SimpleReview/PerRecordDiffView_test.tsx similarity index 100% rename from test/components/signoff/SimpleReview/PerRecordDiffView_test.jsx rename to test/components/signoff/SimpleReview/PerRecordDiffView_test.tsx diff --git a/test/components/signoff/SimpleReview/SimpleReviewButtons_test.jsx b/test/components/signoff/SimpleReview/SimpleReviewButtons_test.tsx similarity index 89% rename from test/components/signoff/SimpleReview/SimpleReviewButtons_test.jsx rename to test/components/signoff/SimpleReview/SimpleReviewButtons_test.tsx index 34a9d090f..6152ec7b5 100644 --- a/test/components/signoff/SimpleReview/SimpleReviewButtons_test.jsx +++ b/test/components/signoff/SimpleReview/SimpleReviewButtons_test.tsx @@ -43,8 +43,9 @@ describe("SimpleReviewHeader component", () => { expect(await screen.findByTestId("spinner")).toBeDefined(); }); - it("should open CommentDialog when request review is clicked and call requestReview from modal", async () => { - const {} = renderButtons({ status: "work-in-progress" }); + it.skip("should open CommentDialog when request review is clicked and call requestReview from modal", async () => { + // TODO: What should this test do? + // const { } = renderButtons({ status: "work-in-progress" }); }); it("should display rollback button when status is wip and call rollbackChanges from modal", async () => { diff --git a/test/components/signoff/SimpleReview/SimpleReviewHeader_test.jsx b/test/components/signoff/SimpleReview/SimpleReviewHeader_test.tsx similarity index 100% rename from test/components/signoff/SimpleReview/SimpleReviewHeader_test.jsx rename to test/components/signoff/SimpleReview/SimpleReviewHeader_test.tsx diff --git a/test/components/signoff/SimpleReview/SimpleReview_test.jsx b/test/components/signoff/SimpleReview/SimpleReview_test.tsx similarity index 100% rename from test/components/signoff/SimpleReview/SimpleReview_test.jsx rename to test/components/signoff/SimpleReview/SimpleReview_test.tsx diff --git a/test/components/signoff/components_test.jsx b/test/components/signoff/components_test.tsx similarity index 100% rename from test/components/signoff/components_test.jsx rename to test/components/signoff/components_test.tsx diff --git a/test/hooks/storage_test.js b/test/hooks/storage_test.ts similarity index 100% rename from test/hooks/storage_test.js rename to test/hooks/storage_test.ts diff --git a/test/locationUtils_test.js b/test/locationUtils_test.ts similarity index 100% rename from test/locationUtils_test.js rename to test/locationUtils_test.ts diff --git a/test/permission_test.js b/test/permission_test.ts similarity index 100% rename from test/permission_test.js rename to test/permission_test.ts diff --git a/test/reducers/bucket_test.js b/test/reducers/bucket_test.ts similarity index 100% rename from test/reducers/bucket_test.js rename to test/reducers/bucket_test.ts diff --git a/test/reducers/collection_test.js b/test/reducers/collection_test.ts similarity index 100% rename from test/reducers/collection_test.js rename to test/reducers/collection_test.ts diff --git a/test/reducers/group_test.js b/test/reducers/group_test.ts similarity index 100% rename from test/reducers/group_test.js rename to test/reducers/group_test.ts diff --git a/test/reducers/notifications_test.js b/test/reducers/notifications_test.ts similarity index 100% rename from test/reducers/notifications_test.js rename to test/reducers/notifications_test.ts diff --git a/test/reducers/record_test.js b/test/reducers/record_test.ts similarity index 100% rename from test/reducers/record_test.js rename to test/reducers/record_test.ts diff --git a/test/reducers/servers_test.js b/test/reducers/servers_test.ts similarity index 100% rename from test/reducers/servers_test.js rename to test/reducers/servers_test.ts diff --git a/test/reducers/sessions_test.js b/test/reducers/sessions_test.ts similarity index 100% rename from test/reducers/sessions_test.js rename to test/reducers/sessions_test.ts diff --git a/test/routes_test.js b/test/routes_test.ts similarity index 100% rename from test/routes_test.js rename to test/routes_test.ts diff --git a/test/sagas/bucket_test.js b/test/sagas/bucket_test.ts similarity index 100% rename from test/sagas/bucket_test.js rename to test/sagas/bucket_test.ts diff --git a/test/sagas/collection_test.js b/test/sagas/collection_test.ts similarity index 100% rename from test/sagas/collection_test.js rename to test/sagas/collection_test.ts diff --git a/test/sagas/group_test.js b/test/sagas/group_test.ts similarity index 100% rename from test/sagas/group_test.js rename to test/sagas/group_test.ts diff --git a/test/sagas/index_test.js b/test/sagas/index_test.ts similarity index 100% rename from test/sagas/index_test.js rename to test/sagas/index_test.ts diff --git a/test/sagas/record_test.js b/test/sagas/record_test.ts similarity index 100% rename from test/sagas/record_test.js rename to test/sagas/record_test.ts diff --git a/test/sagas/route_test.js b/test/sagas/route_test.ts similarity index 100% rename from test/sagas/route_test.js rename to test/sagas/route_test.ts diff --git a/test/sagas/session_test.js b/test/sagas/session_test.ts similarity index 100% rename from test/sagas/session_test.js rename to test/sagas/session_test.ts diff --git a/test/sagas/signoff_test.js b/test/sagas/signoff_test.ts similarity index 100% rename from test/sagas/signoff_test.js rename to test/sagas/signoff_test.ts diff --git a/test/setupTests.js b/test/setupTests.ts similarity index 100% rename from test/setupTests.js rename to test/setupTests.ts diff --git a/test/store/localStore_test.js b/test/store/localStore_test.ts similarity index 100% rename from test/store/localStore_test.js rename to test/store/localStore_test.ts diff --git a/test/url_test.js b/test/url_test.ts similarity index 100% rename from test/url_test.js rename to test/url_test.ts diff --git a/test/utils_test.js b/test/utils_test.ts similarity index 100% rename from test/utils_test.js rename to test/utils_test.ts diff --git a/tsconfig.json b/tsconfig.json index be5392bf5..77d430ab9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,14 @@ { "compilerOptions": { - "target": "ES2020", + "target": "ESNext", "useDefineForClassFields": true, - "lib": ["ES2020", "DOM", "DOM.Iterable", "esnext"], - "module": "esnext", + "lib": ["ESNext", "DOM", "DOM.Iterable"], + "module": "ESNext", "skipLibCheck": true, "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, + "types": ["vitest/globals"], "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", @@ -16,19 +17,8 @@ "forceConsistentCasingInFileNames": true, "experimentalDecorators": true, "declaration": true, - "allowJs": false, - + "allowJs": false, }, - "ts-node": { - "compilerOptions": { - "sourceMap": true, - "composite": true, - "skipLibCheck": true, - "module": "ESNext", - "moduleResolution": "bundler", - "allowSyntheticDefaultImports": true - }, - "include": ["vite.config.ts"] - }, - "include": ["./src/"] + "include": ["src", "test", "__mocks__"], + "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 000000000..7eaa45583 --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,11 @@ + { + "compilerOptions": { + "sourceMap": true, + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] + } diff --git a/vite.config.ts b/vite.config.ts index 9817bd7e9..c47296626 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -28,6 +28,6 @@ export default defineConfig({ globals: true, environment: "jsdom", include: ["**/*_{test,spec}.?(c|m)[jt]s?(x)"], - setupFiles: ["test/setupTests.js"] + setupFiles: ["test/setupTests.ts"] } })