-
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
Teststate enhancement #5920
base: main
Are you sure you want to change the base?
Teststate enhancement #5920
Changes from 3 commits
7305f36
b9dc085
6b49cd9
6ea8a51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7958,3 +7958,9 @@ This release has seen a phenomenal uptake in community contributions! | |||||
## 0.1.0: Fresh Out Of The Dryer | ||||||
|
||||||
First Version! | ||||||
|
||||||
* Teststate enhancement. | ||||||
[@aydinomer00](https://github.com/aydinomer00) | ||||||
[#5920](https://github.com/realm/SwiftLint/issues/5920) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be a link to the issue describing the enhancement, not the PR implementing it:
Suggested change
|
||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ struct QuickDiscouragedCallRule: OptInRule { | |
guard | ||
kind == .call, | ||
let name = dictionary.name, | ||
name != "@TestState", // İstisna: @TestState için uyarı tetiklenmesin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use English for comments. I don't think this fix is correct. |
||
let kindName = QuickCallKind(rawValue: name), | ||
QuickCallKind.restrictiveKinds.contains(kindName) | ||
else { return [] } | ||
|
@@ -58,7 +59,7 @@ struct QuickDiscouragedCallRule: OptInRule { | |
reason: "Discouraged call inside a '\(name)' block") | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove. |
||
private func violationOffsets(in substructure: [SourceKittenDictionary]) -> [ByteCount] { | ||
substructure.flatMap { dictionary -> [ByteCount] in | ||
let substructure = dictionary.substructure.flatMap { dict -> [SourceKittenDictionary] in | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// QuickDiscouragedCallRuleTests.swift | ||
// SwiftLint | ||
// | ||
// Created by Omer Murat Aydin on 28.12.2024. | ||
// | ||
|
||
@testable import SwiftLintBuiltInRules | ||
import XCTest | ||
@testable import SwiftLintFramework | ||
|
||
class QuickDiscouragedCallRuleTests: XCTestCase { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new test class is not required. Please use |
||
|
||
func lint(_ content: String) -> [StyleViolation] { | ||
let file = SwiftLintFile(contents: content) | ||
return QuickDiscouragedCallRule().validate(file: file) | ||
} | ||
|
||
func testQuickDiscouragedCallRule() { | ||
// Example of correct usage (should not trigger a warning) | ||
let nonTriggeringExamples = [ | ||
"@TestState var foo = Foo()" // This should not trigger a warning | ||
] | ||
|
||
// Example of incorrect usage (should trigger a warning) | ||
let triggeringExamples = [ | ||
"describe(\"foo\") { @TestState var foo = Foo() }" // This should trigger a warning | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the correct expectation. With the |
||
] | ||
|
||
// Test for correct usage | ||
nonTriggeringExamples.forEach { example in | ||
XCTAssertEqual(lint(example), []) | ||
} | ||
|
||
// Test for incorrect usage | ||
triggeringExamples.forEach { example in | ||
XCTAssertFalse(lint(example).isEmpty) | ||
} | ||
} | ||
} |
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.
This entry needs to go right to the top of this file.