Skip to content

fix: parse multiline TypeScript function bodies#629

Open
treygoff24 wants to merge 1 commit into
peteromallet:mainfrom
treygoff24:fix/typescript-async-body-extraction
Open

fix: parse multiline TypeScript function bodies#629
treygoff24 wants to merge 1 commit into
peteromallet:mainfrom
treygoff24:fix/typescript-async-body-extraction

Conversation

@treygoff24

Copy link
Copy Markdown

Problem

The TypeScript async_no_await smell detector can report false positives for multiline async functions whose signatures contain braces before the function body, such as:

  • default object parameters (opts = {})
  • destructured parameters
  • return type object literals inside generics (Promise<{ ... }>)

The previous body extractor picked the first { within the signature window, so it inspected an empty/default/destructuring/type block instead of the real function body and missed real await expressions.

Fix

  • Find the actual function body brace while ignoring braces inside parameter lists and return-type syntax.
  • Reuse the existing block-end scanner once the body brace is found.
  • Add regressions for multiline exported async signatures and destructured parameters with Promise<{ ... }> return types.

Verification

  • uvx pytest desloppify/languages/typescript/tests/smells/test_ts_smell_helpers.py::TestDetectAsyncNoAwait desloppify/languages/typescript/tests/test_ts_smells.py::test_detect_async_no_await desloppify/languages/typescript/tests/test_ts_smells.py::test_async_with_await_not_flagged -q — passed
  • uvx pytest desloppify/languages/typescript/tests -q — passed, 428 tests
  • uvx ruff check desloppify/languages/typescript/detectors/smells/detector_core.py desloppify/languages/typescript/tests/smells/test_ts_smell_helpers.py — passed
  • Verified against /Users/treygoff/Code/elevenlabs-cli with PYTHONPATH=/tmp/desloppify-fix ... python -m desloppify scan --path .; false async/no-await findings dropped and objective score improved.

Note: uvx pytest desloppify/tests/ -q currently has 3 unrelated failures in desloppify/tests/lang/common/test_bash_unused_imports.py (bash source/dot-source unused import expectations returned no findings). These are unrelated to this TypeScript detector change.

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

Successfully merging this pull request may close these issues.

1 participant