SwiftLint
SwiftLint copied to clipboard
Rewrite IdenticalOperandsRule with SwiftSyntax
5 Warnings | |
---|---|
:warning: | If this is a user-facing change, please include a CHANGELOG entry to credit yourself! You can find it at CHANGELOG.md. |
:warning: | This PR may need tests. |
:warning: | This PR introduced a violation in Realm: /RealmSwift/Tests/ModernObjectAccessorTests.swift:341:27: warning: Identical Operands Violation: Comparing two identical operands is likely a mistake. (identical_operands) |
:warning: | This PR introduced a violation in Realm: /RealmSwift/Tests/ModernObjectAccessorTests.swift:431:27: warning: Identical Operands Violation: Comparing two identical operands is likely a mistake. (identical_operands) |
:warning: | This PR introduced a violation in Realm: /RealmSwift/Tests/ModernObjectAccessorTests.swift:527:27: warning: Identical Operands Violation: Comparing two identical operands is likely a mistake. (identical_operands) |
13 Messages | |
---|---|
:book: | Linting Aerial with this PR took 0.15s vs 0.27s on main (44% faster) |
:book: | Linting Alamofire with this PR took 0.09s vs 0.34s on main (73% faster) |
:book: | Linting DuckDuckGo with this PR took 0.27s vs 0.73s on main (63% faster) |
:book: | Linting Firefox with this PR took 0.56s vs 1.61s on main (65% faster) |
:book: | Linting Kickstarter with this PR took 0.98s vs 2.2s on main (55% faster) |
:book: | Linting Moya with this PR took 0.14s vs 0.17s on main (17% faster) |
:book: | Linting Nimble with this PR took 0.09s vs 0.17s on main (47% faster) |
:book: | Linting Quick with this PR took 0.06s vs 0.09s on main (33% faster) |
:book: | Linting Realm with this PR took 0.51s vs 1.24s on main (58% faster) |
:book: | Linting SourceKitten with this PR took 0.08s vs 0.14s on main (42% faster) |
:book: | Linting Sourcery with this PR took 0.21s vs 0.49s on main (57% faster) |
:book: | Linting Swift with this PR took 0.8s vs 0.94s on main (14% faster) |
:book: | Linting WordPress with this PR took 0.86s vs 2.59s on main (66% faster) |
Here's an example of your CHANGELOG entry:
* Rewrite IdenticalOperandsRule with SwiftSyntax.
[marcelofabri](https://github.com/marcelofabri)
[#issue_number](https://github.com/realm/SwiftLint/issues/issue_number)
note: There are two invisible spaces after the entry's text.
Generated by :no_entry_sign: Danger
I know this is a work in progress, but flagging so it’s not missed, this looks like a regression:
This PR fixed a violation in Realm: /RealmSwift/Tests/AnyRealmValueTests.swift:942:24: warning: Identical Operands Violation: Comparing two identical operands is likely a mistake. (identical_operands)
Also, it’s really awesome to see what seem to be trustworthy performance benchmark comparisons from OSSCheck.
I know this is a work in progress, but flagging so it’s not missed, this looks like a regression:
This PR fixed a violation in Realm: /RealmSwift/Tests/AnyRealmValueTests.swift:942:24: warning: Identical Operands Violation: Comparing two identical operands is likely a mistake. (identical_operands)
Yeah, I now remember trying to reimplement this a while ago and facing the same problem: https://forums.swift.org/t/detecting-binary-operator-precedence/33350/2
If porting this rule introduces some regressions but is overall more robust, I'm not opposed to that tradeoff, but it'd be nice to avoid regressions. Let me know if you'd like a hand to look into porting the expression folding algorithm like Tony mentioned in the forums.
Codecov Report
Merging #3894 (fe299da) into master (1752587) will decrease coverage by
0.05%
. The diff coverage is90.29%
.
@@ Coverage Diff @@
## master #3894 +/- ##
==========================================
- Coverage 92.53% 92.48% -0.06%
==========================================
Files 443 447 +4
Lines 22292 22746 +454
==========================================
+ Hits 20629 21037 +408
- Misses 1663 1709 +46
Impacted Files | Coverage Δ | |
---|---|---|
...Framework/Models/SequenceExprFoldingRewriter.swift | 75.00% <75.00%> (ø) |
|
...mework/Extensions/SequenceExprSyntax+Folding.swift | 85.82% <85.82%> (ø) |
|
...ntFramework/Rules/Lint/IdenticalOperandsRule.swift | 97.29% <94.59%> (+3.90%) |
:arrow_up: |
...ce/SwiftLintFramework/Models/OperatorContext.swift | 96.35% <96.35%> (ø) |
|
...Framework/Rules/Style/EmptyEnumArgumentsRule.swift | 91.42% <0.00%> (-1.43%) |
:arrow_down: |
...tFramework/Rules/Lint/ValidIBInspectableRule.swift | 95.94% <0.00%> (-1.36%) |
:arrow_down: |
...tFrameworkTests/AutomaticRuleTests.generated.swift | 100.00% <0.00%> (ø) |
|
...ntFramework/Rules/Style/CommaInheritanceRule.swift | 90.32% <0.00%> (ø) |
:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more
If we add the swift syntax folding code, maybe that should go in a new SwiftSyntaxFolding
module?
The new violations flagged by OSSCheck should probably not be reported: https://github.com/realm/realm-cocoa/blob/95ebae968d1183decef9ac5990a7f097d02b603e/RealmSwift/Tests/ModernObjectAccessorTests.swift#L341:27
I don't think it's in the spirit of this rule to include function call expressions.
Moving this to draft as we'd want to use https://github.com/apple/swift-syntax/pull/619 instead
Updated it to use the new SwiftOperators
package. Still need to address this:
I don't think it's in the spirit of this rule to include function call expressions.
Updated it to use the new
SwiftOperators
package.
Nice!