You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
optional_data_string_conversion does not trigger when .init(decoding:as:) is called instead of String(decoding:as:) #6359
enhancementIdeas for improvements of existing features and rules.good first issueIssue to be taken up by new contributors yet unfamiliar with the project.
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:
lettext=String(decoding:data,as:UTF8.self)
// This does not trigger a violation:
lettext: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
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).
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.
enhancementIdeas for improvements of existing features and rules.good first issueIssue to be taken up by new contributors yet unfamiliar with the project.
Activity
SimplyDanny commentedon Nov 27, 2025
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 toString.init(decoding: data, as: UTF8.self).Support String.init and .init syntax in optional_data_string_conversion
theamodhshetty commentedon Feb 24, 2026
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.
theamodhshetty commentedon Mar 30, 2026
Opened #6567. This extends
optional_data_string_conversionto catch the equivalentString.init(decoding:as:)and contextual.init(decoding:as:)spellings, so they get the same treatment as the existingString(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.