-
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
Ignore shebang in all rules #1700
Conversation
Generated by 🚫 Danger |
Codecov Report
@@ Coverage Diff @@
## master #1700 +/- ##
==========================================
+ Coverage 87.41% 87.49% +0.07%
==========================================
Files 208 209 +1
Lines 10278 10371 +93
==========================================
+ Hits 8985 9074 +89
- Misses 1293 1297 +4
Continue to review full report at Codecov.
|
1aab1c5
to
f2d105e
Compare
By making a creative use of regions. Fixes #1294.
f2d105e
to
70fc1a1
Compare
Creative solution! I'm sure there's a "more correct" way, but this should do just fine for now. How about testing all rules with this? diff --git a/Tests/SwiftLintFrameworkTests/FileHeaderRuleTests.swift b/Tests/SwiftLintFrameworkTests/FileHeaderRuleTests.swift
index cbe42be6..c75f1389 100644
--- a/Tests/SwiftLintFrameworkTests/FileHeaderRuleTests.swift
+++ b/Tests/SwiftLintFrameworkTests/FileHeaderRuleTests.swift
@@ -32,7 +32,7 @@ class FileHeaderRuleTests: XCTestCase {
.with(triggeringExamples: triggeringExamples)
verifyRule(description, ruleConfiguration: ["required_string": "**Header"],
- stringDoesntViolate: false, skipCommentTests: true, testMultiByteOffsets: false)
+ stringDoesntViolate: false, skipCommentTests: true, testMultiByteOffsets: false, testShebang: false)
}
func testFileHeaderWithRequiredPattern() {
diff --git a/Tests/SwiftLintFrameworkTests/FileLenghtRuleTests.swift b/Tests/SwiftLintFrameworkTests/FileLenghtRuleTests.swift
index dcc21f08..f341fa6a 100644
--- a/Tests/SwiftLintFrameworkTests/FileLenghtRuleTests.swift
+++ b/Tests/SwiftLintFrameworkTests/FileLenghtRuleTests.swift
@@ -13,7 +13,7 @@ class FileLenghtRuleTests: XCTestCase {
func testFileLengthWithDefaultConfiguration() {
verifyRule(FileLengthRule.description, commentDoesntViolate: false,
- testMultiByteOffsets: false)
+ testMultiByteOffsets: false, testShebang: false)
}
func testFileLengthIgnoringLinesWithOnlyComments() {
diff --git a/Tests/SwiftLintFrameworkTests/RulesTests.swift b/Tests/SwiftLintFrameworkTests/RulesTests.swift
index 9d5169b2..63528cee 100644
--- a/Tests/SwiftLintFrameworkTests/RulesTests.swift
+++ b/Tests/SwiftLintFrameworkTests/RulesTests.swift
@@ -141,7 +141,7 @@ class RulesTests: XCTestCase {
}
func testLeadingWhitespace() {
- verifyRule(LeadingWhitespaceRule.description, testMultiByteOffsets: false)
+ verifyRule(LeadingWhitespaceRule.description, testMultiByteOffsets: false, testShebang: false)
}
func testLegacyCGGeometryFunctions() {
@@ -161,7 +161,7 @@ class RulesTests: XCTestCase {
}
func testLetVarWhitespace() {
- verifyRule(LetVarWhitespaceRule.description)
+ verifyRule(LetVarWhitespaceRule.description, testShebang: false)
}
func testMark() {
@@ -202,7 +202,8 @@ class RulesTests: XCTestCase {
let description = OperatorUsageWhitespaceRule.description
.with(nonTriggeringExamples: ["#!/usr/bin/env swift\n"])
.with(triggeringExamples: []).with(corrections: [:])
- verifyRule(description, skipCommentTests: true, skipStringTests: true, testMultiByteOffsets: false)
+ verifyRule(description, skipCommentTests: true, skipStringTests: true, testMultiByteOffsets: false,
+ testShebang: false)
}
func testPrivateOverFilePrivate() {
diff --git a/Tests/SwiftLintFrameworkTests/TestHelpers.swift b/Tests/SwiftLintFrameworkTests/TestHelpers.swift
index 084b89c0..f132e0fb 100644
--- a/Tests/SwiftLintFrameworkTests/TestHelpers.swift
+++ b/Tests/SwiftLintFrameworkTests/TestHelpers.swift
@@ -135,6 +135,10 @@ private func addEmoji(_ string: String) -> String {
return "/* 👨👩👧👦👨👩👧👦👨👩👧👦 */\n\(string)"
}
+private func addShebang(_ string: String) -> String {
+ return "#!/usr/bin/env swift\n\(string)"
+}
+
extension XCTestCase {
// swiftlint:disable:next function_body_length
func verifyRule(_ ruleDescription: RuleDescription,
@@ -143,7 +147,8 @@ extension XCTestCase {
stringDoesntViolate: Bool = true,
skipCommentTests: Bool = false,
skipStringTests: Bool = false,
- testMultiByteOffsets: Bool = true) {
+ testMultiByteOffsets: Bool = true,
+ testShebang: Bool = true) {
guard let config = makeConfig(ruleConfiguration, ruleDescription.identifier) else {
XCTFail()
return
@@ -158,6 +163,11 @@ extension XCTestCase {
nonTriggers: nonTriggers.map(addEmoji), configuration: config)
}
+ if testShebang {
+ verifyExamples(triggers: triggers.map(addShebang),
+ nonTriggers: nonTriggers.map(addShebang), configuration: config)
+ }
+
// Comment doesn't violate
if !skipCommentTests {
XCTAssertEqual( |
Thanks! 🙏 |
By making a creative use of regions.
Fixes #1294.