Skip to content

Bug: explicit_self false positive with string interpolation #6611

Closed

Description

@jffmrk

New Issue Checklist

Bug Description

The explicit_self analyzer rule reports a violation (“Instance variables and functions should be explicitly accessed with self.”) even when the member is already accessed with self. inside string interpolation \(...) (and the same pattern with raw-string interpolation \#(...)).

Expected: No violation; self is explicit.

Actual: explicit_self reports a violation (false positive).

explicit_self only runs with swiftlint analyze (compiler invocations required), not swiftlint lint.

Minimal example:

class StringInterpolation {
    let foo = "foo"

    var description: String {
        return "StringInterpolation{foo: \(self.foo)}"
    }

    var rawStringLiteral: String {
        return #"StringInterpolation{foo: \#(self.foo)} using "raw" string literals."#
    }
}

Full repro (Swift package, xcodebuild log + analyze): https://github.com/jffmrk/swiftlint-explicit-self-string-interpolation

Example command output:

$ swiftlint analyze --compiler-log-path xcodebuild.log
Analyzing 'StringInterpolation.swift' (1/1)
/Users/jmark/src/github/swiftlint-explicit-self-string-interpolation/Sources/ExplicitSelfStringInterpolationBug/StringInterpolation.swift:5:43: error: Explicit Self Violation: Instance variables and functions should be explicitly accessed with 'self.' (explicit_self)
/Users/jmark/src/github/swiftlint-explicit-self-string-interpolation/Sources/ExplicitSelfStringInterpolationBug/StringInterpolation.swift:9:45: error: Explicit Self Violation: Instance variables and functions should be explicitly accessed with 'self.' (explicit_self)

(Line/column may vary slightly by Swift/Xcode version.)

Environment

  • SwiftLint version (run swiftlint version to be sure): 0.63.2
  • Xcode version (run xcodebuild -version to be sure): Xcode 26.4 (Build version 17E192)
  • Installation method used (Homebrew, CocoaPods, building from source, etc): Homebrew (/opt/homebrew/bin/swiftlint)
  • Configuration file:
analyzer_rules:
  - explicit_self

explicit_self:
  severity: error

Are you using nested configurations? No — single .swiftlint.yml at the repository root.

Activity

  1. jffmrk commented on Apr 19, 2026

    @jffmrk
    ContributorAuthor

    We just enabled explicit_self on our repo, and a lot of false positives showed up under string interpolation.

    PR with a fix:
    #6610

  2. added
    bug
    on May 24, 2026
  3. self-assigned this
    on May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions