Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'promise/catch-or-return' matches incorrectly with Cypress #180

Open
GodOfGrandeur opened this issue Jan 27, 2020 · 4 comments
Open

'promise/catch-or-return' matches incorrectly with Cypress #180

GodOfGrandeur opened this issue Jan 27, 2020 · 4 comments

Comments

@GodOfGrandeur
Copy link

GodOfGrandeur commented Jan 27, 2020

Description

When using the rule promise/catch-or-return you get a error with Cypress because they have a then method.

https://docs.cypress.io/api/commands/then.html#Syntax

Steps to Reproduce

  1. Create repo with this module and Cypress installed
  2. Create integration file where you make use of then method. (see docs)

Expected behavior:
Need a way to exclude this since this isn't actually a promise.

Actual behavior:
This line is marked as needing a catch added but this isn't a promise.

Versions

  • Node version: v10.16.2
  • ESLint version: v5.3.0
  • eslint-plugin-promise version: v4.2.1

Additional Information

Not sure why the library thinks this is a promise but it shouldn't.

@vadimyen
Copy link

vadimyen commented Jul 20, 2020

+1, I got the same trouble, so I manually add specific exceptions to overrides block

@xjamundx
Copy link
Contributor

xjamundx commented Jul 20, 2020

  1. The reason it gets confused is because eslint doesn't run the code or have any idea on the actual types, it has to use heuristics to guess and the best one to use is if there's a method called .then()

  2. The Cypress docs say .then() is modeled identically to the way Promises work in JavaScript.

  3. Eslint already provides a way to disable a rule per file using /* eslint-disable promise/catch-or-return*/

  4. You can also disable per-folder (such as your testing folder) with a custom eslintrc.js file

That all being said....is the parent variable always called something like cy. If that's the case it would be possible to exclude it.

@vadimyen
Copy link

vadimyen commented Jul 21, 2020

AFAIK and according to the docs, there's always the top-level global variable named cy in Cypress method chaining

@bmaupin
Copy link

bmaupin commented Mar 30, 2023

The promise/always-return is also incorrectly matched. I added rules overrides in my eslint config to disable them just for Cypress, e.g.:

  "overrides": [
    {
      "extends": ["plugin:cypress/recommended"],
      "files": ["cypress.config.ts", "cypress/**/*.ts"],
      "parserOptions": {
        "project": ["cypress/tsconfig.json"]
      },
      "rules": {
        "promise/always-return": "off",
        "promise/catch-or-return": "off"
      }
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants