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
When using the code below, SwiftLint 0.57.0 reports an error like this
Optional Data -> String Conversion Violation: Prefer failable String(data:encoding:) initializer when converting Data to String (optional_data_string_conversion)
but following the advice leads to Value of optional type 'String?' must be unwrapped to a value of type 'String'.
// This triggers a violation:vardescription:String{do{letdata=tryencode()returnString(decoding: data, as:UTF8.self)}catch{return error.message.description
}}
Mention the command or other SwiftLint integration method that caused the issue. Include stack traces or command output.
None
Environment
SwiftLint version (run swiftlint version to be sure) 0.57.0
Xcode version (run xcodebuild -version to be sure) Xcode 16.2 Build version 16B5100e
Installation method used (Homebrew, CocoaPods, building from source, etc) Homebrew
Configuration file:
disabled_rules:
opt_in_rules:
- collection_alignment#- conditional_returns_on_newline
- convenience_type
- empty_count
- empty_string
- fallthrough
- fatal_error_message
- file_header
- file_name
- file_name_no_space
- first_where
- flatmap_over_map_reduce
- for_where
- force_unwrapping
- identical_operands
- implicit_return
- implicitly_unwrapped_optional
- is_disjoint
- joined_default_parameter
- legacy_multiple
- legacy_random
- last_where
- lower_acl_than_parent
- modifier_order
- multiline_parameters
- overridden_super_call
- prefixed_toplevel_constant
- prefer_zero_over_explicit_init
- private_action
- private_outlet
- static_operator
- strict_fileprivate
- toggle_bool#- trailing_closure
- unavailable_function
- unowned_variable_capture
- unneeded_parentheses_in_closure_argument
- untyped_error_in_catch
- yoda_conditionanalyzer_rules:
- unused_declaration
- unused_importexcluded: # paths to ignore during linting.
- Frameworks
- Products
- Recovered References
- Carthage
- packages/*/Package.swift
- Packages/*/Package.swift
- packages/*/Tests/
- Packages/*/Tests/# Default rule configurationcyclomatic_complexity:
ignores_case_statements: trueempty_count:
only_after_dot: truefunction_parameter_count: 6function_body_length: 80identifier_name:
allowed_symbols: _ # Is used for private property definitionsmax_length: 50excluded:
- id
- at
- on
- to
- cc
- i
- ok
- no
- qa
- ID
- xl
- d1
- d2
- tr
- vc
- up
- bylarge_tuple: # warn user when using 4 values in tuple, give error if there are 5
- 3line_length: 200nesting:
type_level: 3type_body_length: 270type_name:
max_length: 60excluded:
- AX
- LS# Opt-in rule configurationfile_name:
excluded:
- "BundleConfig_Root.swift"
- "BundleConfig_Root+Extension.swift"
- "BundleConfig_Insurance.swift"
- "BundleConfig_Insurance+Extension.swift"file_header:
required_pattern: | \/\/ \/\/ Copyright \(c\) *******\. All rights reserved\. \/\/
Are you using nested configurations? If so, paste their
relative paths and respective contents.
The text was updated successfully, but these errors were encountered:
That's the idea of the rule. It asks you to use the failable initializer to make you think about the error case. Your current code will just fail at runtime in case data cannot be converted.
SimplyDanny
added
the
discussion
Topics that cannot be categorized as bugs or enhancements yet. They require further discussions.
label
Nov 3, 2024
New Issue Checklist
Bug Description
When using the code below, SwiftLint 0.57.0 reports an error like this
Optional Data -> String Conversion Violation: Prefer failable
String(data:encoding:)
initializer when convertingData
toString
(optional_data_string_conversion)but following the advice leads to Value of optional type 'String?' must be unwrapped to a value of type 'String'.
Mention the command or other SwiftLint integration method that caused the issue. Include stack traces or command output.
None
Environment
swiftlint version
to be sure) 0.57.0xcodebuild -version
to be sure) Xcode 16.2 Build version 16B5100eAre you using nested configurations? If so, paste their
relative paths and respective contents.
The text was updated successfully, but these errors were encountered: