-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reverse Data -> String conversion rule #5601
base: main
Are you sure you want to change the base?
Reverse Data -> String conversion rule #5601
Conversation
8f22541
to
6bca4f2
Compare
6bca4f2
to
f0d657d
Compare
Source/SwiftLintBuiltInRules/Rules/Lint/OptionalDataStringConversionRule.swift
Outdated
Show resolved
Hide resolved
…ersionRule.swift Co-authored-by: Ben P. <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than some nits on formulation and style, this looks good and reasonable to me. Thank you for taking immediate (re)action on the comments in the original PR!
@@ -10,7 +10,10 @@ | |||
|
|||
#### Enhancements | |||
|
|||
* None. | |||
* Add new `optional_data_string_conversion` rule to enforce | |||
failable conversions of `Data` -> UTF-8 `String`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please append two spaces to the end of the description. They are required to enforce a line break in the rendered Markdown.
* Revert `optional_data_string_conversion` enforcing | ||
non-failable conversions of `Data` -> UTF-8 `String`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Revert `optional_data_string_conversion` enforcing | |
non-failable conversions of `Data` -> UTF-8 `String`. | |
* Revert the part of the `non_optional_string_data_conversion` | |
rule that enforces non-failable conversions of `Data` -> UTF-8 | |
`String`. This is due to the fact that the data to be converted | |
can be arbitrary and especially doesn't need to represent a valid | |
UTF-8-encoded string. |
Please append two spaces to the end of the description. They are required to enforce a line break in the rendered Markdown.
Also, this should go into the "Breaking" section.
@@ -5,16 +5,14 @@ struct NonOptionalStringDataConversionRule: Rule { | |||
var configuration = SeverityConfiguration<Self>(.warning) | |||
static let description = RuleDescription( | |||
identifier: "non_optional_string_data_conversion", | |||
name: "Non-Optional String <-> Data Conversion", | |||
description: "Prefer using UTF-8 encoded strings when converting between `String` and `Data`", | |||
name: "Non-Optional String -> Data Conversion", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: "Non-Optional String -> Data Conversion", | |
name: "Non-optional String -> Data Conversion", |
name: "Non-Optional String <-> Data Conversion", | ||
description: "Prefer using UTF-8 encoded strings when converting between `String` and `Data`", | ||
name: "Non-Optional String -> Data Conversion", | ||
description: "Prefer using non-optional Data(_:) when converting a UTF-8 String to Data", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: "Prefer using non-optional Data(_:) when converting a UTF-8 String to Data", | |
description: "Prefer non-optional `Data(_:)` initializer when converting `String` to `Data`", |
static let description = RuleDescription( | ||
identifier: "optional_data_string_conversion", | ||
name: "Optional Data -> String Conversion", | ||
description: "Prefer using failable String(data:encoding:) when converting from `Data` to a UTF-8 `String`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: "Prefer using failable String(data:encoding:) when converting from `Data` to a UTF-8 `String`", | |
description: "Prefer failable `String(data:encoding:)` initializer when converting `Data` to `String`", |
Please run |
This reverses the Data -> String portion of this PR by introducing a new rule, following feedback on the original issue. It leaves the String -> Data portion of the original rule unchanged.