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 private_only to prefixed_toplevel_constant #2315

Merged
merged 5 commits into from
Jul 24, 2018
Merged

Conversation

keith
Copy link
Collaborator

@keith keith commented Jul 24, 2018

This allows users to opt in to only validate top level constants have
the given prefix if the constant is private or fileprivate.

I'm not sure how to add a test with a configuration difference, but I'm happy to do that if it's possible.

@keith keith requested a review from jpsim July 24, 2018 04:41
@SwiftLintBot
Copy link

SwiftLintBot commented Jul 24, 2018

12 Messages
📖 Linting Aerial with this PR took 0.43s vs 0.37s on master (16% slower)
📖 Linting Alamofire with this PR took 3.6s vs 3.22s on master (11% slower)
📖 Linting Firefox with this PR took 14.23s vs 12.01s on master (18% slower)
📖 Linting Kickstarter with this PR took 21.82s vs 17.25s on master (26% slower)
📖 Linting Moya with this PR took 2.19s vs 1.9s on master (15% slower)
📖 Linting Nimble with this PR took 2.12s vs 1.67s on master (26% slower)
📖 Linting Quick with this PR took 0.58s vs 0.52s on master (11% slower)
📖 Linting Realm with this PR took 3.91s vs 3.16s on master (23% slower)
📖 Linting SourceKitten with this PR took 1.11s vs 1.0s on master (11% slower)
📖 Linting Sourcery with this PR took 5.38s vs 4.5s on master (19% slower)
📖 Linting Swift with this PR took 34.59s vs 27.49s on master (25% slower)
📖 Linting WordPress with this PR took 18.8s vs 15.7s on master (19% slower)

Generated by 🚫 Danger

@codecov-io
Copy link

codecov-io commented Jul 24, 2018

Codecov Report

Merging #2315 into master will decrease coverage by 0.08%.
The diff coverage is 30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2315      +/-   ##
==========================================
- Coverage   92.02%   91.93%   -0.09%     
==========================================
  Files         292      293       +1     
  Lines       14763    14782      +19     
==========================================
+ Hits        13585    13590       +5     
- Misses       1178     1192      +14
Impacted Files Coverage Δ
...igurations/PrefixedConstantRuleConfiguration.swift 13.33% <13.33%> (ø)
...Framework/Rules/PrefixedTopLevelConstantRule.swift 95% <80%> (-5%) ⬇️

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 c7c0ac8...999abf1. Read the comment docs.

@keith keith force-pushed the ks/toplevel-private branch from f18b518 to 845b616 Compare July 24, 2018 05:17
@@ -54,6 +54,11 @@ public struct PrefixedTopLevelConstantRule: ASTRule, OptInRule, ConfigurationPro
public func validate(file: File,
kind: SwiftDeclarationKind,
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {
if self.configuration.onlyPrivateMembers,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this could be combined with the other guard below, since both are used for early exiting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought about that but since we only want to take into account if the ACL is private if this configuration is set, it felt like it was getting too complicated to be in that one as well.

@@ -54,6 +54,11 @@ public struct PrefixedTopLevelConstantRule: ASTRule, OptInRule, ConfigurationPro
public func validate(file: File,
kind: SwiftDeclarationKind,
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {
if self.configuration.onlyPrivateMembers,
Copy link
Contributor

Choose a reason for hiding this comment

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

You can safely drop the self. here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@@ -54,6 +54,11 @@ public struct PrefixedTopLevelConstantRule: ASTRule, OptInRule, ConfigurationPro
public func validate(file: File,
kind: SwiftDeclarationKind,
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {
if self.configuration.onlyPrivateMembers,
let acl = dictionary.accessibility.flatMap(AccessControlLevel.init(identifier:)), !acl.isPrivate {
return []
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation here looks a little bit odd.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

huh yea, tab got in here some how

@marcelofabri
Copy link
Collaborator

marcelofabri commented Jul 24, 2018

I'm not sure how to add a test with a configuration difference, but I'm happy to do that if it's possible.

You can do it in a similar way as this commit: https://github.com/realm/SwiftLint/pull/2308/files/73fafd5c071f59b7ed8c09a2fe493f5e202215ea..dc44fbcac37900283ea54072f2fa75c881dc950c.

You can remove the AutomaticTestableRule conformance and create a new PrefixedTopLevelConstantRuleTests that has a test for the default configuration and one for the new configuration.

keith added 3 commits July 24, 2018 09:12
This allows users to opt in to only validate top level constants have
the given prefix if the constant is private or fileprivate.
@keith keith force-pushed the ks/toplevel-private branch from 999abf1 to 61844ea Compare July 24, 2018 16:34
@keith
Copy link
Collaborator Author

keith commented Jul 24, 2018

Awesome, thanks for the example, added tests for this specific configuration

@keith keith force-pushed the ks/toplevel-private branch from 61844ea to 50c7165 Compare July 24, 2018 16:35
"public let Foo = 20.0"
]

let alwaysOnSameLineDescription = PrefixedTopLevelConstantRule.description
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you rename this variable? (I just noticed it's also wrong on the linked PR 😅 )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yea, fixed

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.

Thanks! 💯

@keith keith merged commit 6eedf5d into master Jul 24, 2018
@keith keith deleted the ks/toplevel-private branch July 24, 2018 19:38
dirtydanee pushed a commit to dirtydanee/SwiftLint that referenced this pull request Aug 14, 2018
* Add private_only to prefixed_toplevel_constant

This allows users to opt in to only validate top level constants have
the given prefix if the constant is private or fileprivate.
sjavora pushed a commit to sjavora/SwiftLint that referenced this pull request Mar 9, 2019
* Add private_only to prefixed_toplevel_constant

This allows users to opt in to only validate top level constants have
the given prefix if the constant is private or fileprivate.
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