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

Teststate enhancement #5920

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Collaborator

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.

[@aydinomer00](https://github.com/aydinomer00)
[#5920](https://github.com/realm/SwiftLint/issues/5920)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
[#5920](https://github.com/realm/SwiftLint/issues/5920)
[#5803](https://github.com/realm/SwiftLint/issues/5803)



Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct QuickDiscouragedCallRule: OptInRule {
guard
kind == .call,
let name = dictionary.name,
name != "@TestState", // İstisna: @TestState için uyarı tetiklenmesin
Copy link
Collaborator

Choose a reason for hiding this comment

The 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. name will never be @TestState. These are the names of Quick methods, not variables or attributes.

let kindName = QuickCallKind(rawValue: name),
QuickCallKind.restrictiveKinds.contains(kindName)
else { return [] }
Expand All @@ -58,7 +59,7 @@ struct QuickDiscouragedCallRule: OptInRule {
reason: "Discouraged call inside a '\(name)' block")
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Down
40 changes: 40 additions & 0 deletions Tests/SwiftLintFrameworkTests/QuickDiscouragedCallRuleTests.swift
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This new test class is not required. Please use QuickDiscouragedCallRuleExamples instead to add your test cases.


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
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not the correct expectation. With the @TestState we don't expect a warning. This is what #5803 is all about.

]

// Test for correct usage
nonTriggeringExamples.forEach { example in
XCTAssertEqual(lint(example), [])
}

// Test for incorrect usage
triggeringExamples.forEach { example in
XCTAssertFalse(lint(example).isEmpty)
}
}
}
Loading