Skip to content

Commit 2588749

Browse files
committed
Add an option to test lint rules on the full 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.
1 parent f0d1167 commit 2588749

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

Tests/SwiftFormatTests/Rules/DontRepeatTypeInStaticPropertiesTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,23 @@ final class DontRepeatTypeInStaticPropertiesTests: LintOrFormatRuleTestCase {
7575
]
7676
)
7777
}
78+
79+
80+
func testIgnoreSingleDecl() {
81+
assertLint(
82+
DontRepeatTypeInStaticProperties.self,
83+
pipelineOnly: true,
84+
"""
85+
struct Foo {
86+
// swift-format-ignore: DontRepeatTypeInStaticProperties
87+
static let defaultFoo: Int
88+
static let 1️⃣alternateFoo: Int
89+
}
90+
""",
91+
findings: [
92+
FindingSpec("1️⃣", message: "remove the suffix 'Foo' from the name of the variable 'alternateFoo'"),
93+
]
94+
)
95+
}
96+
7897
}

Tests/SwiftFormatTests/Rules/LintOrFormatRuleTestCase.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class LintOrFormatRuleTestCase: DiagnosingTestCase {
1313
///
1414
/// - Parameters:
1515
/// - type: The metatype of the lint rule you wish to perform.
16+
/// - pipelineOnly: Don't run the linter on its own, only as part of the pipeline. This is
17+
/// because swift-format-ignore has no effect when running the linter standalone.
1618
/// - markedSource: The input source code, which may include emoji markers at the locations
1719
/// where findings are expected to be emitted.
1820
/// - findings: A list of `FindingSpec` values that describe the findings that are expected to
@@ -21,6 +23,7 @@ class LintOrFormatRuleTestCase: DiagnosingTestCase {
2123
/// - line: The line the test resides in (defaults to the current caller's line).
2224
final func assertLint<LintRule: SyntaxLintRule>(
2325
_ type: LintRule.Type,
26+
pipelineOnly: Bool = false,
2427
_ markedSource: String,
2528
findings: [FindingSpec] = [],
2629
file: StaticString = #file,
@@ -42,16 +45,18 @@ class LintOrFormatRuleTestCase: DiagnosingTestCase {
4245
configuration: configuration,
4346
selection: .infinite,
4447
findingConsumer: { emittedFindings.append($0) })
45-
let linter = type.init(context: context)
46-
linter.walk(sourceFileSyntax)
47-
48-
assertFindings(
49-
expected: findings,
50-
markerLocations: markedText.markers,
51-
emittedFindings: emittedFindings,
52-
context: context,
53-
file: file,
54-
line: line)
48+
if !pipelineOnly {
49+
let linter = type.init(context: context)
50+
linter.walk(sourceFileSyntax)
51+
52+
assertFindings(
53+
expected: findings,
54+
markerLocations: markedText.markers,
55+
emittedFindings: emittedFindings,
56+
context: context,
57+
file: file,
58+
line: line)
59+
}
5560

5661
var emittedPipelineFindings = [Finding]()
5762
// Disable default rules, so only select rule runs in pipeline

0 commit comments

Comments
 (0)