From 70a8f8d518816e67988531a73f41945c5d4d2d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Smestad?= Date: Thu, 7 Sep 2023 16:05:29 +0200 Subject: [PATCH] Add specific configs for: * Unit tests * Cypress * Typescript definition files * Node files --- index.js | 55 +++++++++++++++++++++++ package-lock.json | 111 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 + 3 files changed, 166 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ebbe358..9736e73 100644 --- a/index.js +++ b/index.js @@ -7,12 +7,15 @@ import typedReduxSagaPlugin from '@jambit/eslint-plugin-typed-redux-saga'; import tsPlugin from '@typescript-eslint/eslint-plugin'; import tsParser from '@typescript-eslint/parser'; import eslintConfigPrettier from 'eslint-config-prettier'; +import cypress from 'eslint-plugin-cypress'; import importPlugin from 'eslint-plugin-import'; import istanbul from 'eslint-plugin-istanbul'; +import noOnlyTestsPlugin from 'eslint-plugin-no-only-tests'; import prettier from 'eslint-plugin-prettier'; import sortDestructureKeysPlugin from 'eslint-plugin-sort-destructure-keys'; import sortKeysFixPlugin from 'eslint-plugin-sort-keys-fix'; import tsSortKeysPlugin from 'eslint-plugin-typescript-sort-keys'; +import vitest from 'eslint-plugin-vitest'; import globals from 'globals'; // mimic CommonJS variables -- not needed if using CommonJS @@ -329,4 +332,56 @@ export default [ }, }, }, + // Cypress + { + files: ['**/*.cy.ts'], + languageOptions: { + globals: cypress.environments.globals.globals, + }, + plugins: { + cypress, + 'no-only-tests': noOnlyTestsPlugin, + }, + rules: { + ...cypress.configs.recommended.rules, + 'cypress/no-force': 'error', + 'cypress/unsafe-to-chain-command': 'warn', + 'no-only-tests/no-only-tests': 'error', + }, + }, + // For unit tests + { + files: ['**/*.test.ts', '**/*.test.tsx', '__mocks__/**/*.ts'], + ignores: ['**/*.auto.test.tsx'], + languageOptions: { + // @ts-expect-error + globals: vitest.environments.env.globals, + }, + plugins: { vitest }, + rules: { + // @ts-expect-error + ...vitest.configs.recommended.rules, + 'vitest/prefer-to-be': 'off', + 'vitest/prefer-todo': 'error', + }, + }, + // Typescript type definitions + { + files: ['**/*.d.ts'], + rules: { + '@typescript-eslint/consistent-type-definitions': 'off', + 'no-var': 'off', + 'one-var': 'off', + 'vars-on-top': 'off', + }, + }, + // For Node.js scripts + { + files: ['**/scripts/*'], + languageOptions: { + globals: { + ...globals.node, + }, + }, + }, ]; diff --git a/package-lock.json b/package-lock.json index 85e21af..0a53379 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,8 +23,9 @@ "eslint-config-xo": "0.43.1", "eslint-config-xo-react": "0.27.0", "eslint-config-xo-typescript": "1.0.1", - "eslint-plugin-import": "2.28.1", + "eslint-plugin-cypress": "^2.14.0", "eslint-plugin-istanbul": "0.1.2", + "eslint-plugin-no-only-tests": "^3.1.0", "eslint-plugin-prettier": "5.0.0", "eslint-plugin-react": "7.33.2", "eslint-plugin-react-hooks": "4.6.0", @@ -44,6 +45,8 @@ "@types/eslint__js": "^8.42.0", "@types/eslint-config-prettier": "^6.11.0", "ava": "^5.3.1", + "eslint-import-resolver-typescript": "^3.6.0", + "eslint-plugin-import": "^2.28.1", "is-plain-obj": "^4.1.0", "patch-package": "^8.0.0", "temp-write": "^5.0.0" @@ -692,6 +695,7 @@ }, "node_modules/@types/json5": { "version": "0.0.29", + "dev": true, "license": "MIT" }, "node_modules/@types/node": { @@ -1198,6 +1202,7 @@ }, "node_modules/array.prototype.findlastindex": { "version": "1.2.3", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -2145,6 +2150,19 @@ "dev": true, "license": "MIT" }, + "node_modules/enhanced-resolve": { + "version": "5.15.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz", + "integrity": "sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.4", + "tapable": "^2.2.0" + }, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/error-ex": { "version": "1.3.2", "license": "MIT", @@ -2422,6 +2440,7 @@ }, "node_modules/eslint-import-resolver-node": { "version": "0.3.9", + "dev": true, "license": "MIT", "dependencies": { "debug": "^3.2.7", @@ -2431,13 +2450,40 @@ }, "node_modules/eslint-import-resolver-node/node_modules/debug": { "version": "3.2.7", + "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.1" } }, + "node_modules/eslint-import-resolver-typescript": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.6.0.tgz", + "integrity": "sha512-QTHR9ddNnn35RTxlaEnx2gCxqFlF2SEN0SE2d17SqwyM7YOSI2GHWRYp5BiRkObTUNYPupC/3Fq2a0PpT+EKpg==", + "dev": true, + "dependencies": { + "debug": "^4.3.4", + "enhanced-resolve": "^5.12.0", + "eslint-module-utils": "^2.7.4", + "fast-glob": "^3.3.1", + "get-tsconfig": "^4.5.0", + "is-core-module": "^2.11.0", + "is-glob": "^4.0.3" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts/projects/eslint-import-resolver-ts" + }, + "peerDependencies": { + "eslint": "*", + "eslint-plugin-import": "*" + } + }, "node_modules/eslint-module-utils": { "version": "2.8.0", + "dev": true, "license": "MIT", "dependencies": { "debug": "^3.2.7" @@ -2453,14 +2499,28 @@ }, "node_modules/eslint-module-utils/node_modules/debug": { "version": "3.2.7", + "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.1" } }, + "node_modules/eslint-plugin-cypress": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-cypress/-/eslint-plugin-cypress-2.14.0.tgz", + "integrity": "sha512-eW6tv7iIg7xujleAJX4Ujm649Bf5jweqa4ObPEIuueYRyLZt7qXGWhCY/n4bfeFW/j6nQZwbIBHKZt6EKcL/cg==", + "dependencies": { + "globals": "^13.20.0" + }, + "peerDependencies": { + "eslint": ">= 3.2.1" + } + }, "node_modules/eslint-plugin-import": { "version": "2.28.1", - "license": "MIT", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.28.1.tgz", + "integrity": "sha512-9I9hFlITvOV55alzoKBI+K9q74kv0iKMeY6av5+umsNwayt59fz692daGyjR+oStBQgx6nwR9rXldDev3Clw+A==", + "dev": true, "dependencies": { "array-includes": "^3.1.6", "array.prototype.findlastindex": "^1.2.2", @@ -2489,6 +2549,7 @@ }, "node_modules/eslint-plugin-import/node_modules/debug": { "version": "3.2.7", + "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.1" @@ -2496,6 +2557,7 @@ }, "node_modules/eslint-plugin-import/node_modules/semver": { "version": "6.3.1", + "dev": true, "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -2553,6 +2615,14 @@ "semver": "bin/semver.js" } }, + "node_modules/eslint-plugin-no-only-tests": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-no-only-tests/-/eslint-plugin-no-only-tests-3.1.0.tgz", + "integrity": "sha512-Lf4YW/bL6Un1R6A76pRZyE1dl1vr31G/ev8UzIc/geCgFWyrKil8hVjYqWVKGB/UIGmb6Slzs9T0wNezdSVegw==", + "engines": { + "node": ">=5.0.0" + } + }, "node_modules/eslint-plugin-prettier": { "version": "5.0.0", "license": "MIT", @@ -3249,6 +3319,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-tsconfig": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.7.0.tgz", + "integrity": "sha512-pmjiZ7xtB8URYm74PlGJozDNyhvsVLUcpBa8DZBG3bWHwaHa9bPiRpiSfovw+fjhwONSCWKRyk+JQHEGZmMrzw==", + "dev": true, + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, "node_modules/glob": { "version": "7.2.3", "license": "ISC", @@ -4239,6 +4321,7 @@ }, "node_modules/minimist": { "version": "1.2.8", + "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -4256,6 +4339,7 @@ }, "node_modules/ms": { "version": "2.1.3", + "dev": true, "license": "MIT" }, "node_modules/nanoid": { @@ -4391,6 +4475,7 @@ }, "node_modules/object.groupby": { "version": "1.0.1", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -5098,6 +5183,7 @@ }, "node_modules/resolve": { "version": "1.22.4", + "devOptional": true, "license": "MIT", "dependencies": { "is-core-module": "^2.13.0", @@ -5137,6 +5223,15 @@ "node": ">=4" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/reusify": { "version": "1.0.4", "license": "MIT", @@ -5538,6 +5633,7 @@ }, "node_modules/strip-bom": { "version": "3.0.0", + "dev": true, "license": "MIT", "engines": { "node": ">=4" @@ -5666,6 +5762,15 @@ "url": "https://opencollective.com/unts" } }, + "node_modules/tapable": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", + "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/temp-dir": { "version": "2.0.0", "dev": true, @@ -5772,6 +5877,7 @@ }, "node_modules/tsconfig-paths": { "version": "3.14.2", + "dev": true, "license": "MIT", "dependencies": { "@types/json5": "^0.0.29", @@ -5782,6 +5888,7 @@ }, "node_modules/tsconfig-paths/node_modules/json5": { "version": "1.0.2", + "dev": true, "license": "MIT", "dependencies": { "minimist": "^1.2.0" diff --git a/package.json b/package.json index fef6c6c..9dbe901 100644 --- a/package.json +++ b/package.json @@ -71,9 +71,11 @@ "eslint-config-xo": "0.43.1", "eslint-config-xo-react": "0.27.0", "eslint-config-xo-typescript": "1.0.1", + "eslint-plugin-cypress": "^2.14.0", "eslint-import-resolver-typescript": "^3.6.0", "eslint-plugin-import": "^2.28.1", "eslint-plugin-istanbul": "0.1.2", + "eslint-plugin-no-only-tests": "^3.1.0", "eslint-plugin-prettier": "5.0.0", "eslint-plugin-react": "7.33.2", "eslint-plugin-react-hooks": "4.6.0",