-
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
Add options to disable some checks for identifier_name rule #1444
Add options to disable some checks for identifier_name rule #1444
Conversation
"enum Foo { case MyEnum }" | ||
] | ||
let triggeringExamples = baseDescription.triggeringExamples | ||
.filter { !$0.contains("MyLet") && !$0.contains("MyEnum") } |
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 make sense to add triggering and non triggering examples to IdentifierNameRuleExamples
for these two new tests even if they are only used in the tests?
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.
I'm not sure what you mean here, could you elaborate?
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.
I meant adding new static properties in IdentifierNameRuleExamples.swift
(e.g. swift3NonTriggeringExamplesWithIgnoreStartWithLowercase
or similar), instead of appending the two examples, let MyLet = 0
and enum Foo { case MyEnum }
, to the non triggering examples here, and then having to remove examples that contain MyLet
and MyEnum
for the triggering examples.
Generated by 🚫 danger |
@@ -70,7 +72,8 @@ public struct IdentifierNameRule: ASTRule, ConfigurationProviderRule { | |||
} | |||
} | |||
|
|||
if kind != .varStatic && name.isViolatingCase && !name.isOperator { | |||
if (!configuration.ignoresStartWithLowercase || isFunction) && |
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.
maybe extract this condition (inside parenthesis) into a variable?
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.
You need to update LinuxMain.swift
so IdentifierNameRuleTests
is run on Linux
Codecov Report
@@ Coverage Diff @@
## master #1444 +/- ##
==========================================
+ Coverage 83.07% 83.16% +0.09%
==========================================
Files 182 185 +3
Lines 9117 9275 +158
==========================================
+ Hits 7574 7714 +140
- Misses 1543 1561 +18
Continue to review full report at Codecov.
|
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 is good 💯
Just some comments 😬
@@ -17,6 +17,8 @@ public struct NameConfiguration: RuleConfiguration, Equatable { | |||
var minLength: SeverityLevelsConfiguration | |||
var maxLength: SeverityLevelsConfiguration | |||
var excluded: Set<String> | |||
var allowedSymbols: Set<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.
this configuration is used on TypeNameRule
and GenericTypeNameRule
too. Maybe we should add support on those rules as well?
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.
also, can you update consoleDescription
to show all variables?
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.
It wouldn't be difficult to add it to TypeNameRule
and GenericTypeNameRule
, but do you think it'll be a common case? I can't remember seeing any code base with types or generic types with symbols
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.
I was thinking more about keeping them consistente since they all use the same configuration type
@@ -17,6 +17,8 @@ public struct NameConfiguration: RuleConfiguration, Equatable { | |||
var minLength: SeverityLevelsConfiguration | |||
var maxLength: SeverityLevelsConfiguration | |||
var excluded: Set<String> | |||
var allowedSymbols: Set<String> | |||
var ignoresStartWithLowercase: Bool |
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.
what do you think about validatesStartWithLowercase
(defaulting to true
)?
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.
I think it looks better than my option 😆 I'll change it!
@@ -70,7 +72,9 @@ public struct IdentifierNameRule: ASTRule, ConfigurationProviderRule { | |||
} | |||
} | |||
|
|||
if kind != .varStatic && name.isViolatingCase && !name.isOperator { | |||
let requiresCaseCheck = !configuration.ignoresStartWithLowercase || isFunction |
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.
why the isFunction
check? 🤔
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.
It made sense to me not to allow this option for functions, I thought there would be more cases where someone would want to disable this, in order to migrate code with enum cases that start with uppercase for example, than cases where someone would have functions starting with uppercase. Nonetheless, I wouldn't mind changing this if you think it'd be better 🙂
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.
💯
Minor changes in 61e9b39 |
Thanks for the help and feedback, @marcelofabri 🙂 |
Add options mentioned in #541 for
IdentifierNameRule
, in order to allow names that start with an uppercase character and to exclude non alphanumeric characters.