From d22709e5c323b1943cc80ec5e9ee34c2631ff0ed Mon Sep 17 00:00:00 2001 From: Shamiul Mowla Date: Fri, 6 Dec 2024 13:37:15 -0500 Subject: [PATCH] Update the eslint rules and fix the vitest config. --- eslint.config.mjs | 60 +++++-------------- package.json | 6 +- .../setConsent/createSetConsent.spec.js | 2 +- .../createInstanceManager.spec.js | 2 +- vitest.config.js => vitest.config.mjs | 4 +- 5 files changed, 21 insertions(+), 53 deletions(-) rename vitest.config.js => vitest.config.mjs (94%) diff --git a/eslint.config.mjs b/eslint.config.mjs index 1e39a333..72c08882 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -35,21 +35,6 @@ export default [ plugins: { "unused-imports": unusedImports, }, - settings: { - "import/resolver": { - alias: { - map: [ - ["@src", "./src"], - ["@test", "./test"] - ], - extensions: [".js", ".jsx", ".mjs"] - }, - node: { - extensions: [".js", ".jsx", ".mjs"], - paths: [path.resolve(__dirname)] - } - } - }, languageOptions: { parser: babelParser, parserOptions: { @@ -61,16 +46,8 @@ export default [ globals: { ...globals.browser, ...globals.node, - describe: true, - it: true, - expect: true, - beforeAll: true, - beforeEach: true, - afterAll: true, - afterEach: true, - vi: true, + fixture: true, test: true, - fixture: true }, }, rules: { @@ -97,10 +74,12 @@ export default [ controlComponents: ["WrappedField"], }, ], + // Has been deprecated in favor of label-has-associated-control "jsx-a11y/label-has-for": "off", - "import/no-extraneous-dependencies": ["error", { - "devDependencies": ["**/*.test.js", "**/*.spec.js", "**/vitest.config.js", "**/test/**/*"] - }], + // Turning this off allows us to import devDependencies in our build tools. + // We enable the rule in src/.eslintrc.js since that's the only place we + // want to disallow importing extraneous dependencies. + "import/no-extraneous-dependencies": "off", "prefer-destructuring": "off", "import/prefer-default-export": "off", "no-console": [ @@ -109,6 +88,13 @@ export default [ allow: ["error"], }, ], + // This rule typically shows an error if a Link component + // doesn't have an href. We use React-Spectrum's Link + // component, however, which doesn't have an href prop + // (Link expects a anchor element as a child). We have + // to provide an empty components array here to get around + // eslint complaining about this. eslint still checks + // anchor elements though. "jsx-a11y/anchor-is-valid": [ "error", { @@ -126,29 +112,11 @@ export default [ 2, { namedComponents: "arrow-function" }, ], + "import/no-named-as-default-member": "off", "import/no-named-as-default": "off", - "import/no-unresolved": ["error", { - "ignore": ["vitest", "vitest/config"] - }] }, }, - { - files: ["test/**/*.{js,jsx,mjs}"], - languageOptions: { - globals: { - describe: true, - it: true, - expect: true, - beforeAll: true, - beforeEach: true, - afterAll: true, - afterEach: true, - vi: true, - test: true - } - } - }, { files: ["src/**/*.{mjs,js,jsx}"], languageOptions: { diff --git a/package.json b/package.json index baef161b..398d4443 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,10 @@ "prepare": "husky", "prepush-msg": "echo 'Running pre-push scripts...' && exit 0", "sandbox": "./scripts/buildExtensionManifest.mjs && reactor-sandbox", - "test:unit": "vitest --config ./vitest.config.js run", - "test:watch": "vitest --config ./vitest.config.js", + "test:unit": "vitest --config ./vitest.config.mjs run", + "test:watch": "vitest --config ./vitest.config.mjs", "test:coverage": "vitest run --coverage", - "test:unit:watch:chrome": "vitest --config ./vitest.config.js --environment jsdom", + "test:unit:watch:chrome": "vitest --config ./vitest.config.mjs --environment jsdom", "test:functional": "npm run build && testcafe chrome --esm test/functional/specs", "test:functional:component": "npm run build:componentFixtures && testcafe --esm chrome test/functional/specs/component", "test:functional:runtime": "npm-run-all -p build:alloy build:lib && testcafe --esm chrome test/functional/specs/runtime", diff --git a/test/unit/lib/actions/setConsent/createSetConsent.spec.js b/test/unit/lib/actions/setConsent/createSetConsent.spec.js index 440f4073..523d9094 100644 --- a/test/unit/lib/actions/setConsent/createSetConsent.spec.js +++ b/test/unit/lib/actions/setConsent/createSetConsent.spec.js @@ -11,7 +11,7 @@ governing permissions and limitations under the License. */ import { describe, it, expect, vi } from "vitest"; -import createSetConsent from "@src/lib/actions/setConsent/createSetConsent"; +import createSetConsent from "../../../../../src/lib/actions/setConsent/createSetConsent"; describe("Set Consent", () => { ["in", "out"].forEach((generalConsent) => { diff --git a/test/unit/lib/instanceManager/createInstanceManager.spec.js b/test/unit/lib/instanceManager/createInstanceManager.spec.js index c2c57eb0..70340d91 100644 --- a/test/unit/lib/instanceManager/createInstanceManager.spec.js +++ b/test/unit/lib/instanceManager/createInstanceManager.spec.js @@ -11,7 +11,7 @@ governing permissions and limitations under the License. */ import { describe, it, expect, beforeEach, vi } from "vitest"; -import createInstanceManager from "@src/lib/instanceManager/createInstanceManager"; +import createInstanceManager from "../../../../src/lib/instanceManager/createInstanceManager"; describe("Instance Manager", () => { let instanceManager; diff --git a/vitest.config.js b/vitest.config.mjs similarity index 94% rename from vitest.config.js rename to vitest.config.mjs index 6ecb7e89..0d88708b 100644 --- a/vitest.config.js +++ b/vitest.config.mjs @@ -1,4 +1,4 @@ -import { defineConfig } from "vitest/config"; +import { defineConfig } from "vitest/dist/config.js"; import react from "@vitejs/plugin-react"; import path from "path"; import { fileURLToPath } from "url"; @@ -40,4 +40,4 @@ export default defineConfig({ web: [/\.[jt]sx?$/], }, }, -}); +}); \ No newline at end of file