You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parenthesized chained assertions not detected as unsafe_double_type_assertion #27
When a chained assertion is wrapped in parentheses — such as (value as unknown) as any — the detector does not classify it as unsafe_double_type_assertion. Instead it falls through to the generic single-assertion branch (or produces a different finding), because the outer AsExpression.expression is a ParenthesizedExpression, not an AsExpression.
Evidence
Reported by CodeRabbit review on PR #24 (commit 3a9b942): the visitor checks ts.isAsExpression(node.expression) which fails for parenthesized chains.
// This pattern is NOT detected as a chained assertion:constx=(valueasunknown)asany;// AST: AsExpression → ParenthesizedExpression → AsExpression
Removing the parentheses makes it detectable:
// This pattern IS detected as a chained assertion:constx=valueasunknownasany;
Requirements
(value as X) as Y must be classified as unsafe_double_type_assertion with assertionForm: chained_as.
(value as X) as any must produce both unsafe_double_type_assertion and unsafe_type_assertion independently.
((value as X) as Y) as Z (nested parens) must still be detected.
Non-chained parenthesized expressions must not be affected.
Existing chain-count tests must continue to pass.
Constraints
Do not change finding types or severity.
Do not affect non-chained single assertions.
Do not modify suppression behavior.
Do not exceed the existing per-AST-node finding-count semantics.
Do not add dependencies.
Validation
Add tests (RED before fix, GREEN after) for:
(value as X) as Y → 1 finding, unsafe_double_type_assertion
(value as unknown) as any → 2 findings (double + any)
((value as X) as Y) as Z → 2 findings
(value) as any (unnecessary parens around expression, not chain) → 1 finding unsafe_type_assertion
(value as X) as Y as Z → 2 findings (outer chain + inner chain)
#9 - fix: resolve all false positives (issues #2, #6, #7, #8) [closed] #23 - feat: detect unsafe TypeScript type assertions via AST (issue #22) [open] #24 - feat: migrate unsafe_type_assertion from regex to AST detection [open]
📝 Issue Planner
Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.
Create Plan
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
💬 Have feedback or questions? Drop into our discord!
Activity
coderabbitai commentedon Jul 27, 2026
🔗 Related PRs
#9 - fix: resolve all false positives (issues
#2,#6,#7,#8) [closed]#23 - feat: detect unsafe TypeScript type assertions via AST (issue
#22) [open]#24 - feat: migrate unsafe_type_assertion from regex to AST detection [open]
📝 Issue Planner
Check the box below or use the
@coderabbitai plancommand to generate an implementation plan and prompts that you can use with your favorite coding assistant.🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!