diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fd6e5c7f1..6c08ac4af3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,8 +121,7 @@ * Make `empty_count` auto-correctable. [KS1019](https://github.com/KS1019/) -* Add new `functions_arguments_spacing` rule to remove the space before the first function argument - and after the last argument. +* Add new `no_unnecessary_spaces` rule that No space before the first and after the last argument and exactly one space after every comma. [u-abyss](https://github.com/u-abyss) [#5259](https://github.com/realm/SwiftLint/issues/5224) diff --git a/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift b/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift index 4b9ce7db26..38e60a5364 100644 --- a/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift +++ b/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift @@ -78,7 +78,6 @@ public let builtInRules: [any Rule.Type] = [ ForceCastRule.self, ForceTryRule.self, ForceUnwrappingRule.self, - FunctionArgumentsSpacingRule.self, FunctionBodyLengthRule.self, FunctionDefaultParameterAtEndRule.self, FunctionParameterCountRule.self, @@ -135,6 +134,7 @@ public let builtInRules: [any Rule.Type] = [ NonOptionalStringDataConversionRule.self, NonOverridableClassDeclarationRule.self, NotificationCenterDetachmentRule.self, + NoUnnecessarySpacesRule.self, NumberSeparatorRule.self, ObjectLiteralRule.self, OneDelarationPerFileRule.self, diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/FunctionArgumentsSpacingRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/NoUnnecessarySpacesRule.swift similarity index 94% rename from Source/SwiftLintBuiltInRules/Rules/Lint/FunctionArgumentsSpacingRule.swift rename to Source/SwiftLintBuiltInRules/Rules/Lint/NoUnnecessarySpacesRule.swift index 54b686d14c..bca94525d0 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/FunctionArgumentsSpacingRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/NoUnnecessarySpacesRule.swift @@ -1,13 +1,13 @@ import SwiftSyntax @SwiftSyntaxRule -struct FunctionArgumentsSpacingRule: Rule { +struct NoUnnecessarySpacesRule: Rule { var configuration = SeverityConfiguration(.warning) static let description = RuleDescription( - identifier: "functions_arguments_spacing", - name: "Function Arguments Spacing", - description: "Remove the space before the first function argument and after the last argument", + identifier: "no_unnecessary_spaces", + name: "no Unnecessary Spaces", + description: "No space before the first and after the last argument and exactly one space after every comma", kind: .lint, nonTriggeringExamples: [ Example("f()"), @@ -75,7 +75,7 @@ private extension TriviaPiece { } } -private extension FunctionArgumentsSpacingRule { +private extension NoUnnecessarySpacesRule { final class Visitor: ViolationsSyntaxVisitor { override func visitPost(_ node: FunctionCallExprSyntax) { guard let leftParen = node.leftParen else { return } diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/VerticalWhitespaceRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/VerticalWhitespaceRule.swift index c7c509d728..70751ab2a9 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/VerticalWhitespaceRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/VerticalWhitespaceRule.swift @@ -26,7 +26,7 @@ struct VerticalWhitespaceRule: CorrectableRule { Example("let b = 0\n\n\nclass AAA {}\n"): Example("let b = 0\n\nclass AAA {}\n"), Example("let c = 0\n\n\nlet num = 1\n"): Example("let c = 0\n\nlet num = 1\n"), Example("// bca \n\n\n"): Example("// bca \n\n") - ]// End of line autocorrections are handled by Trailing Newline Rule. + ] // End of line autocorrections are handled by Trailing Newline Rule. ) private var configuredDescriptionReason: String { diff --git a/Tests/GeneratedTests/GeneratedTests.swift b/Tests/GeneratedTests/GeneratedTests.swift index a183d813e9..d12375506b 100644 --- a/Tests/GeneratedTests/GeneratedTests.swift +++ b/Tests/GeneratedTests/GeneratedTests.swift @@ -458,12 +458,6 @@ class ForceUnwrappingRuleGeneratedTests: SwiftLintTestCase { } } -class FunctionArgumentsSpacingRuleGeneratedTests: SwiftLintTestCase { - func testWithDefaultConfiguration() { - verifyRule(FunctionArgumentsSpacingRule.description) - } -} - class FunctionBodyLengthRuleGeneratedTests: SwiftLintTestCase { func testWithDefaultConfiguration() { verifyRule(FunctionBodyLengthRule.description) @@ -800,6 +794,12 @@ class NotificationCenterDetachmentRuleGeneratedTests: SwiftLintTestCase { } } +class NoUnnecessarySpacesRuleGeneratedTests: SwiftLintTestCase { + func testWithDefaultConfiguration() { + verifyRule(NoUnnecessarySpacesRule.description) + } +} + class NumberSeparatorRuleGeneratedTests: SwiftLintTestCase { func testWithDefaultConfiguration() { verifyRule(NumberSeparatorRule.description) diff --git a/Tests/SwiftLintFrameworkTests/FunctionArgumentsSpacingRuleTests.swift b/Tests/SwiftLintFrameworkTests/FunctionArgumentsSpacingRuleTests.swift deleted file mode 100644 index 45fb57e6a0..0000000000 --- a/Tests/SwiftLintFrameworkTests/FunctionArgumentsSpacingRuleTests.swift +++ /dev/null @@ -1,8 +0,0 @@ -@testable import SwiftLintBuiltInRules - -class FunctionArgumentsSpacingRuleTests: SwiftLintTestCase { - func testFunctionArgumentsSpacingRule() { - let description = FunctionArgumentsSpacingRule.description - verifyRule(description) - } -} diff --git a/Tests/SwiftLintFrameworkTests/NoUnnecessarySpacesRuleTests.swift b/Tests/SwiftLintFrameworkTests/NoUnnecessarySpacesRuleTests.swift new file mode 100644 index 0000000000..78044eb593 --- /dev/null +++ b/Tests/SwiftLintFrameworkTests/NoUnnecessarySpacesRuleTests.swift @@ -0,0 +1,8 @@ +@testable import SwiftLintBuiltInRules + +class NoUnnecessarySpacesRuleTests: SwiftLintTestCase { + func testNoUnnecessarySpacesRule() { + let description = NoUnnecessarySpacesRule.description + verifyRule(description) + } +}