-
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
Reenable cache #1516
Reenable cache #1516
Conversation
I'd love if you could review this too @victorpimentel. |
Generated by 🚫 danger |
Codecov Report
@@ Coverage Diff @@
## master #1516 +/- ##
=========================================
- Coverage 82.78% 82.49% -0.3%
=========================================
Files 187 187
Lines 9342 9432 +90
=========================================
+ Hits 7734 7781 +47
- Misses 1608 1651 +43
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.
LGTM 👍
lock.lock() | ||
var filesCache = (cache["files"] as? [String: Any]) ?? [:] | ||
var filesCache = (cache[LinterCache.Key.files.rawValue] as? [String: Any]) ?? [:] |
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.
Very small code style question: is there any reason to use LinterCache.Key in some lines and just Key in others? It's not important, but I'm reviewing this from my phone so I'm not 100% sure if they refer to another type.
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 (inconsistently) omitted LinterCache
within its body since it could be inferred. This one slipped through. Fixed in 43e4ed6.
CHANGELOG.md
Outdated
##### Enhancements | ||
|
||
* Cache linter results for files unmodified since the previous linter run. | ||
[Victor Pimentel](https://github.com/victorpimentel) | ||
[#1184](https://github.com/realm/SwiftLint/issues/1184) |
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.
missing two trailing spaces on all entries 😅
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.
new computer accidentally has whitespace = fix
in its .gitconfig
so it automatically trimmed trailing whitespace when rebasing. Promptly removed that.
public var cacheDescription: String { | ||
let cacheRulesDescriptions: [String: Any] = rules.reduce([:]) { accu, element in | ||
var accu = accu | ||
accu[type(of: element).description.identifier] = element.configurationDescription |
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.
the configurationDescription
of ConditionalReturnsOnNewline
is "N/A"
for some reason. We probably should change that 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.
fixed in #1523.
"root": rootPath ?? FileManager.default.currentDirectoryPath, | ||
"rules": cacheRulesDescriptions | ||
] | ||
if let prettyJSONData = try? JSONSerialization.data(withJSONObject: dict), |
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.
shouldn't this pass options
to actually be a pretty? 😆
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.
doesn't need to be pretty actually, since I'm just using this for serialization. fixed variable name.
Also, does this handle nested configurations? (It doesn't look like it does) |
…files with a weak algorithm.
applying minor edits. Remove `configurationDescription` from breaking changes in changelog since additions aren't breaking changes.
rather than use hardcoded, duplicate string literals
rather than just when using one of many code paths in one of many initializers
to provide more complete descriptions for cache invalidation purposes.
by respecting the value of ignoreCache rather than always passing 'true'
I've updated/rebased this after #1522, #1523 & #1524 were merged. I also updated it to consider custom rules in cache invalidation. In manual testing, I've confirmed that: An individual file cache is invalidated when:
Entire cache is invalidated when:
Cache is not invalidated when:
The only thing I can see doesn't work is nested configurations. I haven't really looked into what it would take to support that either. I suspect it wouldn't be too hard though. |
dict["message"] = message | ||
dict["regex"] = regex.pattern | ||
if let included = included?.pattern { | ||
dict["included"] = included |
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.
doesn't dict["included"] = included?.pattern
have the same effect? (this applies for all optional 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.
that would produce ["included": nil]
rather than [:]
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 doesn't 😅
var dict = [String: String]()
dict["foo"] = nil
dict["bar"] = "bar"
let data = try! JSONSerialization.data(withJSONObject: dict)
print(String(data: data, encoding: .utf8)!) // {"bar":"bar"}
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.
👍 thanks
Do you want to merge this without supporting nested configurations? If so, I'd suggest to disable caching by default until we do support them. |
WIP support for nested configurations: jp-reenable-cache...jp-wip-cache-support-nested-configs I have some cleaning up to do and tests to write, but it shows that it can be done fairly easily. |
I'd really rather not ship this (again) with known issues or limitations. |
Thanks so much for this @jpsim 👍 |
Superseded by #1530. |
Continued from #1311. Addresses #1184.