From 3057b7d6c2f27bbb67631e8be69a16f9a86e2767 Mon Sep 17 00:00:00 2001 From: Ryan Ling Date: Tue, 23 Apr 2024 09:47:33 +1000 Subject: [PATCH] Revert to `eslint-plugin-cypress` (#141) --- .changeset/famous-cobras-join.md | 10 ++++ base.js | 16 +----- package.json | 6 +- pnpm-lock.yaml | 40 +++++++------ rules/unsafe-to-chain-command.js | 96 -------------------------------- 5 files changed, 34 insertions(+), 134 deletions(-) create mode 100644 .changeset/famous-cobras-join.md delete mode 100644 rules/unsafe-to-chain-command.js diff --git a/.changeset/famous-cobras-join.md b/.changeset/famous-cobras-join.md new file mode 100644 index 0000000..8862bbd --- /dev/null +++ b/.changeset/famous-cobras-join.md @@ -0,0 +1,10 @@ +--- +'eslint-config-seek': patch +--- + +Revert from [`@finsit/eslint-plugin-cypress`] back to [`eslint-plugin-cypress`] + +The official plugin now supports ESLint v8. Consumers that were overriding `@finsit/cypress/*` rules will need to override `cypress/*` rules instead. + +[`@finsit/eslint-plugin-cypress`]: https://github.com/foretagsplatsen/eslint-plugin-cypress +[`eslint-plugin-cypress`]: https://github.com/cypress-io/eslint-plugin-cypress diff --git a/base.js b/base.js index 4e9502b..83c9863 100644 --- a/base.js +++ b/base.js @@ -1,12 +1,8 @@ -const path = require('path'); const root = require('find-root')(process.cwd()); const OFF = 0; const ERROR = 2; -const rulesDirPlugin = require('eslint-plugin-rulesdir'); -rulesDirPlugin.RULES_DIR = path.join(__dirname, 'rules'); - const baseRules = { // Possible Errors 'no-console': ERROR, @@ -218,17 +214,11 @@ const baseConfig = { { // Cypress config files: [`**/cypress/**/*.{${allExtensions}}`], - // eslint-plugin-cypress doesn't support ESLint v8. - // Use fork by `@finsit` until this is solved. - // https://github.com/cypress-io/eslint-plugin-cypress/issues/89 - extends: ['plugin:@finsit/cypress/recommended'], + extends: ['plugin:cypress/recommended'], env: { - '@finsit/cypress/globals': true, - }, - plugins: ['@finsit/cypress', 'rulesdir'], - rules: { - 'rulesdir/unsafe-to-chain-command': ERROR, + 'cypress/globals': true, }, + plugins: ['cypress'], }, ], }; diff --git a/package.json b/package.json index 74679e3..fa8ccca 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,7 @@ "files": [ "index.js", "base.js", - "extensions.js", - "rules/*" + "extensions.js" ], "repository": { "type": "git", @@ -28,7 +27,7 @@ "@babel/core": "^7.22.6", "@babel/eslint-parser": "^7.22.6", "@babel/preset-react": "^7.22.5", - "@finsit/eslint-plugin-cypress": "^3.1.1", + "eslint-plugin-cypress": "^3.0.0", "@typescript-eslint/eslint-plugin": "^7.2.0", "@typescript-eslint/parser": "^7.2.0", "eslint-config-prettier": "^8.8.0", @@ -37,7 +36,6 @@ "eslint-plugin-jest": "^27.9.0", "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-rulesdir": "^0.2.2", "find-root": "^1.1.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad9e0e6..39bdb7e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,9 +14,6 @@ dependencies: '@babel/preset-react': specifier: ^7.22.5 version: 7.22.5(@babel/core@7.22.6) - '@finsit/eslint-plugin-cypress': - specifier: ^3.1.1 - version: 3.1.1(eslint@8.57.0) '@typescript-eslint/eslint-plugin': specifier: ^7.2.0 version: 7.2.0(@typescript-eslint/parser@7.2.0)(eslint@8.57.0)(typescript@5.4.2) @@ -29,6 +26,9 @@ dependencies: eslint-import-resolver-typescript: specifier: 3.5.5 version: 3.5.5(@typescript-eslint/parser@7.2.0)(eslint-plugin-import@2.27.5)(eslint@8.57.0) + eslint-plugin-cypress: + specifier: ^3.0.0 + version: 3.0.0(eslint@8.57.0) eslint-plugin-import: specifier: ^2.27.5 version: 2.27.5(@typescript-eslint/parser@7.2.0)(eslint-import-resolver-typescript@3.5.5)(eslint@8.57.0) @@ -41,9 +41,6 @@ dependencies: eslint-plugin-react-hooks: specifier: ^4.6.0 version: 4.6.0(eslint@8.57.0) - eslint-plugin-rulesdir: - specifier: ^0.2.2 - version: 0.2.2 find-root: specifier: ^1.1.0 version: 1.1.0 @@ -663,16 +660,6 @@ packages: resolution: {integrity: sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - /@finsit/eslint-plugin-cypress@3.1.1(eslint@8.57.0): - resolution: {integrity: sha512-cowFcoYNYOjg/yxKlQ7f26uiGl7FK2Sksvo0KaBnRF0EZbIJTv3apSRLB1RqaTg1N5bhLL9EpVwXqXRpcICNQg==} - engines: {node: '>=8.10.0'} - peerDependencies: - eslint: '>= 7.0.0' - dependencies: - eslint: 8.57.0 - globals: 13.19.0 - dev: false - /@humanwhocodes/config-array@0.11.14: resolution: {integrity: sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==} engines: {node: '>=10.10.0'} @@ -1541,6 +1528,15 @@ packages: - supports-color dev: false + /eslint-plugin-cypress@3.0.0(eslint@8.57.0): + resolution: {integrity: sha512-ZQ0l8+fcWDYptaxLkmk2l77TAfmJqNM2SSbC6t9+P/GeMLOu2zq2jtJKsHh+qxZEzkm/5IfFgbwAU3P5AZf7+w==} + peerDependencies: + eslint: '>=7 <9' + dependencies: + eslint: 8.57.0 + globals: 13.24.0 + dev: false + /eslint-plugin-import@2.27.5(@typescript-eslint/parser@7.2.0)(eslint-import-resolver-typescript@3.5.5)(eslint@8.57.0): resolution: {integrity: sha512-LmEt3GVofgiGuiE+ORpnvP+kAm3h6MLZJ4Q5HCyHADofsb4VzXFsRiWj3c0OFiV+3DWFh0qg3v9gcPlfc3zRow==} engines: {node: '>=4'} @@ -1628,11 +1624,6 @@ packages: string.prototype.matchall: 4.0.8 dev: false - /eslint-plugin-rulesdir@0.2.2: - resolution: {integrity: sha512-qhBtmrWgehAIQeMDJ+Q+PnOz1DWUZMPeVrI0wE9NZtnpIMFUfh3aPKFYt2saeMSemZRrvUtjWfYwepsC8X+mjQ==} - engines: {node: '>=4.0.0'} - dev: false - /eslint-scope@5.1.1: resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==} engines: {node: '>=8.0.0'} @@ -1926,6 +1917,13 @@ packages: dependencies: type-fest: 0.20.2 + /globals@13.24.0: + resolution: {integrity: sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==} + engines: {node: '>=8'} + dependencies: + type-fest: 0.20.2 + dev: false + /globalyzer@0.1.0: resolution: {integrity: sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==} dev: false diff --git a/rules/unsafe-to-chain-command.js b/rules/unsafe-to-chain-command.js deleted file mode 100644 index db3beed..0000000 --- a/rules/unsafe-to-chain-command.js +++ /dev/null @@ -1,96 +0,0 @@ -/** This rule was copied from the original `eslint-plugin-cypress` so we can use the fork (which - * supports eslint 8) while having the same recommended rules as the upstream - * https://github.com/foretagsplatsen/eslint-plugin-cypress - * https://github.com/cypress-io/eslint-plugin-cypress/blob/c626ad543f65babf1def5caabd1bc9bb9900d2c7/lib/rules/unsafe-to-chain-command.js - */ -// eslint-disable-next-line strict -'use strict'; - -/** @type {import("eslint").Rule.RuleModule} */ -module.exports = { - meta: { - type: 'problem', - docs: { - description: 'Actions should be at the end of chains, not in the middle', - category: 'Possible Errors', - recommended: true, - url: 'https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle', - }, - schema: [], - fixable: 'code', - messages: { - unexpected: - 'It is unsafe to chain further commands that rely on the subject after this command. It is best to split the chain, chaining again from `cy.` in the next command.', - }, - }, - create(context) { - return { - CallExpression(node) { - if ( - isRootCypress(node) && - isActionUnsafeToChain(node) && - node.parent.type === 'MemberExpression' - ) { - context.report({ - node, - messageId: 'unexpected', - }); - } - }, - }; - }, -}; - -/** @param {import("eslint").Rule.Node} node */ -function isRootCypress(node) { - while (node.type === 'CallExpression') { - if (node.callee.type !== 'MemberExpression') { - return false; - } - - if ( - node.callee.object.type === 'Identifier' && - node.callee.object.name === 'cy' - ) { - return true; - } - - // eslint-disable-next-line no-param-reassign - node = node.callee.object; - } - - return false; -} - -/** @param {import("eslint").Rule.Node} node */ -function isActionUnsafeToChain(node) { - // commands listed in the documentation with text: 'It is unsafe to chain further commands that rely on the subject after xxx' - const unsafeToChainActions = [ - 'blur', - 'clear', - 'click', - 'check', - 'dblclick', - 'each', - 'focus', - 'rightclick', - 'screenshot', - 'scrollIntoView', - 'scrollTo', - 'select', - 'selectFile', - 'spread', - 'submit', - 'type', - 'trigger', - 'uncheck', - 'within', - ]; - - return ( - node.callee && - node.callee.property && - node.callee.property.type === 'Identifier' && - unsafeToChainActions.includes(node.callee.property.name) - ); -}