Skip to content

🐛 BUG: return outside of function with @typescript-eslint/no-misused-promises rule causes ESLint crash #451

@evangirardin

Description

@evangirardin

Describe the Bug

If the @typescript-eslint/no-misused-promises rule is enabled in ESLint, a statement like return Astro.redirect('/404'); in the frontmatter will cause ESLint to crash. I'm assuming this might be related to the workaround implemented in #336. Sorry if this a problem with a package other than prettier-plugin-astro, I can't really tell for sure, I just suspect it might be a symptom of a problem with that PR.

Oops! Something went wrong! :(

ESLint: 9.39.1

Error: Non-null Assertion Failed: Expected node to have a parent.
Occurred while linting [project]/src/pages/index.astro:14
Rule: "@typescript-eslint/no-misused-promises"
    at nullThrows [project]/node_modules/@typescript-eslint/utils/dist/eslint-utils/nullThrows.js:18:15)
    at [project]/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-promises.js:462:46
    at checkReturnStatement ([project]/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-misused-promises.js:463:15)
    at ruleErrorHandler ([project]/node_modules/eslint/lib/linter/linter.js:1173:33)
    at [project]/node_modules/eslint/lib/linter/source-code-visitor.js:76:46
    at Array.forEach (<anonymous>)
    at SourceCodeVisitor.callSync ([project]/node_modules/eslint/lib/linter/source-code-visitor.js:76:30)
    at [project]/node_modules/eslint/lib/linter/source-code-traverser.js:291:18
    at Array.forEach (<anonymous>)
    at SourceCodeTraverser.traverseSync ([project]/node_modules/eslint/lib/linter/source-code-traverser.js:290:10)

Steps to Reproduce

  1. Install typescript-eslint, eslint-plugin-prettier, and prettier-plugin-astro
  2. Write an eslint.config.js with @typescript-eslint/no-misused-promises set to 'error'
  3. Try to lint the following page:
---
return Astro.redirect('/404');
---
  1. ESLint crashes :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions