Skip to content

optional_data_string_conversion does not trigger when .init(decoding:as:) is called instead of String(decoding:as:) #6359

Closed

Description

@zenfty

New Issue Checklist

Bug Description

As the title suggests, optional_data_string_conversion does not trigger when calling String.init() instead of directly calling String().

Example:

// This triggers a violation:
let text = String(decoding: data, as: UTF8.self)

// This does not trigger a violation:
let text: String = .init(decoding: data, as: UTF8.self)

(swiftlint is in its default configuration, ran by xcode)

Environment

  • SwiftLint version — 0.62.2
  • Xcode version — 26.1 (17B55)
  • Installation method used (Homebrew, CocoaPods, building from source, etc)
  • Configuration file:
# n/a?

Are you using nested configurations? If so, paste their
relative paths and respective contents.
N/A

Activity

  1. SimplyDanny commented on Nov 27, 2025

    @SimplyDanny
    Collaborator

    This could be supported. However, I'd hide it behind an option since we cannot be 100% sure that .init(decoding: data, as: UTF8.self) refers to String.init(decoding: data, as: UTF8.self).

  2. added
    enhancement
    good first issue
    on Nov 27, 2025
  3. added a commit that references this issue on Feb 13, 2026
    ea44b87
  4. theamodhshetty commented on Feb 24, 2026

    @theamodhshetty
    Contributor

    Implemented this in #6508.

    I added include_shorthand_init (default false) so shorthand .init(decoding:as:) can be linted when desired, while avoiding ambiguous cases by default.

  5. theamodhshetty commented on Mar 30, 2026

    @theamodhshetty
    Contributor

    Opened #6567. This extends optional_data_string_conversion to catch the equivalent String.init(decoding:as:) and contextual .init(decoding:as:) spellings, so they get the same treatment as the existing String(decoding:as:) case. I also added explicit examples for both forms and ran the generated rule test plus a strict lint pass on the touched files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions