Add include_variables option to non_optional_string_data_conversion rule#6172
Merged
SimplyDanny merged 1 commit intomainfrom Aug 2, 2025
Merged
Add include_variables option to non_optional_string_data_conversion rule#6172SimplyDanny merged 1 commit intomainfrom
include_variables option to non_optional_string_data_conversion rule#6172SimplyDanny merged 1 commit intomainfrom
Conversation
Copilot
AI
changed the title
[WIP]
Add Aug 1, 2025
non_optional_string_data_conversion does not trigger with non-literal stringsinclude_variables option to non_optional_string_data_conversion rule
Generated by 🚫 Danger |
SimplyDanny
requested changes
Aug 1, 2025
Collaborator
SimplyDanny
left a comment
There was a problem hiding this comment.
Add a changelog entry to CHANGELOG.md to let users know about the new option and its behavior.
Source/SwiftLintBuiltInRules/Rules/Lint/NonOptionalStringDataConversionRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Lint/NonOptionalStringDataConversionRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Lint/NonOptionalStringDataConversionRule.swift
Outdated
Show resolved
Hide resolved
Contributor
Author
Added changelog entry to the Enhancements section documenting the new |
SimplyDanny
reviewed
Aug 1, 2025
Tests/BuiltInRulesTests/NonOptionalStringDataConversionRuleTests.swift
Outdated
Show resolved
Hide resolved
d9b9463 to
e468e33
Compare
SimplyDanny
approved these changes
Aug 1, 2025
e468e33 to
3bd308c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
non_optional_string_data_conversionrule was previously limited to only triggering on string literals like"foo".data(using: .utf8), but would not catch variable usage likestringVariable.data(using: .utf8).This PR adds an optional
include_variablesconfiguration option (default:false) that allows the rule to also trigger on variables, properties, function calls, and other non-literal expressions when enabled.Changes Made
NonOptionalStringDataConversionConfigurationin a separate file withinclude_variables: falseby defaultUsage
Default behavior (unchanged for backward compatibility):
With
include_variablesenabled:This addresses the maintainer's suggestion in the issue comments to add an optional feature for variable checking while balancing false positive concerns.
Fixes #6094.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.