Skip to content
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

Merged
merged 6 commits into from
May 14, 2017
Merged

Add options to disable some checks for identifier_name rule #1444

merged 6 commits into from
May 14, 2017

Conversation

jaherhi
Copy link
Contributor

@jaherhi jaherhi commented Apr 17, 2017

Add options mentioned in #541 for IdentifierNameRule, in order to allow names that start with an uppercase character and to exclude non alphanumeric characters.

"enum Foo { case MyEnum }"
]
let triggeringExamples = baseDescription.triggeringExamples
.filter { !$0.contains("MyLet") && !$0.contains("MyEnum") }
Copy link
Contributor Author

@jaherhi jaherhi Apr 17, 2017

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?

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@SwiftLintBot
Copy link

SwiftLintBot commented Apr 17, 2017

12 Messages
📖 Linting WordPress with this PR took 15.02s vs 13.74s on master (9% slower)
📖 Linting Alamofire with this PR took 4.91s vs 3.15s on master (55% slower)
📖 Linting Firefox with this PR took 17.95s vs 13.7s on master (31% slower)
📖 Linting Kickstarter with this PR took 22.93s vs 18.98s on master (20% slower)
📖 Linting Moya with this PR took 0.47s vs 0.46s on master (2% slower)
📖 Linting Nimble with this PR took 2.08s vs 1.9s on master (9% slower)
📖 Linting Aerial with this PR took 0.67s vs 0.41s on master (63% slower)
📖 Linting Realm with this PR took 3.43s vs 3.19s on master (7% slower)
📖 Linting SourceKitten with this PR took 1.33s vs 1.24s on master (7% slower)
📖 Linting Sourcery with this PR took 2.82s vs 2.55s on master (10% slower)
📖 Linting Swift with this PR took 17.6s vs 14.4s on master (22% slower)
📖 Linting Quick with this PR took 0.64s vs 0.71s on master (9% faster)

Generated by 🚫 danger

@@ -70,7 +72,8 @@ public struct IdentifierNameRule: ASTRule, ConfigurationProviderRule {
}
}

if kind != .varStatic && name.isViolatingCase && !name.isOperator {
if (!configuration.ignoresStartWithLowercase || isFunction) &&
Copy link
Collaborator

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?

Copy link
Collaborator

@marcelofabri marcelofabri left a 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-io
Copy link

codecov-io commented Apr 19, 2017

Codecov Report

Merging #1444 into master will increase coverage by 0.09%.
The diff coverage is 87.64%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
Tests/SwiftLintFrameworkTests/RulesTests.swift 71.81% <ø> (+0.17%) ⬆️
Source/SwiftLintFramework/Rules/TypeNameRule.swift 92.45% <100%> (+0.29%) ⬆️
...iftLintFrameworkTests/RuleConfigurationTests.swift 77.58% <100%> (+0.31%) ⬆️
.../SwiftLintFramework/Rules/IdentifierNameRule.swift 95% <100%> (+0.26%) ⬆️
...SwiftLintFramework/Rules/GenericTypeNameRule.swift 93.65% <100%> (+0.1%) ⬆️
...k/Rules/RuleConfigurations/NameConfiguration.swift 84.44% <71.42%> (-3.8%) ⬇️
...ftLintFrameworkTests/IdentifierNameRuleTests.swift 86.66% <86.66%> (ø)
...ts/SwiftLintFrameworkTests/TypeNameRuleTests.swift 87.75% <87.75%> (ø)
...tLintFrameworkTests/GenericTypeNameRuleTests.swift 88% <88%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6f9a85...d652cfe. Read the comment docs.

Copy link
Collaborator

@marcelofabri marcelofabri left a 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>
Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Contributor Author

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 TypeNameRuleand 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

Copy link
Collaborator

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
Copy link
Collaborator

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)?

Copy link
Contributor Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the isFunction check? 🤔

Copy link
Contributor Author

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 🙂

Copy link
Collaborator

@marcelofabri marcelofabri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@jpsim
Copy link
Collaborator

jpsim commented May 15, 2017

Minor changes in 61e9b39

@jaherhi
Copy link
Contributor Author

jaherhi commented May 15, 2017

Thanks for the help and feedback, @marcelofabri 🙂

@jaherhi jaherhi deleted the identifier_name_allow_non_alphanumeric_and_uppercase_characters branch May 15, 2017 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants