Skip to content

Bug: explicit_self false positive with string interpolation #6611

@jffmrk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions