Skip to content

JS-1116 Fix S4335 FP on intersections with {} in generic type patterns#6339

Merged
ss-vibe-bot[bot] merged 4 commits intomasterfrom
fix/JS-1116-fix-fp-on-s4335-intersections-with--in-generic-type-manipulation-patterns-opus
Feb 6, 2026
Merged

JS-1116 Fix S4335 FP on intersections with {} in generic type patterns#6339
ss-vibe-bot[bot] merged 4 commits intomasterfrom
fix/JS-1116-fix-fp-on-s4335-intersections-with--in-generic-type-manipulation-patterns-opus

Conversation

@ss-vibe-bot
Copy link
Contributor

@ss-vibe-bot ss-vibe-bot bot commented Feb 6, 2026

Summary

Fix false positives in rule S4335 where intersections with {} in generic type manipulation patterns were incorrectly flagged as useless. Patterns like T & {}, GenericType<T> & {}, and { [K in keyof T]: T[K] } & {} are legitimate TypeScript idioms for type normalization and non-nullability constraints.

Changes

  • Add isGenericTypePattern check that exempts mapped types, generic type references with type arguments, and type parameter references from being flagged when intersected with {}
  • Use the TypeScript type checker (isTypeParameter) instead of name-based heuristics for more accurate type parameter detection
  • Add test cases covering: Simplify/Prettify mapped type patterns, generic type references with type arguments, interface property positions with generics, and reversed {} & GenericType order
  • Move ExtendedProps<T> = SomeProps<T> & {} from invalid to valid test cases
  • Sync expected ruling files (ant-design generateRangePicker.tsx no longer raises an issue for RangePickerProps<DateType> & {})

Relates to JS-1116

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

Ruling Report

Code no longer flagged (1 issue)

S4335

ant-design/components/date-picker/generatePicker/generateRangePicker.tsx:25

    23 |   generateConfig: GenerateConfig<DateType>,
    24 | ): PickerComponentClass<RangePickerProps<DateType>> {
>   25 |   type InternalRangePickerProps = RangePickerProps<DateType> & {};
    26 | 
    27 |   const RangePicker = forwardRef<

@ss-vibe-bot
Copy link
Contributor Author

ss-vibe-bot bot commented Feb 6, 2026

github-actions[bot] 2026-02-06T15:02:54Z addressed
This ruling change is expected. The pattern RangePickerProps<DateType> & {} at line 25 of generateRangePicker.tsx is a generic type reference with type arguments intersected with {} — exactly one of the patterns the fix exempts (Pattern 2 in the algorithm: TSTypeReference with type arguments). The expected ruling files were already synced in commit 2b4a393.

@ss-vibe-bot ss-vibe-bot bot marked this pull request as ready for review February 6, 2026 15:14
@francois-mora-sonarsource
Copy link
Contributor

LGTM

@francois-mora-sonarsource francois-mora-sonarsource requested a review from a team February 6, 2026 15:25
@ss-vibe-bot ss-vibe-bot bot force-pushed the fix/JS-1116-fix-fp-on-s4335-intersections-with--in-generic-type-manipulation-patterns-opus branch from 2b4a393 to 0f2f958 Compare February 6, 2026 15:33
@ss-vibe-bot
Copy link
Contributor Author

ss-vibe-bot bot commented Feb 6, 2026

francois-mora-sonarsource 2026-02-06T15:24:42Z addressed
Thanks for the review!

@ss-vibe-bot ss-vibe-bot bot force-pushed the fix/JS-1116-fix-fp-on-s4335-intersections-with--in-generic-type-manipulation-patterns-opus branch from 0f2f958 to 2f6bca8 Compare February 6, 2026 16:03
Vibe Bot and others added 4 commits February 6, 2026 16:33
Tests cover the scenario where intersections with {} in generic type
manipulation patterns are incorrectly flagged as useless. Added valid
test cases for: Simplify/Prettify mapped type pattern, generic type
references with type arguments, interface property position with
generics, and reversed {} & GenericType order. Moved the
ExtendedProps<T> = SomeProps<T> & {} case from invalid to valid.

Relates to JS-1116
Add exception for intersections with {} when used with generic types.
Patterns like T & {}, GenericType<T> & {}, and { [K in keyof T]: T[K] } & {}
are legitimate TypeScript idioms for type normalization and non-nullability
constraints. The new isGenericTypePattern check exempts mapped types, generic
type references with type arguments, and type parameter references.

Implementation follows the approved proposal algorithm with an improvement:
Pattern 3 uses the TypeScript type checker (isTypeParameter) instead of a
name-based heuristic for more accurate type parameter detection.

Relates to JS-1116
Ruling analysis confirmed the implementation is correct: the single
ruling entry (ant-design generateRangePicker.tsx) correctly no longer
raises an issue for `RangePickerProps<DateType> & {}`, which is a
legitimate generic type reference pattern.

Added a test case for generic type references with `& {}` inside a
function body, where the type parameter comes from the enclosing
function rather than the type alias itself.
Ticket: JS-1116

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ss-vibe-bot ss-vibe-bot bot force-pushed the fix/JS-1116-fix-fp-on-s4335-intersections-with--in-generic-type-manipulation-patterns-opus branch from 2f6bca8 to 8181912 Compare February 6, 2026 16:33
Copy link
Contributor

@francois-mora-sonarsource francois-mora-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sonarqube-next
Copy link

sonarqube-next bot commented Feb 6, 2026

@ss-vibe-bot ss-vibe-bot bot merged commit c0dba2c into master Feb 6, 2026
41 checks passed
@ss-vibe-bot ss-vibe-bot bot deleted the fix/JS-1116-fix-fp-on-s4335-intersections-with--in-generic-type-manipulation-patterns-opus branch February 6, 2026 16:51
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