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

Command Line Options for Interacting with the Configuration Merging Process #1748

Closed
wants to merge 7 commits into from
Closed

Command Line Options for Interacting with the Configuration Merging Process #1748

wants to merge 7 commits into from

Conversation

SDGGiesbrecht
Copy link
Contributor

(From #1693, expanded from @jpsim’s suggestions in #1323.)

Adds three command line options:

  • --config-defaults: the path of an external configuration file to use as the root of the merge tree.
  • --config-overrides: the path of an external configuration file to append to the end of each branch of the merge tree
  • --ignore-nested-configs: ignores nested configuration files

(The combination of --config-defaults and --ignore-nested-configs can be used to make --config-defaults stomp anything present in the project, even the root directory.)

Commit breakdown:

The interaction with the merge logic is isolated in the second commit. (The first commit simply adds the options to the interface and gets them to Configuration.)

Other Notes:

I left --config alone for now, but I think this pull request would make it obsolete. (In the wake of #1687 it looks like it merges itself with anything it finds, all the way back to the system root, which I doubt anyone expects.)

The read‐me is out of date. It still says nested files trump their parents. I left it alone in case you want it in sync with the last stable release and not master.

In the process of writing this, I discovered that the existing merge process went backwards. A tree like this...
A
↳ B
  ↳ C
    ↳ D
...was being merged as A is overridden by D, which is overridden by C, which is overridden by B.
The refactors in this pull request eliminate the problem, but if this pull request is not accepted, that bug will have to be dealt with elsewhere.

Maintainers have been given direct write access.

(@Aranoledur, you were tracking the related issue, so you might want to look at this.)

@SDGGiesbrecht
Copy link
Contributor Author

Since I guess I cannot request reviews directly, this is a callout to you, @marcelofabri.

@SwiftLintBot
Copy link

SwiftLintBot commented Aug 4, 2017

12 Messages
📖 Linting Aerial with this PR took 0.38s vs 0.35s on master (8% slower)
📖 Linting Alamofire with this PR took 2.37s vs 2.38s on master (0% faster)
📖 Linting Firefox with this PR took 9.92s vs 9.87s on master (0% slower)
📖 Linting Kickstarter with this PR took 14.83s vs 14.81s on master (0% slower)
📖 Linting Moya with this PR took 1.02s vs 1.0s on master (2% slower)
📖 Linting Nimble with this PR took 1.35s vs 1.37s on master (1% faster)
📖 Linting Quick with this PR took 0.44s vs 0.44s on master (0% slower)
📖 Linting Realm with this PR took 2.1s vs 2.08s on master (0% slower)
📖 Linting SourceKitten with this PR took 0.79s vs 0.78s on master (1% slower)
📖 Linting Sourcery with this PR took 3.5s vs 3.44s on master (1% slower)
📖 Linting Swift with this PR took 9.9s vs 9.84s on master (0% slower)
📖 Linting WordPress with this PR took 9.55s vs 9.33s on master (2% slower)

Generated by 🚫 Danger

@SDGGiesbrecht
Copy link
Contributor Author

Any idea why only Linux would fail to accurately compare two Configurations?

@codecov-io
Copy link

codecov-io commented Aug 4, 2017

Codecov Report

Merging #1748 into master will decrease coverage by 0.06%.
The diff coverage is 67.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1748      +/-   ##
==========================================
- Coverage   87.75%   87.69%   -0.07%     
==========================================
  Files         218      218              
  Lines       10704    10781      +77     
==========================================
+ Hits         9393     9454      +61     
- Misses       1311     1327      +16
Impacted Files Coverage Δ
Source/swiftlint/Helpers/CommonOptions.swift 0% <ø> (ø) ⬆️
...iftlint/Extensions/Configuration+CommandLine.swift 0% <0%> (ø) ⬆️
Source/swiftlint/Commands/AutoCorrectCommand.swift 0% <0%> (ø) ⬆️
Source/swiftlint/Commands/LintCommand.swift 0% <0%> (ø) ⬆️
Source/swiftlint/Commands/RulesCommand.swift 0% <0%> (ø) ⬆️
...rameworkTests/ConfigurationTests+ProjectMock.swift 100% <100%> (ø) ⬆️
...urce/SwiftLintFramework/Models/Configuration.swift 88.69% <100%> (+1.35%) ⬆️
...LintFrameworkTests/ConfigurationTests+Nested.swift 100% <100%> (ø) ⬆️
...ntFramework/Extensions/Configuration+Merging.swift 91.83% <90%> (+2.36%) ⬆️

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 54d6199...f7f0fff. Read the comment docs.

@SDGGiesbrecht
Copy link
Contributor Author

The code coverage report is misleading. The two affected files in SwiftLintFramework improved. Overall coverage fell because 5⁄9 of the affected files are in the swiftlint executable and therefore untestable.

@SDGGiesbrecht
Copy link
Contributor Author

SDGGiesbrecht commented Aug 4, 2017

The single Linux failure only occurred in 3/4 times with no changes to the relevant code. (See the CI logs for the four separate commits above).

The test is older than this pull request. It is an XCTAssertEqual() that compares two Configuration files. I manually compared the two configurations in the most recent log. The only difference between their descriptions is that two of the active rules appear in a different order in the list (LineLengthRule and DiscardedNotificationCenterObserverRule).

It reminds me of chatter a while ago about a similar issue on Linux to do with caches not matching because set/dictionary iteration order is not deterministic. Since sets are being used in mergingRules (which this pull request does not touch), and never sorted, checking the resulting arrays for equality is unpredictable, which is what Configuration does in its ==.

Adding a sort step would slow things down, but I notice Configuration’s Equatable conformance is never used by Swiftlint itself, only by the tests, so maybe it would be best to do the sorting there:

(lhs.rules == rhs.rules)

(lhs.rules.sorted(by: { String(describing: $0) < String(describing: $1) })
    == rhs.rules.sorted(by: { String(describing: $0) < String(describing: $1) }))

Thoughts? Or do you want to keep that issue distinct from this pull request?

@SDGGiesbrecht
Copy link
Contributor Author

I will push the above fix for the Linux tests. (If nothing else, for the nice green checkmark.) Since maintainers have write access to the branch, if you decide a different solution would be better, you can go ahead make the change.

@SDGGiesbrecht
Copy link
Contributor Author

Everything is ready now.

@SDGGiesbrecht
Copy link
Contributor Author

Merge conflicts have accumulated since the original proposal. Since this pull request has never received any reviews or comments, the work of updating it does not seem worth it. I am therefore closing it.

(I will wait a week before I actually delete my branch in case there really are others out there who want something like this.)

@Aranoledur
Copy link

Well, my company need this too, but guys in charge don't think it's a good feature. Have to find another solution

@SDGGiesbrecht
Copy link
Contributor Author

@Aranoledur, you are welcome to pull my changes to your own fork if you want to maintain one. Just do it sooner rather than later, as I will not likely keep my fork around forever.

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.

4 participants