Repository navigation
Define JavaScript/JSX coverage contract for unsafe_type_assertion #28
Copy link
Copy link
Open
Labels
questionFurther information is requestedFurther information is requested
Description
Finding
The AST migration (PR #24) removed the regex-based unsafe_type_assertion pattern and replaced it with a never-match sentinel (/(?!)/). The AST detection in findUnsafeAssertions() only runs for .ts and .tsx file extensions. Since the regex path is also skipped for .js and .jsx, those targets no longer produce unsafe_type_assertion findings.
However:
AISlopDetector.targetExtensionsincludes.jsand.jsx.- Standard JavaScript does not support TypeScript
asassertion syntax, so detectingas anyin.jsfiles via AST is not valid. - The old regex path would have detected
as anyin.jsfiles, which may have produced false positives in JavaScript codebases whereasis a valid identifier.
Open Questions (Need Decision)
-
Is
.js/.jsxsupport forunsafe_type_assertionintentional?- If yes: find equivalent detection (parser/compatibility layer) that handles whatever subset is valid.
- If no: remove
.js/.jsxfrom the supported scope for this pattern and document the boundary.
-
If JS/JSX support is removed, should it be removed for all AST-based patterns or only
unsafe_type_assertion?unsafe_double_type_assertion,unsafe_object_assertion,unsafe_array_assertionall share the same AST-gate and would have the same issue.
Evidence
ai-slop-detector.ts:1031-1036— regex path skipsunsafe_type_assertionfor all extensions.ai-slop-detector.ts:178—findUnsafeAssertionsaccepts only.tsand.tsxscript kinds.targetExtensions— includes.js,.jsx,.ts,.tsx.
Requirements (apply after decision)
If JS/JSX support is kept:
.jsand.jsxfiles must detect the sameas anypatterns as.ts/.tsxor produce equivalent behavior.- No false positives for standard JavaScript
askeyword usage.
If JS/JSX support is dropped:
unsafe_type_assertionmust be explicitly documented as TypeScript/TSX-only.- Target extension documentation must reflect this boundary.
- The regex sentinel must remain a never-match (no change needed).
Constraints
- Do not reintroduce regex detection for
unsafe_type_assertionwithout proving it does not create false positives. - Do not change extension handling for patterns unrelated to assertion detection.
- Do not modify
findUnsafeAssertionsto accept JavaScript script kinds without verifying it handles the syntax differences correctly.
Validation
- Reproduce behavior for
.jsand.jsxagainst the merged PR baseline. - Document the reproduction result in this issue.
- Based on the decision:
- Implement and test the chosen path.
- Or document the decision and close without implementation.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested
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!