Skip to content

no-nesting: false positives when nested references vars in closure #123

@gabmontes

Description

@gabmontes

Description

Avoid nesting promises is truly desirable but there are some scenarios when un-nesting is not possible. One of such scenarios is when the inner promise uses variables created in an outer promise function and, therefore, exist in that function closure.

Steps to Reproduce

Let's consider the following case:

const exportFullPost = id => getPost(id)
  .then(post => getComments(post.url)
             // ^^^ "Avoid nesting promises" warning is shown here
    .then(comms => exportPost(id, post, comms))
  )

Expected behavior: Since exportPost needs the post object, it cannot be un-nested and the rule should not have been triggered. In fact, un-nesting would lead to an error condition:

module.exports = id => getPost(id)
  .then(post => getComments(post.url))
  .then(comms => exportPost(id, post, comms))
                             // ^^^ "'post' is not defined"

Actual behavior: The rule should have detected the usage of a variable in the closure and should have not triggered.

Versions

  • ESLint version: 4.19.0
  • eslint-plugin-promise version: 3.7.0

Additional Information

The "export posts with comments" is just an example to force the problem and show the scenario where this rule is not conveniently defined.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions