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

#2435 - Make modifier_order rule rely on an explicit set of rules #2458

Merged
merged 6 commits into from
Nov 28, 2018

Conversation

abdulowork
Copy link
Contributor

After a bit of research resulting from #2435 it was found that modifier_order rule only cares about specified exact leading ordering. For example given the ordering [.final, .override, .acl] the following would be considered triggering:

weak final override private var a: String
final weak override private var b: String
final override weak private var c: String

but this would be considered fine:

final override private weak var d: String

Such behavior is not always desired. It might be more beneficial if modifier_order rule only enforced order between the specified modifiers and left the unspecified in place. I slightly modified the algorithm and adjusted it such that it's a bit stricter than the current oss-check.

@SwiftLintBot
Copy link

SwiftLintBot commented Nov 9, 2018

14 Warnings
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Account/FxADeviceRegistration.swift:56:33: warning: Modifier Order Violation: required modifier should be before convenience. (modifier_order)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Push/PushRegistration.swift:32:39: warning: Modifier Order Violation: required modifier should be before convenience. (modifier_order)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/project/osscheck/Firefox/Push/PushRegistration.swift:94:39: warning: Modifier Order Violation: required modifier should be before convenience. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:99:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:107:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:113:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:119:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:125:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:131:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:137:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:144:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:154:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/project/osscheck/Sourcery/SourceryRuntime/Sources/TemplateContext.swift:168:31: warning: Modifier Order Violation: internal modifier should be before lazy. (modifier_order)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/project/osscheck/WordPress/WordPress/Classes/Utility/Environment/Environment.swift:26:5: warning: Modifier Order Violation: private modifier should be before static. (modifier_order)
12 Messages
📖 Linting Aerial with this PR took 2.56s vs 2.58s on master (0% faster)
📖 Linting Alamofire with this PR took 7.01s vs 4.91s on master (42% slower)
📖 Linting Firefox with this PR took 25.94s vs 19.15s on master (35% slower)
📖 Linting Kickstarter with this PR took 34.73s vs 28.18s on master (23% slower)
📖 Linting Moya with this PR took 3.46s vs 2.74s on master (26% slower)
📖 Linting Nimble with this PR took 3.69s vs 2.45s on master (50% slower)
📖 Linting Quick with this PR took 0.92s vs 0.74s on master (24% slower)
📖 Linting Realm with this PR took 7.16s vs 4.57s on master (56% slower)
📖 Linting SourceKitten with this PR took 2.12s vs 1.61s on master (31% slower)
📖 Linting Sourcery with this PR took 9.65s vs 6.31s on master (52% slower)
📖 Linting Swift with this PR took 56.59s vs 35.34s on master (60% slower)
📖 Linting WordPress with this PR took 28.76s vs 26.43s on master (8% slower)

Generated by 🚫 Danger

@codecov-io
Copy link

codecov-io commented Nov 9, 2018

Codecov Report

Merging #2458 into master will increase coverage by 0.03%.
The diff coverage is 98.11%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2458      +/-   ##
=========================================
+ Coverage   90.67%   90.7%   +0.03%     
=========================================
  Files         322     322              
  Lines       16225   16261      +36     
=========================================
+ Hits        14712   14750      +38     
+ Misses       1513    1511       -2
Impacted Files Coverage Δ
...s/SwiftLintFrameworkTests/ModifierOrderTests.swift 97.33% <100%> (ø) ⬆️
...tLintFramework/Rules/Style/ModifierOrderRule.swift 95.06% <98.07%> (+1.72%) ⬆️
...ntFramework/Rules/Idiomatic/LegacyRandomRule.swift 5.26% <0%> (ø) ⬆️
...SwiftLintFramework/Extensions/File+SwiftLint.swift 97.23% <0%> (+0.46%) ⬆️
...mework/Rules/Style/ClosureEndIndentationRule.swift 98.38% <0%> (+0.8%) ⬆️

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 30808b1...ffa78c0. Read the comment docs.

public struct ModifierOrderRule: ASTRule, OptInRule, ConfigurationProviderRule {
public var configuration = ModifierOrderConfiguration(preferredModifierOrder: [.override, .acl])
public var configuration = ModifierOrderConfiguration(
preferredModifierOrder: [
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change this?

Copy link
Contributor Author

@abdulowork abdulowork Nov 14, 2018

Choose a reason for hiding this comment

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

Leaving the order as is would fix all of the violations where some other modifier preceded or was in-between the [.override, .acl] modifiers. Matching the prior behavior of the rule with this version was impossible so I just used the oss-check as a guideline to establish the modifier order. The order should definitely be made less strict if this change is desired.

@@ -14,163 +25,8 @@ public struct ModifierOrderRule: ASTRule, OptInRule, ConfigurationProviderRule {
description: "Modifier order should be consistent.",
kind: .style,
minSwiftVersion: .fourDotOne ,
nonTriggeringExamples: [
Copy link
Contributor

@masters3d masters3d Nov 14, 2018

Choose a reason for hiding this comment

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

can this be its. own commit? hard to see if any of the test cases changed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, moved to a separate commit. None of the test cases were changed

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some non triggering test cases like the ones you described above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the examples

@abdulowork abdulowork force-pushed the modifier-order-fix branch 2 times, most recently from f762335 to 2c5fdd4 Compare November 15, 2018 10:21
@jpsim jpsim force-pushed the modifier-order-fix branch from 2c5fdd4 to 0deadd1 Compare November 28, 2018 22:05
@jpsim
Copy link
Collaborator

jpsim commented Nov 28, 2018

Thank you very much for this PR @Biboran! I had concerns about this when the rule was originally added, so it's nice to see you address them 😄

I made some small changes and added a changelog entry. I'll merge when CI is happy.

@jpsim jpsim merged commit efa6817 into realm:master Nov 28, 2018
sjavora pushed a commit to sjavora/SwiftLint that referenced this pull request Mar 9, 2019
realm#2458)

* realm#2435 - Adjust modifier_order rule to require explicit modifier order specified to conclude a violation

* realm#2435 - Move modifier order rule examples to a separate file

* realm#2435 - Add modifier interference tests

* realm#2435 - Fix whitespaces

* Minor edits

* Add changelog entry
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