From 01ac89455850a921ba9a0a9e957e5e86ce0f805c Mon Sep 17 00:00:00 2001 From: Shawn Hyam Date: Thu, 25 Jul 2024 09:43:02 -0400 Subject: [PATCH] Change assertLint helper to run via the pipeline only. Standalone lint visitors don't check for swift-format-ignore markers, so any test cases that use those markers will return different results between standalone vs full pipeline. Since the app uses the pipeline only, there is no value in running the rule standalone. --- ...DontRepeatTypeInStaticPropertiesTests.swift | 18 ++++++++++++++++++ .../Rules/LintOrFormatRuleTestCase.swift | 12 +----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Tests/SwiftFormatTests/Rules/DontRepeatTypeInStaticPropertiesTests.swift b/Tests/SwiftFormatTests/Rules/DontRepeatTypeInStaticPropertiesTests.swift index 3d961d2d6..801a89a8c 100644 --- a/Tests/SwiftFormatTests/Rules/DontRepeatTypeInStaticPropertiesTests.swift +++ b/Tests/SwiftFormatTests/Rules/DontRepeatTypeInStaticPropertiesTests.swift @@ -75,4 +75,22 @@ final class DontRepeatTypeInStaticPropertiesTests: LintOrFormatRuleTestCase { ] ) } + + + func testIgnoreSingleDecl() { + assertLint( + DontRepeatTypeInStaticProperties.self, + """ + struct Foo { + // swift-format-ignore: DontRepeatTypeInStaticProperties + static let defaultFoo: Int + static let 1️⃣alternateFoo: Int + } + """, + findings: [ + FindingSpec("1️⃣", message: "remove the suffix 'Foo' from the name of the variable 'alternateFoo'"), + ] + ) + } + } diff --git a/Tests/SwiftFormatTests/Rules/LintOrFormatRuleTestCase.swift b/Tests/SwiftFormatTests/Rules/LintOrFormatRuleTestCase.swift index 814952e6d..953f1e254 100644 --- a/Tests/SwiftFormatTests/Rules/LintOrFormatRuleTestCase.swift +++ b/Tests/SwiftFormatTests/Rules/LintOrFormatRuleTestCase.swift @@ -42,16 +42,6 @@ class LintOrFormatRuleTestCase: DiagnosingTestCase { configuration: configuration, selection: .infinite, findingConsumer: { emittedFindings.append($0) }) - let linter = type.init(context: context) - linter.walk(sourceFileSyntax) - - assertFindings( - expected: findings, - markerLocations: markedText.markers, - emittedFindings: emittedFindings, - context: context, - file: file, - line: line) var emittedPipelineFindings = [Finding]() // Disable default rules, so only select rule runs in pipeline @@ -66,7 +56,7 @@ class LintOrFormatRuleTestCase: DiagnosingTestCase { operatorTable: OperatorTable.standardOperators, assumingFileURL: URL(string: file.description)!) - // Check that pipeline produces the same findings as the isolated linter rule + // Check that pipeline produces the expected findings assertFindings( expected: findings, markerLocations: markedText.markers,