From dd5c0d359910a4cbdf9f5d71e9cadab1379ffad8 Mon Sep 17 00:00:00 2001 From: Noah Gilmore Date: Sun, 8 Nov 2020 15:56:03 -0800 Subject: [PATCH 01/11] Add CommentSpacingRule (#3233) --- .../Models/PrimaryRuleList.swift | 1 + .../Rules/Lint/CommentSpacingRule.swift | 138 ++++++++++++++++++ Tests/LinuxMain.swift | 7 + .../AutomaticRuleTests.generated.swift | 6 + .../SwiftLintFrameworkTests/TestHelpers.swift | 3 +- 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift diff --git a/Source/SwiftLintFramework/Models/PrimaryRuleList.swift b/Source/SwiftLintFramework/Models/PrimaryRuleList.swift index 78610986f4..1316ea937a 100644 --- a/Source/SwiftLintFramework/Models/PrimaryRuleList.swift +++ b/Source/SwiftLintFramework/Models/PrimaryRuleList.swift @@ -16,6 +16,7 @@ public let primaryRuleList = RuleList(rules: [ CollectionAlignmentRule.self, ColonRule.self, CommaRule.self, + CommentSpacingRule.self, CompilerProtocolInitRule.self, ComputedAccessorsOrderRule.self, ConditionalReturnsOnNewlineRule.self, diff --git a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift new file mode 100644 index 0000000000..9436511331 --- /dev/null +++ b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift @@ -0,0 +1,138 @@ +import Foundation +import SourceKittenFramework + +public struct CommentSpacingRule: OptInRule, ConfigurationProviderRule, SubstitutionCorrectableRule, AutomaticTestableRule { + public var configuration = SeverityConfiguration(.warning) + + public init() {} + + public static let description = RuleDescription( + identifier: "comment_spacing", + name: "Comment Spacing", + description: "Prefer at least one space after slashes for comments.", + kind: .lint, + nonTriggeringExamples: [ + Example(""" + // This is a comment + """), + Example(""" + /// Triple slash comment + """), + Example(""" + // Multiline double-slash + // comment + """), + Example(""" + /// Multiline triple-slash + /// comment + """), + Example(""" + /// Multiline triple-slash + /// - This is indented + """), + Example(""" + // - MARK: Mark comment + """), + Example(""" + /* Asterisk comment */ + """), + Example(""" + /* + Multiline asterisk comment + */ + """) + ], + triggeringExamples: [ + Example(""" + //↓Something + """), + Example(""" + //↓MARK + """), + Example(""" + //↓👨‍👨‍👦‍👦Something + """), + Example(""" + func a() { + //↓This needs refactoring + print("Something") + } + //↓We should improve above function + """), + Example(""" + ///↓This is a comment + """), + Example(""" + /// Multiline triple-slash + ///↓This line is incorrect, though + """), + Example(""" + //↓- MARK: Mark comment + """) + ], + corrections: [ + Example("//↓Something"): Example("// Something"), + Example("//↓- MARK: Mark comment"): Example("// - MARK: Mark comment"), + Example(""" + /// Multiline triple-slash + ///↓This line is incorrect, though + """): Example(""" + /// Multiline triple-slash + /// This line is incorrect, though + """), + Example(""" + func a() { + //↓This needs refactoring + print("Something") + } + //↓We should improve above function + """): Example(""" + func a() { + // This needs refactoring + print("Something") + } + // We should improve above function + """) + ] + ) + + public func violationRanges(in file: SwiftLintFile) -> [NSRange] { + let commentTokens = file.syntaxMap.tokens.filter { [.comment, .docComment].contains($0.kind) } + return commentTokens.compactMap { (token: SwiftLintSyntaxToken) -> [NSRange]? in + guard let commentBody = file.stringView.substringWithByteRange(token.range).map(StringView.init) else { + return nil + } + return regex("^(\\/){2,3}[^\\s\\/]").matches(in: commentBody, options: .anchored) + .compactMap { result in + // Set the location to be directly before the first non-slash, + // non-whitespace character which was matched + guard let characterRange = file.stringView.byteRangeToNSRange( + ByteRange( + location: ByteCount( + token.range.lowerBound.value + result.range.upperBound - 1 + ), + length: ByteCount(1) + ) + ) else { + return nil + } + return characterRange + } + }.flatMap { $0 } + } + + public func validate(file: SwiftLintFile) -> [StyleViolation] { + return violationRanges(in: file).map { range in + StyleViolation( + ruleDescription: Self.description, + severity: configuration.severity, + location: Location(file: file, characterOffset: range.location) + ) + } + } + + public func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? { + let violationCharacters = file.stringView.substring(with: violationRange) + return (violationRange, " \(violationCharacters)") + } +} diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 15d2311312..f611276030 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -136,6 +136,12 @@ extension CommandTests { ] } +extension CommentSpacingRuleTests { + static var allTests: [(String, (CommentSpacingRuleTests) -> () throws -> Void)] = [ + ("testWithDefaultConfiguration", testWithDefaultConfiguration) + ] +} + extension CompilerProtocolInitRuleTests { static var allTests: [(String, (CompilerProtocolInitRuleTests) -> () throws -> Void)] = [ ("testWithDefaultConfiguration", testWithDefaultConfiguration), @@ -1756,6 +1762,7 @@ XCTMain([ testCase(ColonRuleTests.allTests), testCase(CommaRuleTests.allTests), testCase(CommandTests.allTests), + testCase(CommentSpacingRuleTests.allTests), testCase(CompilerProtocolInitRuleTests.allTests), testCase(ComputedAccessorsOrderRuleTests.allTests), testCase(ConditionalReturnsOnNewlineRuleTests.allTests), diff --git a/Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift b/Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift index 29ee779700..de101f9045 100644 --- a/Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift +++ b/Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift @@ -66,6 +66,12 @@ class CommaRuleTests: XCTestCase { } } +class CommentSpacingRuleTests: XCTestCase { + func testWithDefaultConfiguration() { + verifyRule(CommentSpacingRule.description) + } +} + class ContainsOverFilterCountRuleTests: XCTestCase { func testWithDefaultConfiguration() { verifyRule(ContainsOverFilterCountRule.description) diff --git a/Tests/SwiftLintFrameworkTests/TestHelpers.swift b/Tests/SwiftLintFrameworkTests/TestHelpers.swift index b7f84560b0..75848202ba 100644 --- a/Tests/SwiftLintFrameworkTests/TestHelpers.swift +++ b/Tests/SwiftLintFrameworkTests/TestHelpers.swift @@ -350,6 +350,7 @@ extension XCTestCase { XCTAssertEqual( triggers.flatMap({ makeViolations($0.with(code: "/*\n " + $0.code + "\n */")) }).count, commentDoesntViolate ? 0 : triggers.count, + "Violation(s) still triggered when code was nested inside comment", file: (file), line: line ) } @@ -433,7 +434,7 @@ extension XCTestCase { let violationsAtUnexpectedLocation = triggerViolations .filter { !expectedLocations.contains($0.location) } if !violationsAtUnexpectedLocation.isEmpty { - XCTFail("triggeringExample violate at unexpected location: \n" + + XCTFail("triggeringExample violated at unexpected location: \n" + "\(render(violations: violationsAtUnexpectedLocation, in: trigger.code))", file: trigger.file, line: trigger.line) From 1a104e4dc44257f3ad41931171af7ad145660e54 Mon Sep 17 00:00:00 2001 From: Noah Gilmore Date: Sun, 8 Nov 2020 17:03:06 -0800 Subject: [PATCH 02/11] Add comments --- .../SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift index 9436511331..14a3570b50 100644 --- a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift +++ b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift @@ -97,11 +97,14 @@ public struct CommentSpacingRule: OptInRule, ConfigurationProviderRule, Substitu ) public func violationRanges(in file: SwiftLintFile) -> [NSRange] { + // Find all comment tokens in the file and regex search them for violations let commentTokens = file.syntaxMap.tokens.filter { [.comment, .docComment].contains($0.kind) } return commentTokens.compactMap { (token: SwiftLintSyntaxToken) -> [NSRange]? in guard let commentBody = file.stringView.substringWithByteRange(token.range).map(StringView.init) else { return nil } + // Look for 2-3 slash characters followed immediately by a non-whitespace, non-slash + // character (this is a violation) return regex("^(\\/){2,3}[^\\s\\/]").matches(in: commentBody, options: .anchored) .compactMap { result in // Set the location to be directly before the first non-slash, @@ -133,6 +136,8 @@ public struct CommentSpacingRule: OptInRule, ConfigurationProviderRule, Substitu public func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? { let violationCharacters = file.stringView.substring(with: violationRange) + // Since the violation range is just the first character after the slashes, all we have to + // do is prepend a single space return (violationRange, " \(violationCharacters)") } } From 3508ef8e1e0aa8029be628d687af0385b8420086 Mon Sep 17 00:00:00 2001 From: Noah Gilmore Date: Sun, 8 Nov 2020 17:04:29 -0800 Subject: [PATCH 03/11] Add changelog entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 074996cb7a..c30132a456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -452,7 +452,9 @@ This is the last release to support building with Swift 5.0.x. #### Enhancements -* None. +* Add `comment_spacing` rule. + [Noah Gilmore](https://github.com/noahsark769) + [#3233](https://github.com/realm/SwiftLint/issues/3233) #### Bug Fixes From 442eac25567be1afdd587924ae1b0ed7324719c8 Mon Sep 17 00:00:00 2001 From: Noah Gilmore Date: Mon, 9 Nov 2020 13:04:30 -0800 Subject: [PATCH 04/11] Update Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift Co-authored-by: JP Simard --- Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift index 14a3570b50..093c011739 100644 --- a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift +++ b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift @@ -98,7 +98,7 @@ public struct CommentSpacingRule: OptInRule, ConfigurationProviderRule, Substitu public func violationRanges(in file: SwiftLintFile) -> [NSRange] { // Find all comment tokens in the file and regex search them for violations - let commentTokens = file.syntaxMap.tokens.filter { [.comment, .docComment].contains($0.kind) } + let commentTokens = file.syntaxMap.tokens.filter { SyntaxKind.commentKinds.contains($0.kind) } return commentTokens.compactMap { (token: SwiftLintSyntaxToken) -> [NSRange]? in guard let commentBody = file.stringView.substringWithByteRange(token.range).map(StringView.init) else { return nil From 6bd38e86076b89569ac312f818248fddac999210 Mon Sep 17 00:00:00 2001 From: Noah Gilmore Date: Mon, 9 Nov 2020 13:04:37 -0800 Subject: [PATCH 05/11] Update Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift Co-authored-by: JP Simard --- Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift index 093c011739..be84e84a3b 100644 --- a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift +++ b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift @@ -105,7 +105,7 @@ public struct CommentSpacingRule: OptInRule, ConfigurationProviderRule, Substitu } // Look for 2-3 slash characters followed immediately by a non-whitespace, non-slash // character (this is a violation) - return regex("^(\\/){2,3}[^\\s\\/]").matches(in: commentBody, options: .anchored) + return regex(#"^(\/){2,3}[^\s\/]"#).matches(in: commentBody, options: .anchored) .compactMap { result in // Set the location to be directly before the first non-slash, // non-whitespace character which was matched From 5108233ac55b7fb1f133b8055d73636394d71f30 Mon Sep 17 00:00:00 2001 From: Noah Gilmore Date: Mon, 9 Nov 2020 21:53:51 -0800 Subject: [PATCH 06/11] Further PR comments --- .../Rules/Lint/CommentSpacingRule.swift | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift index be84e84a3b..ed0101816d 100644 --- a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift +++ b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift @@ -1,7 +1,10 @@ import Foundation import SourceKittenFramework -public struct CommentSpacingRule: OptInRule, ConfigurationProviderRule, SubstitutionCorrectableRule, AutomaticTestableRule { +public struct CommentSpacingRule: OptInRule, + ConfigurationProviderRule, + SubstitutionCorrectableRule, + AutomaticTestableRule { public var configuration = SeverityConfiguration(.warning) public init() {} @@ -98,28 +101,32 @@ public struct CommentSpacingRule: OptInRule, ConfigurationProviderRule, Substitu public func violationRanges(in file: SwiftLintFile) -> [NSRange] { // Find all comment tokens in the file and regex search them for violations - let commentTokens = file.syntaxMap.tokens.filter { SyntaxKind.commentKinds.contains($0.kind) } + let commentTokens = file.syntaxMap.tokens.filter { + guard let kind = $0.kind else { return false } + return SyntaxKind.commentKinds.contains(kind) + } return commentTokens.compactMap { (token: SwiftLintSyntaxToken) -> [NSRange]? in - guard let commentBody = file.stringView.substringWithByteRange(token.range).map(StringView.init) else { - return nil - } - // Look for 2-3 slash characters followed immediately by a non-whitespace, non-slash - // character (this is a violation) - return regex(#"^(\/){2,3}[^\s\/]"#).matches(in: commentBody, options: .anchored) - .compactMap { result in - // Set the location to be directly before the first non-slash, - // non-whitespace character which was matched - guard let characterRange = file.stringView.byteRangeToNSRange( - ByteRange( - location: ByteCount( - token.range.lowerBound.value + result.range.upperBound - 1 - ), - length: ByteCount(1) - ) - ) else { - return nil - } - return characterRange + return file.stringView + .substringWithByteRange(token.range) + .map(StringView.init).map { commentBody in + // Look for 2-3 slash characters followed immediately by a non-whitespace, non-slash + // character (this is a violation) + return regex(#"^(\/){2,3}[^\s\/]"#).matches(in: commentBody, options: .anchored) + .compactMap { result in + // Set the location to be directly before the first non-slash, + // non-whitespace character which was matched + guard let characterRange = file.stringView.byteRangeToNSRange( + ByteRange( + location: ByteCount( + token.range.lowerBound.value + result.range.upperBound - 1 + ), + length: ByteCount(1) + ) + ) else { + return nil + } + return characterRange + } } }.flatMap { $0 } } From 5185afc4a41ef30271c14a80039ad36c03dca691 Mon Sep 17 00:00:00 2001 From: Noah Gilmore Date: Mon, 9 Nov 2020 21:57:01 -0800 Subject: [PATCH 07/11] Update Changelog --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c30132a456..4dad08752e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,10 @@ `unused_import` rule. [Keith Smiley](https://github.com/keith) +* Add `comment_spacing` rule. + [Noah Gilmore](https://github.com/noahsark769) + [#3233](https://github.com/realm/SwiftLint/issues/3233) + #### Bug Fixes * None. @@ -452,9 +456,7 @@ This is the last release to support building with Swift 5.0.x. #### Enhancements -* Add `comment_spacing` rule. - [Noah Gilmore](https://github.com/noahsark769) - [#3233](https://github.com/realm/SwiftLint/issues/3233) +* None. #### Bug Fixes From 30db88dde31bdcaf530980768b0fc0b72658fd85 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Tue, 10 Nov 2020 12:28:28 -0500 Subject: [PATCH 08/11] Add double trailing space to changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dad08752e..30d2ad905e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,7 +55,7 @@ `unused_import` rule. [Keith Smiley](https://github.com/keith) -* Add `comment_spacing` rule. +* Add `comment_spacing` rule. [Noah Gilmore](https://github.com/noahsark769) [#3233](https://github.com/realm/SwiftLint/issues/3233) From 869fe868b3338ff7b86a137215cb3125b5bac54d Mon Sep 17 00:00:00 2001 From: JP Simard Date: Tue, 10 Nov 2020 12:42:40 -0500 Subject: [PATCH 09/11] Apply minor refactorings 1. Add some comments 2. Name variables when used in multiline closures 3. Change violation range length from 1 to 0, which simplifies the substitution 4. Tweak indentation --- .../Rules/Lint/CommentSpacingRule.swift | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift index ed0101816d..cc96f329e6 100644 --- a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift +++ b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift @@ -101,34 +101,33 @@ public struct CommentSpacingRule: OptInRule, public func violationRanges(in file: SwiftLintFile) -> [NSRange] { // Find all comment tokens in the file and regex search them for violations - let commentTokens = file.syntaxMap.tokens.filter { - guard let kind = $0.kind else { return false } + let commentTokens = file.syntaxMap.tokens.filter { token in + guard let kind = token.kind else { return false } return SyntaxKind.commentKinds.contains(kind) } - return commentTokens.compactMap { (token: SwiftLintSyntaxToken) -> [NSRange]? in - return file.stringView - .substringWithByteRange(token.range) - .map(StringView.init).map { commentBody in - // Look for 2-3 slash characters followed immediately by a non-whitespace, non-slash - // character (this is a violation) - return regex(#"^(\/){2,3}[^\s\/]"#).matches(in: commentBody, options: .anchored) - .compactMap { result in + return commentTokens + .compactMap { (token: SwiftLintSyntaxToken) -> [NSRange]? in + return file.stringView + .substringWithByteRange(token.range) + .map(StringView.init) + .map { commentBody in + // Look for 2-3 slash characters followed immediately by a non-whitespace, non-slash + // character (this is a violation) + regex(#"^(\/){2,3}[^\s\/]"#).matches(in: commentBody, options: .anchored).compactMap { result in // Set the location to be directly before the first non-slash, // non-whitespace character which was matched - guard let characterRange = file.stringView.byteRangeToNSRange( + return file.stringView.byteRangeToNSRange( ByteRange( - location: ByteCount( - token.range.lowerBound.value + result.range.upperBound - 1 - ), - length: ByteCount(1) + // Safe to mix NSRange offsets with byte offsets here because the regex can't + // contain multi-byte characters + location: ByteCount(token.range.lowerBound.value + result.range.upperBound - 1), + length: 0 ) - ) else { - return nil - } - return characterRange + ) } - } - }.flatMap { $0 } + } + } + .flatMap { $0 } } public func validate(file: SwiftLintFile) -> [StyleViolation] { @@ -142,9 +141,6 @@ public struct CommentSpacingRule: OptInRule, } public func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? { - let violationCharacters = file.stringView.substring(with: violationRange) - // Since the violation range is just the first character after the slashes, all we have to - // do is prepend a single space - return (violationRange, " \(violationCharacters)") + return (violationRange, " ") } } From bf2790df5421ea480a69dac22c26800f89717ee0 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Tue, 10 Nov 2020 12:47:04 -0500 Subject: [PATCH 10/11] Enable CommentSpacingRule by default And fix violations in SwiftLint --- .../Extensions/SwiftLintFile+Regex.swift | 1 - .../Rules/Lint/CommentSpacingRule.swift | 3 +-- .../OverridenSuperCallConfiguration.swift | 10 +++++----- .../Rules/Style/OpeningBraceRule.swift | 2 +- .../Rules/Style/VerticalWhitespaceRule.swift | 2 +- .../ExplicitTypeInterfaceRuleTests.swift | 2 +- Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift | 2 +- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Source/SwiftLintFramework/Extensions/SwiftLintFile+Regex.swift b/Source/SwiftLintFramework/Extensions/SwiftLintFile+Regex.swift index a89e40821b..c42ec394df 100644 --- a/Source/SwiftLintFramework/Extensions/SwiftLintFile+Regex.swift +++ b/Source/SwiftLintFramework/Extensions/SwiftLintFile+Regex.swift @@ -191,7 +191,6 @@ extension SwiftLintFile { return tokens.map { $0.kinds } } - //Added by S2dent /** This function returns only matches that are not contained in a syntax kind specified. diff --git a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift index cc96f329e6..070aa89682 100644 --- a/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift +++ b/Source/SwiftLintFramework/Rules/Lint/CommentSpacingRule.swift @@ -1,8 +1,7 @@ import Foundation import SourceKittenFramework -public struct CommentSpacingRule: OptInRule, - ConfigurationProviderRule, +public struct CommentSpacingRule: ConfigurationProviderRule, SubstitutionCorrectableRule, AutomaticTestableRule { public var configuration = SeverityConfiguration(.warning) diff --git a/Source/SwiftLintFramework/Rules/RuleConfigurations/OverridenSuperCallConfiguration.swift b/Source/SwiftLintFramework/Rules/RuleConfigurations/OverridenSuperCallConfiguration.swift index ac5aa40588..e3a9fe9d99 100644 --- a/Source/SwiftLintFramework/Rules/RuleConfigurations/OverridenSuperCallConfiguration.swift +++ b/Source/SwiftLintFramework/Rules/RuleConfigurations/OverridenSuperCallConfiguration.swift @@ -1,16 +1,16 @@ public struct OverridenSuperCallConfiguration: RuleConfiguration, Equatable { private let defaultIncluded = [ - //NSObject + // NSObject "awakeFromNib()", "prepareForInterfaceBuilder()", - //UICollectionViewLayout + // UICollectionViewLayout "invalidateLayout()", "invalidateLayout(with:)", "invalidateLayoutWithContext(_:)", - //UIView + // UIView "prepareForReuse()", "updateConstraints()", - //UIViewController + // UIViewController "addChildViewController(_:)", "decodeRestorableState(with:)", "decodeRestorableStateWithCoder(_:)", @@ -27,7 +27,7 @@ public struct OverridenSuperCallConfiguration: RuleConfiguration, Equatable { "viewDidLoad()", "viewWillAppear(_:)", "viewWillDisappear(_:)", - //XCTestCase + // XCTestCase "setUp()", "setUpWithError()", "tearDown()", diff --git a/Source/SwiftLintFramework/Rules/Style/OpeningBraceRule.swift b/Source/SwiftLintFramework/Rules/Style/OpeningBraceRule.swift index a12e9ef112..35e249b1fe 100644 --- a/Source/SwiftLintFramework/Rules/Style/OpeningBraceRule.swift +++ b/Source/SwiftLintFramework/Rules/Style/OpeningBraceRule.swift @@ -37,7 +37,7 @@ private extension SwiftLintFile { return false } - //First non-whitespace character should be "(" - otherwise it is not an anonymous closure + // First non-whitespace character should be "(" - otherwise it is not an anonymous closure let afterBracketCode = closureCode.substring(from: closingBracketPosition + 1) .trimmingCharacters(in: .whitespaces) return afterBracketCode.first == "(" diff --git a/Source/SwiftLintFramework/Rules/Style/VerticalWhitespaceRule.swift b/Source/SwiftLintFramework/Rules/Style/VerticalWhitespaceRule.swift index fa2293099f..4890c694d1 100644 --- a/Source/SwiftLintFramework/Rules/Style/VerticalWhitespaceRule.swift +++ b/Source/SwiftLintFramework/Rules/Style/VerticalWhitespaceRule.swift @@ -134,7 +134,7 @@ public struct VerticalWhitespaceRule: CorrectableRule, ConfigurationProviderRule let description = Self.description let location = Location(file: file, characterOffset: currentLine.range.location) - //reports every line that is being deleted + // reports every line that is being deleted corrections.append(Correction(ruleDescription: description, location: location)) continue // skips line } diff --git a/Tests/SwiftLintFrameworkTests/ExplicitTypeInterfaceRuleTests.swift b/Tests/SwiftLintFrameworkTests/ExplicitTypeInterfaceRuleTests.swift index e872117c28..681385246f 100644 --- a/Tests/SwiftLintFrameworkTests/ExplicitTypeInterfaceRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/ExplicitTypeInterfaceRuleTests.swift @@ -149,7 +149,7 @@ class ExplicitTypeInterfaceRuleTests: XCTestCase { verifyRule(description) } - //swiftlint:disable function_body_length + // swiftlint:disable function_body_length func testSwitchCaseDeclarations() { guard SwiftVersion.current >= .fourDotOne else { return diff --git a/Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift b/Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift index 79ff500620..2a7093e1cf 100644 --- a/Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift +++ b/Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift @@ -78,7 +78,7 @@ class ModifierOrderTests: XCTestCase { "override"]]) } - //swiftlint:disable function_body_length + // swiftlint:disable function_body_length func testAtPrefixedGroup() { let descriptionOverride = RuleDescription( identifier: "modifier_order", From 6d4487c5179fcdc20005654a110d5716660fdedb Mon Sep 17 00:00:00 2001 From: Noah Gilmore Date: Tue, 10 Nov 2020 16:08:25 -0800 Subject: [PATCH 11/11] Fix a few test which failed due to comment_spacing being a default rule --- Tests/SwiftLintFrameworkTests/CommandTests.swift | 8 ++++---- Tests/SwiftLintFrameworkTests/LineEndingTests.swift | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/SwiftLintFrameworkTests/CommandTests.swift b/Tests/SwiftLintFrameworkTests/CommandTests.swift index af01657a55..ef01e37919 100644 --- a/Tests/SwiftLintFrameworkTests/CommandTests.swift +++ b/Tests/SwiftLintFrameworkTests/CommandTests.swift @@ -257,22 +257,22 @@ class CommandTests: XCTestCase { func testDisableAllOverridesSuperfluousDisableCommand() { XCTAssert( violations( - Example("//swiftlint:disable all\n// swiftlint:disable nesting\nprint(123)\n") + Example("// swiftlint:disable all\n// swiftlint:disable nesting\nprint(123)\n") ).isEmpty ) XCTAssert( violations( - Example("//swiftlint:disable all\n// swiftlint:disable:next nesting\nprint(123)\n") + Example("// swiftlint:disable all\n// swiftlint:disable:next nesting\nprint(123)\n") ).isEmpty ) XCTAssert( violations( - Example("//swiftlint:disable all\n// swiftlint:disable:this nesting\nprint(123)\n") + Example("// swiftlint:disable all\n// swiftlint:disable:this nesting\nprint(123)\n") ).isEmpty ) XCTAssert( violations( - Example("//swiftlint:disable all\n// swiftlint:disable:previous nesting\nprint(123)\n") + Example("// swiftlint:disable all\n// swiftlint:disable:previous nesting\nprint(123)\n") ).isEmpty ) } diff --git a/Tests/SwiftLintFrameworkTests/LineEndingTests.swift b/Tests/SwiftLintFrameworkTests/LineEndingTests.swift index eb4b384698..0385befee1 100644 --- a/Tests/SwiftLintFrameworkTests/LineEndingTests.swift +++ b/Tests/SwiftLintFrameworkTests/LineEndingTests.swift @@ -5,7 +5,7 @@ class LineEndingTests: XCTestCase { func testCarriageReturnDoesNotCauseError() { XCTAssert( violations( - Example("//swiftlint:disable all\r\nprint(123)\r\n") + Example("// swiftlint:disable all\r\nprint(123)\r\n") ).isEmpty ) }