Skip to content

line_length: ignores_urls strips property accesses like post.id (NSDataDetector matches bare domains with valid TLDs) #6811

Description

@AlexNsbmr

New Issue Checklist

Bug Report

line_length with ignores_urls: true silently skips lines containing ordinary property accesses like post.id or user.name, because NSDataDetector recognizes them as links (.id, .name, .info, … are valid TLDs).

Complete output when running SwiftLint, including the stack trace and command used

$ cat Repro.swift
// Both lines are exactly 124 characters long. Only the second one is reported.
        guard let response = try? await qoqaService2.performRequest(GetUserBookmarkRequest(postId: post.id)) else { return }
        guard let response = try? await qoqaService2.performRequest(GetUserBookmarkRequest(postId: postXid)) else { return }
$ cat .swiftlint.yml
line_length:
  ignores_urls: true

$ swiftlint lint --no-cache Repro.swift
Repro.swift:3:1: warning: Line Length Violation: Line should be 120 characters or less; currently it has 124 characters (line_length)

Line 2 (post.id) produces no violation; line 3 (postXid), identical in length, is flagged.

Environment

  • SwiftLint version: 0.65.0
  • Xcode version: 26.x
  • Installation method used: Homebrew
  • Configuration file: see above (ignores_urls: true is the only relevant option)

Root cause

String.strippingURLs in LineLengthRule.swift uses NSDataDetector(types: .link) and removes every match before measuring the line:

https://github.com/realm/SwiftLint/blob/main/Source/SwiftLintBuiltInRules/Rules/Metrics/LineLengthRule.swift

NSDataDetector intentionally matches bare domains such as example.com — but in Swift source, member accesses like post.id, user.name or offer.info have the same shape (identifier.validTLD), so they are stripped too. In a codebase using ignores_urls: true, any over-long line that happens to contain such an expression passes the rule.

Possible fix

Only strip matches that look like actual URLs, e.g. require a scheme (match.url?.scheme != nil and not the implicit http NSDataDetector adds to bare domains), or require the match to contain :// / start with www.. The Linux regex path already roughly does this by requiring a scheme, www., or a trailing /.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions