pi-lens
Version:
Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo
61 lines (50 loc) • 1.44 kB
YAML
id: mixed-async-styles
name: Mixed Async/Await and Promise Chains
severity: warning
category: style
defect_class: async-misuse
inline_tier: warning
language: typescript
message: "Mixed async/await + promise chains — use consistent async style"
description: |
Mixing async/await with .then()/.catch() chains in the same function
is confusing and inconsistent. Choose one style per function.
✅ FIXES:
1. Convert all to async/await (preferred)
2. Convert all to promise chains (if needed for specific control flow)
query: |
(function_declaration
"async"
body: (statement_block) @BODY)
(arrow_function
"async"
body: (statement_block) @BODY)
(method_definition
"async"
body: (statement_block) @BODY)
(function_expression
"async"
body: (statement_block) @BODY)
# Post-filter: Check if body contains both await and .then()
post_filter: has_mixed_async
metavars:
- BODY
tags:
- style
- async
- consistency
examples:
bad: |
async function getUser() {
const response = await fetch('/api/user');
return response.json().then(data => data.name); // Mixed!
}
good: |
async function getUser() {
const response = await fetch('/api/user');
const data = await response.json(); // Consistent async/await
return data.name;
}
has_fix: false