Skip to content

Fix explicit_self false positives around string interpolation#6610

Open
jffmrk wants to merge 1 commit intorealm:mainfrom
jffmrk:fix-explicit-self-string-interpolation
Open

Fix explicit_self false positives around string interpolation#6610
jffmrk wants to merge 1 commit intorealm:mainfrom
jffmrk:fix-explicit-self-string-interpolation

Conversation

@jffmrk
Copy link
Copy Markdown

@jffmrk jffmrk commented Apr 18, 2026

Summary

SourceKit can report misleading instance-member refs for explicit_self when code uses string literals and \(...) interpolation (e.g. literal text that matches a property name, or bogus offsets at the interpolation open paren).

This PR filters those cases using SwiftSyntax static string segments, skips offsets at \(, and verifies explicit self.` spans in source text.

Fixes #6611

Testing

  • swift test --filter ExplicitSelfRuleGeneratedTests

Made with Cursor

@SwiftLintBot
Copy link
Copy Markdown

SwiftLintBot commented Apr 18, 2026

1 Warning
⚠️ This PR may need tests.
19 Messages
📖 Building this branch resulted in a binary size of 27624.77 KiB vs 27621.7 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.82 s vs 0.83 s on main (1% faster).
📖 Linting Alamofire with this PR took 1.04 s vs 1.06 s on main (1% faster).
📖 Linting Brave with this PR took 7.4 s vs 7.4 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 28.55 s vs 28.58 s on main (0% faster).
📖 Linting Firefox with this PR took 12.32 s vs 12.37 s on main (0% faster).
📖 Linting Kickstarter with this PR took 8.54 s vs 8.56 s on main (0% faster).
📖 Linting Moya with this PR took 0.45 s vs 0.46 s on main (2% faster).
📖 Linting NetNewsWire with this PR took 2.64 s vs 2.64 s on main (0% slower).
📖 Linting Nimble with this PR took 0.67 s vs 0.69 s on main (2% faster).
📖 Linting PocketCasts with this PR took 7.93 s vs 8.14 s on main (2% faster).
📖 Linting Quick with this PR took 0.46 s vs 0.46 s on main (0% slower).
📖 Linting Realm with this PR took 2.97 s vs 3.08 s on main (3% faster).
📖 Linting Sourcery with this PR took 1.91 s vs 1.9 s on main (0% slower).
📖 Linting Swift with this PR took 4.81 s vs 4.78 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 0.35 s vs 0.35 s on main (0% slower).
📖 Linting VLC with this PR took 1.25 s vs 1.22 s on main (2% slower).
📖 Linting Wire with this PR took 19.17 s vs 19.22 s on main (0% faster).
📖 Linting WordPress with this PR took 12.93 s vs 12.95 s on main (0% faster).

Generated by 🚫 Danger

@jffmrk jffmrk marked this pull request as draft April 18, 2026 21:06
@jffmrk jffmrk force-pushed the fix-explicit-self-string-interpolation branch from 01f0fc8 to cedcca5 Compare April 19, 2026 00:36
@jffmrk jffmrk changed the title Fix explicit_self false positives around string interpolation Fix explicit_self false positives around string interpolation Apr 19, 2026
@jffmrk jffmrk marked this pull request as ready for review April 19, 2026 00:38
@jffmrk jffmrk marked this pull request as draft April 19, 2026 23:11
@jffmrk jffmrk force-pushed the fix-explicit-self-string-interpolation branch from f5e32b7 to 6dfa8fc Compare April 20, 2026 01:23
SourceKit can report instance-member refs for text inside string literals, at
the open paren of \(...), or with offsets that do not match a simple '.' check.
Combine SwiftSyntax static segment ranges with source-text verification for
explicit self.<member> spans, and skip bogus offsets at string interpolation
open parens.

Add non-triggering, triggering, and correction examples for implicit member
access inside string interpolation.
@jffmrk jffmrk force-pushed the fix-explicit-self-string-interpolation branch from 6dfa8fc to 12dd5f5 Compare April 20, 2026 01:29
@jffmrk jffmrk marked this pull request as ready for review April 20, 2026 01:29
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.

Bug: explicit_self false positive with string interpolation

2 participants