-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add new invisible_characters rule #6424
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
base: main
Are you sure you want to change the base?
Conversation
01a6b0a to
21d78ba
Compare
Generated by 🚫 Danger |
3561c44 to
a89ae33
Compare
|
@SimplyDanny please review. I don't check NULL control character: \u0000 because it gets lost when copypasting so it's almost impossible to have it in string literals by accident. |
9382226 to
ceccd1d
Compare
SimplyDanny
left a comment
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.
Thanks for the contribution!
I wonder if this rule should catch even more characters of this kind, some maybe optionally. We could check what other linters do.
Source/SwiftLintBuiltInRules/Rules/Lint/InvisibleCharactersRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Lint/InvisibleCharactersRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Lint/InvisibleCharacterRule.swift
Outdated
Show resolved
Hide resolved
3a37574 to
708d32e
Compare
|
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.
Would it be wrong to have the rule auto-correct the findings by just removing the violating characters?
We could also think about making the rule configurable, so that people can add their own characters with descriptions. That's what the "tool" you cited allows as well.
Source/SwiftLintBuiltInRules/Rules/Lint/InvisibleCharacterRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Lint/InvisibleCharacterRule.swift
Outdated
Show resolved
Hide resolved
708d32e to
09b260e
Compare
09b260e to
eef6f03
Compare
The second commit makes the rule correctable. I've also made some performance optimizations. |
eef6f03 to
60290ce
Compare
Source/SwiftLintBuiltInRules/Rules/Lint/InvisibleCharacterRule.swift
Outdated
Show resolved
Hide resolved
Tests/IntegrationTests/Resources/default_rule_configurations.yml
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Lint/InvisibleCharacterRule.swift
Outdated
Show resolved
Hide resolved
Fine for me to skip the description or have it optional. |
I've added the ability to configure additional characters. I thought about it for a long time and initially decided not to allow disabling the validation of default characters. The hardest part was coming up with names for the parameter and variables 😅. But I'm still having doubts. Please review ) |
9c58429 to
c336b5f
Compare
…olating characters
c336b5f to
01b29ad
Compare
SimplyDanny
left a comment
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.
This looks very good now! Thank you for all the updates.
I posted a suggestion for the option's name. Let me know what you think about it.
Source/SwiftLintBuiltInRules/Rules/RuleConfigurations/InvisibleCharacterConfiguration.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/RuleConfigurations/InvisibleCharacterConfiguration.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Lint/InvisibleCharacterRule.swift
Outdated
Show resolved
Hide resolved
|
There is something wrong with the tests on Linux and Windows. I can reproduce that on Linux. The test execution is just stuck. |
7031a5f to
1b30907
Compare
1b30907 to
9921111
Compare
I can reproduce that on Windows but I wasn't able to debug the issue. The problem is related only to the 0x200D character. For some reason, it just stucks on Windows/Linux if there is an Example with this character. |
|
So that might even be an issue with the compiler. If we were able to create a small reproducer, we could use that to report a bug. |
#6045
Summary
invisible_characterslint rule that detects invisible characters in string literals: