From b744cf08f1b2a67512a6e88e02f29596e410814f Mon Sep 17 00:00:00 2001 From: JP Simard Date: Tue, 11 Feb 2020 13:40:04 -0800 Subject: [PATCH] Temporarily remove all SwiftSyntax rules and support (#3107) The new rules introduced in 0.39.0 that depend on SwiftSyntax have been temporarily removed as we work out release packaging issues. * `prohibited_nan_comparison` * `return_value_from_void_function` * `tuple_pattern` * `void_function_in_ternary` See https://github.com/realm/SwiftLint/issues/3105 for details. --- .gitmodules | 3 - .swiftlint.yml | 4 - CHANGELOG.md | 9 +- Package.resolved | 9 - Package.swift | 15 +- README.md | 2 +- .../Extensions/SwiftLintFile+Cache.swift | 36 --- .../Models/MasterRuleList.swift | 4 - .../Protocols/SyntaxRule.swift | 44 ---- .../ReturnValueFromVoidFunctionRule.swift | 76 ------ ...urnValueFromVoidFunctionRuleExamples.swift | 234 ------------------ .../Rules/Idiomatic/TuplePatternRule.swift | 90 ------- .../VoidFunctionInTernaryConditionRule.swift | 110 -------- .../Lint/PhohibitedNaNComparisonRule.swift | 99 -------- SwiftLint.xcodeproj/project.pbxproj | 48 +--- .../contents.xcworkspacedata | 3 - SwiftSyntax | 1 - Tests/LinuxMain.swift | 28 --- .../AutomaticRuleTests.generated.swift | 24 -- .../ConfigurationTests+Nested.swift | 6 +- azure-pipelines.yml | 8 +- script/bootstrap | 2 - 22 files changed, 23 insertions(+), 832 deletions(-) delete mode 100644 Source/SwiftLintFramework/Protocols/SyntaxRule.swift delete mode 100644 Source/SwiftLintFramework/Rules/Idiomatic/ReturnValueFromVoidFunctionRule.swift delete mode 100644 Source/SwiftLintFramework/Rules/Idiomatic/ReturnValueFromVoidFunctionRuleExamples.swift delete mode 100644 Source/SwiftLintFramework/Rules/Idiomatic/TuplePatternRule.swift delete mode 100644 Source/SwiftLintFramework/Rules/Idiomatic/VoidFunctionInTernaryConditionRule.swift delete mode 100644 Source/SwiftLintFramework/Rules/Lint/PhohibitedNaNComparisonRule.swift delete mode 160000 SwiftSyntax diff --git a/.gitmodules b/.gitmodules index 4979a82c69..d451957f2e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,6 +16,3 @@ [submodule "Carthage/Checkouts/Yams"] path = Carthage/Checkouts/Yams url = https://github.com/jpsim/Yams.git -[submodule "SwiftSyntax"] - path = SwiftSyntax - url = https://github.com/apple/swift-syntax.git diff --git a/.swiftlint.yml b/.swiftlint.yml index 2ef7c85a42..0804f37002 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -50,7 +50,6 @@ opt_in_rules: - private_action - private_outlet - prohibited_interface_builder - - prohibited_nan_comparison - prohibited_super_call - quick_discouraged_call - quick_discouraged_focused_test @@ -58,14 +57,12 @@ opt_in_rules: - reduce_into - redundant_nil_coalescing - redundant_type_annotation - - return_value_from_void_function - single_test_class - sorted_first_last - sorted_imports - static_operator - strong_iboutlet - toggle_bool - - tuple_pattern - unavailable_function - unneeded_parentheses_in_closure_argument - unowned_variable_capture @@ -73,7 +70,6 @@ opt_in_rules: - vertical_parameter_alignment_on_call - vertical_whitespace_closing_braces - vertical_whitespace_opening_braces - - void_function_in_ternary - xct_specific_matcher - yoda_condition diff --git a/CHANGELOG.md b/CHANGELOG.md index 6639349fe1..a2c7c5bd10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,14 @@ #### Breaking -* None. +* The new rules introduced in 0.39.0 that depend on SwiftSyntax have been + temporarily removed as we work out release packaging issues. + * `prohibited_nan_comparison` + * `return_value_from_void_function` + * `tuple_pattern` + * `void_function_in_ternary` + [JP Simard](https://github.com/jpsim) + [#3105](https://github.com/realm/SwiftLint/issues/3105) #### Experimental diff --git a/Package.resolved b/Package.resolved index 8f440c17e5..ad29737fff 100644 --- a/Package.resolved +++ b/Package.resolved @@ -55,15 +55,6 @@ "version": "0.29.0" } }, - { - "package": "SwiftSyntax", - "repositoryURL": "https://github.com/apple/swift-syntax.git", - "state": { - "branch": null, - "revision": "3e3eb191fcdbecc6031522660c4ed6ce25282c25", - "version": "0.50100.0" - } - }, { "package": "SwiftyTextTable", "repositoryURL": "https://github.com/scottrhoyt/SwiftyTextTable.git", diff --git a/Package.swift b/Package.swift index dfe1a024bb..99a64d209b 100644 --- a/Package.swift +++ b/Package.swift @@ -7,17 +7,8 @@ private let addCryptoSwift = false private let addCryptoSwift = true #endif -#if compiler(>=5.1.0) -private let addSwiftSyntax = true -#else -private let addSwiftSyntax = false -#endif - let package = Package( name: "SwiftLint", - platforms: [ - .macOS(.v10_12) - ], products: [ .executable(name: "swiftlint", targets: ["swiftlint"]), .library(name: "SwiftLintFramework", targets: ["SwiftLintFramework"]) @@ -27,8 +18,7 @@ let package = Package( .package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMinor(from: "0.29.0")), .package(url: "https://github.com/jpsim/Yams.git", from: "2.0.0"), .package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"), - ] + (addCryptoSwift ? [.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMinor(from: "1.0.0"))] : []) + - (addSwiftSyntax ? [.package(url: "https://github.com/apple/swift-syntax.git", .exact("0.50100.0"))] : []), + ] + (addCryptoSwift ? [.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMinor(from: "1.0.0"))] : []), targets: [ .target( name: "swiftlint", @@ -43,8 +33,7 @@ let package = Package( dependencies: [ "SourceKittenFramework", "Yams", - ] + (addCryptoSwift ? ["CryptoSwift"] : []) + - (addSwiftSyntax ? ["SwiftSyntax"] : []) + ] + (addCryptoSwift ? ["CryptoSwift"] : []) ), .testTarget( name: "SwiftLintFrameworkTests", diff --git a/README.md b/README.md index b65ac5b6f7..7494e77487 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ running it. ### Compiling from source: You can also build from source by cloning this project and running -`script/bootstrap; make install` (Xcode 11.0 or later). +`git submodule update --init --recursive; make install` (Xcode 10.2 or later). ### Known Installation Issues On MacOS Before 10.14.4 diff --git a/Source/SwiftLintFramework/Extensions/SwiftLintFile+Cache.swift b/Source/SwiftLintFramework/Extensions/SwiftLintFile+Cache.swift index 52849cb9ae..36b7d609e2 100644 --- a/Source/SwiftLintFramework/Extensions/SwiftLintFile+Cache.swift +++ b/Source/SwiftLintFramework/Extensions/SwiftLintFile+Cache.swift @@ -1,8 +1,5 @@ import Foundation import SourceKittenFramework -#if canImport(SwiftSyntax) -import SwiftSyntax -#endif private typealias FileCacheKey = Int private var responseCache = Cache({ file -> [String: SourceKitRepresentable]? in @@ -33,20 +30,6 @@ private var syntaxMapCache = Cache({ file in private var syntaxKindsByLinesCache = Cache({ file in file.syntaxKindsByLine() }) private var syntaxTokensByLinesCache = Cache({ file in file.syntaxTokensByLine() }) -#if canImport(SwiftSyntax) -private var syntaxCache = Cache({ file -> SourceFileSyntax? in - do { - if let path = file.path { - return try SyntaxParser.parse(URL(fileURLWithPath: path)) - } - - return try SyntaxParser.parse(source: file.contents) - } catch { - return nil - } -}) -#endif - internal typealias AssertHandler = () -> Void private var assertHandlers = [FileCacheKey: AssertHandler]() @@ -175,19 +158,6 @@ extension SwiftLintFile { return syntaxMap } - #if canImport(SwiftSyntax) - internal var syntax: SourceFileSyntax { - guard let syntax = syntaxCache.get(self) else { - if let handler = assertHandler { - handler() - return SourceFileSyntax({ _ in }) - } - queuedFatalError("Never call this for file that sourcekitd fails.") - } - return syntax - } - #endif - internal var syntaxTokensByLines: [[SwiftLintSyntaxToken]] { guard let syntaxTokensByLines = syntaxTokensByLinesCache.get(self) else { if let handler = assertHandler { @@ -219,9 +189,6 @@ extension SwiftLintFile { syntaxMapCache.invalidate(self) syntaxTokensByLinesCache.invalidate(self) syntaxKindsByLinesCache.invalidate(self) - #if canImport(SwiftSyntax) - syntaxCache.invalidate(self) - #endif } internal static func clearCaches() { @@ -233,8 +200,5 @@ extension SwiftLintFile { syntaxMapCache.clear() syntaxTokensByLinesCache.clear() syntaxKindsByLinesCache.clear() - #if canImport(SwiftSyntax) - syntaxCache.clear() - #endif } } diff --git a/Source/SwiftLintFramework/Models/MasterRuleList.swift b/Source/SwiftLintFramework/Models/MasterRuleList.swift index 7bdc7d6095..8c8aca5747 100644 --- a/Source/SwiftLintFramework/Models/MasterRuleList.swift +++ b/Source/SwiftLintFramework/Models/MasterRuleList.swift @@ -121,7 +121,6 @@ public let masterRuleList = RuleList(rules: [ OverriddenSuperCallRule.self, OverrideInExtensionRule.self, PatternMatchingKeywordsRule.self, - PhohibitedNaNComparisonRule.self, PreferSelfTypeOverTypeOfSelfRule.self, PrefixedTopLevelConstantRule.self, PrivateActionRule.self, @@ -148,7 +147,6 @@ public let masterRuleList = RuleList(rules: [ RequiredDeinitRule.self, RequiredEnumCaseRule.self, ReturnArrowWhitespaceRule.self, - ReturnValueFromVoidFunctionRule.self, ShorthandOperatorRule.self, SingleTestClassRule.self, SortedFirstLastRule.self, @@ -168,7 +166,6 @@ public let masterRuleList = RuleList(rules: [ TrailingNewlineRule.self, TrailingSemicolonRule.self, TrailingWhitespaceRule.self, - TuplePatternRule.self, TypeBodyLengthRule.self, TypeContentsOrderRule.self, TypeNameRule.self, @@ -192,7 +189,6 @@ public let masterRuleList = RuleList(rules: [ VerticalWhitespaceClosingBracesRule.self, VerticalWhitespaceOpeningBracesRule.self, VerticalWhitespaceRule.self, - VoidFunctionInTernaryConditionRule.self, VoidReturnRule.self, WeakDelegateRule.self, XCTFailMessageRule.self, diff --git a/Source/SwiftLintFramework/Protocols/SyntaxRule.swift b/Source/SwiftLintFramework/Protocols/SyntaxRule.swift deleted file mode 100644 index a83dff5ed1..0000000000 --- a/Source/SwiftLintFramework/Protocols/SyntaxRule.swift +++ /dev/null @@ -1,44 +0,0 @@ -import Foundation -#if canImport(SwiftSyntax) -import SwiftSyntax -#endif - -/// A rule that leverages the SwiftSyntax library. -public protocol SyntaxRule: Rule {} - -#if canImport(SwiftSyntax) -/// A SwiftSyntax visitor that collects data to provide violations for a specific rule. -public protocol SyntaxRuleVisitor: SyntaxVisitor { - /// The rule that uses this visitor. - associatedtype Rule: SyntaxRule - - /// Returns the violations that should be calculated based on data that was accumulated during the `visit` methods. - func violations(for rule: Rule, in file: SwiftLintFile) -> [StyleViolation] -} - -public extension SyntaxRule { - /// Wraps computation of violations based on a visitor. - func validate(file: SwiftLintFile, - visitor: Visitor) -> [StyleViolation] where Visitor.Rule == Self { - let lock = NSLock() - var visitor = visitor - - // https://bugs.swift.org/browse/SR-11170 - let work = DispatchWorkItem { - lock.lock() - file.syntax.walk(&visitor) - lock.unlock() - } - let thread = Thread { - work.perform() - } - thread.stackSize = 8 << 20 // 8 MB. - thread.start() - work.wait() - - lock.lock() - defer { lock.unlock() } - return visitor.violations(for: self, in: file) - } -} -#endif diff --git a/Source/SwiftLintFramework/Rules/Idiomatic/ReturnValueFromVoidFunctionRule.swift b/Source/SwiftLintFramework/Rules/Idiomatic/ReturnValueFromVoidFunctionRule.swift deleted file mode 100644 index 518b124d77..0000000000 --- a/Source/SwiftLintFramework/Rules/Idiomatic/ReturnValueFromVoidFunctionRule.swift +++ /dev/null @@ -1,76 +0,0 @@ -import SourceKittenFramework -#if canImport(SwiftSyntax) -import SwiftSyntax -#endif - -public struct ReturnValueFromVoidFunctionRule: ConfigurationProviderRule, SyntaxRule, OptInRule, - AutomaticTestableRule { - public var configuration = SeverityConfiguration(.warning) - - public init() {} - - public static let description = RuleDescription( - identifier: "return_value_from_void_function", - name: "Return Value from Void Function", - description: "Returning values from Void functions should be avoided.", - kind: .idiomatic, - minSwiftVersion: .fiveDotOne, - nonTriggeringExamples: ReturnValueFromVoidFunctionRuleExamples.nonTriggeringExamples, - triggeringExamples: ReturnValueFromVoidFunctionRuleExamples.triggeringExamples - ) - - public func validate(file: SwiftLintFile) -> [StyleViolation] { - #if canImport(SwiftSyntax) - return validate(file: file, visitor: ReturnVisitor()) - #else - return [] - #endif - } -} - -#if canImport(SwiftSyntax) -private class ReturnVisitor: SyntaxRuleVisitor { - private var positions = [AbsolutePosition]() - - func visit(_ node: ReturnStmtSyntax) -> SyntaxVisitorContinueKind { - if node.expression != nil, - let functionNode = node.enclosingFunction(), - functionNode.returnsVoid { - positions.append(node.positionAfterSkippingLeadingTrivia) - } - return .visitChildren - } - - func violations(for rule: ReturnValueFromVoidFunctionRule, in file: SwiftLintFile) -> [StyleViolation] { - return positions.map { position in - StyleViolation(ruleDescription: type(of: rule).description, - severity: rule.configuration.severity, - location: Location(file: file, byteOffset: ByteCount(position.utf8Offset))) - } - } -} - -private extension Syntax { - func enclosingFunction() -> FunctionDeclSyntax? { - if let node = self as? FunctionDeclSyntax { - return node - } - - if self is ClosureExprSyntax || self is VariableDeclSyntax { - return nil - } - - return parent?.enclosingFunction() - } -} - -private extension FunctionDeclSyntax { - var returnsVoid: Bool { - if let type = signature.output?.returnType as? SimpleTypeIdentifierSyntax { - return type.name.text == "Void" - } - - return signature.output?.returnType == nil - } -} -#endif diff --git a/Source/SwiftLintFramework/Rules/Idiomatic/ReturnValueFromVoidFunctionRuleExamples.swift b/Source/SwiftLintFramework/Rules/Idiomatic/ReturnValueFromVoidFunctionRuleExamples.swift deleted file mode 100644 index d3adb651e5..0000000000 --- a/Source/SwiftLintFramework/Rules/Idiomatic/ReturnValueFromVoidFunctionRuleExamples.swift +++ /dev/null @@ -1,234 +0,0 @@ -// swiftlint:disable:next type_body_length -internal struct ReturnValueFromVoidFunctionRuleExamples { - static let nonTriggeringExamples = [ - Example(""" - func foo() { - return - } - """), - Example(""" - func foo() { - return /* a comment */ - } - """), - Example(""" - func foo() -> Int { - return 1 - } - """), - Example(""" - func foo() -> Void { - if condition { - return - } - bar() - } - """), - Example(""" - func foo() { - return; - bar() - } - """), - Example("func test() {}"), - Example(""" - init?() { - guard condition else { - return nil - } - } - """), - Example(""" - init?(arg: String?) { - guard arg != nil else { - return nil - } - } - """), - Example(""" - func test() { - guard condition else { - return - } - } - """), - Example(""" - func test() -> Result { - func other() {} - func otherVoid() -> Void {} - } - """), - Example(""" - func test() -> Int? { - return nil - } - """), - Example(""" - func test() { - if bar { - print("") - return - } - let foo = [1, 2, 3].filter { return true } - return - } - """), - Example(""" - func test() { - guard foo else { - bar() - return - } - } - """), - Example(""" - func spec() { - var foo: Int { - return 0 - } - """) - ] - - static let triggeringExamples = [ - Example(""" - func foo() { - ↓return bar() - } - """), - Example(""" - func foo() { - ↓return self.bar() - } - """), - Example(""" - func foo() -> Void { - ↓return bar() - } - """), - Example(""" - func foo() -> Void { - ↓return /* comment */ bar() - } - """), - Example(""" - func foo() { - ↓return - self.bar() - } - """), - Example(""" - func foo() { - variable += 1 - ↓return - variable += 1 - } - """), - Example(""" - func initThing() { - guard foo else { - ↓return print("") - } - } - """), - Example(""" - // Leading comment - func test() { - guard condition else { - ↓return assertionfailure("") - } - } - """), - Example(""" - func test() -> Result { - func other() { - guard false else { - ↓return assertionfailure("") - } - } - func otherVoid() -> Void {} - } - """), - Example(""" - func test() { - guard conditionIsTrue else { - sideEffects() - return // comment - } - guard otherCondition else { - ↓return assertionfailure("") - } - differentSideEffect() - } - """), - Example(""" - func test() { - guard otherCondition else { - ↓return assertionfailure(""); // comment - } - differentSideEffect() - } - """), - Example(""" - func test() { - if x { - ↓return foo() - } - bar() - } - """), - Example(""" - func test() { - switch x { - case .a: - ↓return foo() // return to skip baz() - case .b: - bar() - } - baz() - } - """), - Example(""" - func test() { - if check { - if otherCheck { - ↓return foo() - } - } - bar() - } - """), - Example(""" - func test() { - ↓return foo() - } - """), - Example(""" - func test() { - ↓return foo({ - return bar() - }) - } - """), - Example(""" - func test() { - guard x else { - ↓return foo() - } - bar() - } - """), - Example(""" - func test() { - let closure: () -> () = { - return assert() - } - if check { - if otherCheck { - return // comments are fine - } - } - ↓return foo() - } - """) - ] -} diff --git a/Source/SwiftLintFramework/Rules/Idiomatic/TuplePatternRule.swift b/Source/SwiftLintFramework/Rules/Idiomatic/TuplePatternRule.swift deleted file mode 100644 index bd6e7c4d9e..0000000000 --- a/Source/SwiftLintFramework/Rules/Idiomatic/TuplePatternRule.swift +++ /dev/null @@ -1,90 +0,0 @@ -import SourceKittenFramework -#if canImport(SwiftSyntax) -import SwiftSyntax -#endif - -public struct TuplePatternRule: ConfigurationProviderRule, SyntaxRule, OptInRule, - AutomaticTestableRule { - public var configuration = SeverityConfiguration(.warning) - - public init() {} - - public static let description = RuleDescription( - identifier: "tuple_pattern", - name: "Tuple Pattern", - description: "Assigning variables through a tuple pattern is only permitted if the left-hand side of the " + - "assignment is unlabeled.", - kind: .idiomatic, - minSwiftVersion: .fiveDotOne, - nonTriggeringExamples: [ - Example("let (a, b) = (y: 4, x: 5.0)"), - Example("let (a, b) = (4, 5.0)"), - Example("let (a, b) = (a: 4, b: 5.0)"), - Example("let (a, b) = tuple") - ], - triggeringExamples: [ - Example("let ↓(x: a, y: b) = (y: 4, x: 5.0)"), - Example("let ↓(x: Int, y: Double) = (y: 4, x: 5.0)"), - Example("let ↓(x: Int, y: Double) = (y: 4, x: 5.0)") - ] - ) - - public func validate(file: SwiftLintFile) -> [StyleViolation] { - #if canImport(SwiftSyntax) - return validate(file: file, visitor: PatternBindingVisitor()) - #else - return [] - #endif - } -} - -#if canImport(SwiftSyntax) -private class PatternBindingVisitor: SyntaxRuleVisitor { - private var positions = [AbsolutePosition]() - - func visit(_ node: PatternBindingSyntax) -> SyntaxVisitorContinueKind { - if let tuplePattern = node.pattern as? TuplePatternSyntax, - case let leftSideLabels = tuplePattern.labels, - !leftSideLabels.compactMap({ $0 }).isEmpty, - let rightSideLabels = node.initializer?.tupleElementList?.labels, - leftSideLabels != rightSideLabels { - positions.append(node.positionAfterSkippingLeadingTrivia) - } - return .visitChildren - } - - func violations(for rule: TuplePatternRule, in file: SwiftLintFile) -> [StyleViolation] { - return positions.map { position in - StyleViolation(ruleDescription: type(of: rule).description, - severity: rule.configuration.severity, - location: Location(file: file, byteOffset: ByteCount(position.utf8Offset))) - } - } -} - -private extension TuplePatternSyntax { - var labels: [String?] { - return elements.map { element in - element.labelName?.withoutTrivia().text - } - } -} - -private extension InitializerClauseSyntax { - var tupleElementList: TupleElementListSyntax? { - if let expr = value as? TupleExprSyntax { - return expr.elementList - } - - return nil - } -} - -private extension TupleElementListSyntax { - var labels: [String?] { - return map { element in - element.label?.withoutTrivia().text - } - } -} -#endif diff --git a/Source/SwiftLintFramework/Rules/Idiomatic/VoidFunctionInTernaryConditionRule.swift b/Source/SwiftLintFramework/Rules/Idiomatic/VoidFunctionInTernaryConditionRule.swift deleted file mode 100644 index 8c560e38b4..0000000000 --- a/Source/SwiftLintFramework/Rules/Idiomatic/VoidFunctionInTernaryConditionRule.swift +++ /dev/null @@ -1,110 +0,0 @@ -import SourceKittenFramework -#if canImport(SwiftSyntax) -import SwiftSyntax -#endif - -public struct VoidFunctionInTernaryConditionRule: ConfigurationProviderRule, SyntaxRule, OptInRule, - AutomaticTestableRule { - public var configuration = SeverityConfiguration(.warning) - - public init() {} - - public static let description = RuleDescription( - identifier: "void_function_in_ternary", - name: "Void Function in Ternary", - description: "Using ternary to call Void functions should be avoided.", - kind: .idiomatic, - minSwiftVersion: .fiveDotOne, - nonTriggeringExamples: [ - Example("let result = success ? foo() : bar()"), - Example(""" - if success { - askQuestion() - } else { - exit() - } - """), - Example(""" - var price: Double { - return hasDiscount ? calculatePriceWithDiscount() : calculateRegularPrice() - } - """), - Example("foo(x == 2 ? a() : b())"), - Example(""" - chevronView.image = collapsed ? .icon(.mediumChevronDown) : .icon(.mediumChevronUp) - """), - Example(""" - array.map { elem in - elem.isEmpty() ? .emptyValue() : .number(elem) - } - """) - ], - triggeringExamples: [ - Example("success ↓? askQuestion() : exit()"), - Example(""" - perform { elem in - elem.isEmpty() ↓? .emptyValue() : .number(elem) - return 1 - } - """), - Example(""" - DispatchQueue.main.async { - self.sectionViewModels[section].collapsed.toggle() - self.sectionViewModels[section].collapsed - ↓? self.tableView.deleteRows(at: [IndexPath(row: 0, section: section)], with: .automatic) - : self.tableView.insertRows(at: [IndexPath(row: 0, section: section)], with: .automatic) - self.tableView.scrollToRow(at: IndexPath(row: NSNotFound, section: section), at: .top, animated: true) - } - """) - ] - ) - - public func validate(file: SwiftLintFile) -> [StyleViolation] { - #if canImport(SwiftSyntax) - return validate(file: file, visitor: TernaryVisitor()) - #else - return [] - #endif - } -} - -#if canImport(SwiftSyntax) -private class TernaryVisitor: SyntaxRuleVisitor { - private var positions = [AbsolutePosition]() - - func visit(_ node: TernaryExprSyntax) -> SyntaxVisitorContinueKind { - if node.firstChoice is FunctionCallExprSyntax, node.secondChoice is FunctionCallExprSyntax, - let parent = node.parent as? ExprListSyntax, !parent.containsAssignment, - parent.parent is SequenceExprSyntax, - let blockItem = parent.parent?.parent as? CodeBlockItemSyntax, !blockItem.isClosureImplictReturn { - positions.append(node.questionMark.positionAfterSkippingLeadingTrivia) - } - - return .visitChildren - } - - func violations(for rule: VoidFunctionInTernaryConditionRule, in file: SwiftLintFile) -> [StyleViolation] { - return positions.map { position in - StyleViolation(ruleDescription: type(of: rule).description, - severity: rule.configuration.severity, - location: Location(file: file, byteOffset: ByteCount(position.utf8Offset))) - } - } -} - -private extension ExprListSyntax { - var containsAssignment: Bool { - return children.contains(where: { $0 is AssignmentExprSyntax }) - } -} - -private extension CodeBlockItemSyntax { - var isClosureImplictReturn: Bool { - guard let parent = parent as? CodeBlockItemListSyntax else { - return false - } - - return Array(parent.children).count == 1 && parent.parent is ClosureExprSyntax - } -} -#endif diff --git a/Source/SwiftLintFramework/Rules/Lint/PhohibitedNaNComparisonRule.swift b/Source/SwiftLintFramework/Rules/Lint/PhohibitedNaNComparisonRule.swift deleted file mode 100644 index c267ea9829..0000000000 --- a/Source/SwiftLintFramework/Rules/Lint/PhohibitedNaNComparisonRule.swift +++ /dev/null @@ -1,99 +0,0 @@ -import Foundation -import SourceKittenFramework -#if canImport(SwiftSyntax) -import SwiftSyntax -#endif - -public struct PhohibitedNaNComparisonRule: ConfigurationProviderRule, SyntaxRule, OptInRule, AutomaticTestableRule { - public var configuration = SeverityConfiguration(.warning) - - public init() {} - - public static let description = RuleDescription( - identifier: "prohibited_nan_comparison", - name: "Prohibited NaN Comparison", - description: "Use `isNaN` instead of comparing values to the `.nan` constant.", - kind: .lint, - minSwiftVersion: .fiveDotOne, - nonTriggeringExamples: [ - Example("if number.isNaN {}"), - Example("if foo.nan == 3 {}") // allows using in non-types - ], - triggeringExamples: [ - Example("if number == .nan {}"), - Example("if number + 1 == .nan {}"), - Example("if number == Float.nan {}"), - Example("if .nan == number {}"), - Example("if Double.nan == number {}") - ] - ) - - public func validate(file: SwiftLintFile) -> [StyleViolation] { - #if canImport(SwiftSyntax) - return validate(file: file, visitor: BinaryOperatorVisitor()) - #else - return [] - #endif - } -} - -#if canImport(SwiftSyntax) -private class BinaryOperatorVisitor: SyntaxRuleVisitor { - private var positions = [AbsolutePosition]() - private let operators: Set = ["==", "!="] - - func visit(_ node: BinaryOperatorExprSyntax) -> SyntaxVisitorContinueKind { - if operators.contains(node.operatorToken.withoutTrivia().text), let children = node.parent?.children { - let array = Array(children) - let before = array[array.index(before: node.indexInParent)] - let after = array[array.index(after: node.indexInParent)] - - if before.isNaN || after.isNaN { - positions.append(node.operatorToken.positionAfterSkippingLeadingTrivia) - } - } - - return .visitChildren - } - - func violations(for rule: PhohibitedNaNComparisonRule, in file: SwiftLintFile) -> [StyleViolation] { - return positions.map { position in - StyleViolation(ruleDescription: type(of: rule).description, - severity: rule.configuration.severity, - location: Location(file: file, byteOffset: ByteCount(position.utf8Offset))) - } - } -} - -private extension Syntax { - var isNaN: Bool { - guard let memberExpr = self as? MemberAccessExprSyntax else { - return false - } - - let isNaNProperty = memberExpr.name.withoutTrivia().text == "nan" - return isNaNProperty && (memberExpr.base == nil || memberExpr.base?.referringToType == true) - } -} - -private extension ExprSyntax { - var referringToType: Bool { - guard let expr = self as? IdentifierExprSyntax else { - return false - } - - return expr.identifier.classifications.map { $0.kind } == [.identifier] && - expr.identifier.withoutTrivia().text.isTypeLike - } -} - -private extension String { - var isTypeLike: Bool { - guard let firstLetter = unicodeScalars.first else { - return false - } - - return CharacterSet.uppercaseLetters.contains(firstLetter) - } -} -#endif diff --git a/SwiftLint.xcodeproj/project.pbxproj b/SwiftLint.xcodeproj/project.pbxproj index 95a19fcc4b..6866c2d0ec 100644 --- a/SwiftLint.xcodeproj/project.pbxproj +++ b/SwiftLint.xcodeproj/project.pbxproj @@ -264,7 +264,6 @@ D40AD08A1E032F9700F48C30 /* UnusedClosureParameterRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40AD0891E032F9700F48C30 /* UnusedClosureParameterRule.swift */; }; D40E041C1F46E3B30043BC4E /* SuperfluousDisableCommandRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40E041B1F46E3B30043BC4E /* SuperfluousDisableCommandRule.swift */; }; D40F83881DE9179200524C62 /* TrailingCommaConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40F83871DE9179200524C62 /* TrailingCommaConfiguration.swift */; }; - D40F8B6723E6D60E00A5218E /* PhohibitedNaNComparisonRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40F8B6623E6D60E00A5218E /* PhohibitedNaNComparisonRule.swift */; }; D40FE89D1F867BFF006433E2 /* OverrideInExtensionRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40FE89C1F867BFF006433E2 /* OverrideInExtensionRule.swift */; }; D4130D971E16183F00242361 /* IdentifierNameRuleExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4130D961E16183F00242361 /* IdentifierNameRuleExamples.swift */; }; D4130D991E16CC1300242361 /* TypeNameRuleExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4130D981E16CC1300242361 /* TypeNameRuleExamples.swift */; }; @@ -298,8 +297,6 @@ D4470D591EB6B4D1008A1B2E /* EmptyEnumArgumentsRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4470D581EB6B4D1008A1B2E /* EmptyEnumArgumentsRule.swift */; }; D4470D5B1EB76F44008A1B2E /* UnusedOptionalBindingRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4470D5A1EB76F44008A1B2E /* UnusedOptionalBindingRuleTests.swift */; }; D4470D5D1EB8004B008A1B2E /* VerticalParameterAlignmentOnCallRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4470D5C1EB8004B008A1B2E /* VerticalParameterAlignmentOnCallRule.swift */; }; - D4492B9323DD499A004EC27B /* _CSwiftSyntax.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D4492B9123DD499A004EC27B /* _CSwiftSyntax.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; - D4492B9523DD499A004EC27B /* SwiftSyntax.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D4492B9223DD499A004EC27B /* SwiftSyntax.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; D44AD2761C0AA5350048F7B0 /* LegacyConstructorRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D44AD2741C0AA3730048F7B0 /* LegacyConstructorRule.swift */; }; D450D1D121EC4A6900E60010 /* StrongIBOutletRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D450D1D021EC4A6900E60010 /* StrongIBOutletRule.swift */; }; D450D1DD21F199F700E60010 /* TrailingClosureConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D450D1DA21F1992E00E60010 /* TrailingClosureConfiguration.swift */; }; @@ -309,8 +306,6 @@ D462021F1E15F52D0027AAD1 /* NumberSeparatorRuleExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = D462021E1E15F52D0027AAD1 /* NumberSeparatorRuleExamples.swift */; }; D46252541DF63FB200BE2CA1 /* NumberSeparatorRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D46252531DF63FB200BE2CA1 /* NumberSeparatorRule.swift */; }; D466B620233D229F0068190B /* FlatMapOverMapReduceRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D466B61F233D229F0068190B /* FlatMapOverMapReduceRule.swift */; }; - D467275823DD971300DE73B6 /* VoidFunctionInTernaryConditionRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D467275723DD971300DE73B6 /* VoidFunctionInTernaryConditionRule.swift */; }; - D467275A23DE71D200DE73B6 /* TuplePatternRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D467275923DE71D200DE73B6 /* TuplePatternRule.swift */; }; D46A317F1F1CEDCD00AF914A /* UnneededParenthesesInClosureArgumentRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D46A317E1F1CEDCD00AF914A /* UnneededParenthesesInClosureArgumentRule.swift */; }; D46C7C3E23BF2F6A007C517F /* PreferSelfTypeOverTypeOfSelfRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D46C7C3D23BF2F6A007C517F /* PreferSelfTypeOverTypeOfSelfRule.swift */; }; D46E041D1DE3712C00728374 /* TrailingCommaRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D46E041C1DE3712C00728374 /* TrailingCommaRule.swift */; }; @@ -373,14 +368,11 @@ D4DE9133207B4750000FFAA8 /* UnavailableFunctionRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4DE9131207B4731000FFAA8 /* UnavailableFunctionRule.swift */; }; D4E2BA851F6CD77B00E8E184 /* ArrayInitRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E2BA841F6CD77B00E8E184 /* ArrayInitRule.swift */; }; D4E4FB5223E7A1A300746FCD /* LineEndingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E4FB5123E7A1A300746FCD /* LineEndingTests.swift */; }; - D4E4FB5523E7A6CF00746FCD /* ReturnValueFromVoidFunctionRuleExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E4FB5323E7A6CF00746FCD /* ReturnValueFromVoidFunctionRuleExamples.swift */; }; - D4E4FB5623E7A6CF00746FCD /* ReturnValueFromVoidFunctionRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E4FB5423E7A6CF00746FCD /* ReturnValueFromVoidFunctionRule.swift */; }; D4E92D1F2137B4C9002EDD48 /* IdenticalOperandsRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E92D1E2137B4C9002EDD48 /* IdenticalOperandsRule.swift */; }; D4EA77C81F817FD200C315FB /* UnneededBreakInSwitchRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EA77C71F817FD200C315FB /* UnneededBreakInSwitchRule.swift */; }; D4EA77CA1F81FACC00C315FB /* LiteralExpressionEndIdentationRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EA77C91F81FACC00C315FB /* LiteralExpressionEndIdentationRule.swift */; }; D4EAB3A420E9948E0051C09A /* AutomaticRuleTests.generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EAB3A320E9948D0051C09A /* AutomaticRuleTests.generated.swift */; }; D4EABD0C22CE6F5B00635667 /* VerticalParameterAlignmentRuleExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EABD0B22CE6F5B00635667 /* VerticalParameterAlignmentRuleExamples.swift */; }; - D4EF8EA223E695EA0038C26E /* SyntaxRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EF8EA123E695EA0038C26E /* SyntaxRule.swift */; }; D4F10614229A2F5E00FDE319 /* NoFallthroughOnlyRuleExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4F10613229A2F5E00FDE319 /* NoFallthroughOnlyRuleExamples.swift */; }; D4F10616229A331200FDE319 /* LegacyMultipleRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4F10615229A331200FDE319 /* LegacyMultipleRule.swift */; }; D4F5851520E99A8A0085C6D8 /* TrailingWhitespaceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4F5851320E99A720085C6D8 /* TrailingWhitespaceTests.swift */; }; @@ -799,7 +791,6 @@ D40AD0891E032F9700F48C30 /* UnusedClosureParameterRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnusedClosureParameterRule.swift; sourceTree = ""; }; D40E041B1F46E3B30043BC4E /* SuperfluousDisableCommandRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SuperfluousDisableCommandRule.swift; sourceTree = ""; }; D40F83871DE9179200524C62 /* TrailingCommaConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrailingCommaConfiguration.swift; sourceTree = ""; }; - D40F8B6623E6D60E00A5218E /* PhohibitedNaNComparisonRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhohibitedNaNComparisonRule.swift; sourceTree = ""; }; D40FE89C1F867BFF006433E2 /* OverrideInExtensionRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideInExtensionRule.swift; sourceTree = ""; }; D4130D961E16183F00242361 /* IdentifierNameRuleExamples.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdentifierNameRuleExamples.swift; sourceTree = ""; }; D4130D981E16CC1300242361 /* TypeNameRuleExamples.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeNameRuleExamples.swift; sourceTree = ""; }; @@ -833,8 +824,6 @@ D4470D581EB6B4D1008A1B2E /* EmptyEnumArgumentsRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmptyEnumArgumentsRule.swift; sourceTree = ""; }; D4470D5A1EB76F44008A1B2E /* UnusedOptionalBindingRuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnusedOptionalBindingRuleTests.swift; sourceTree = ""; }; D4470D5C1EB8004B008A1B2E /* VerticalParameterAlignmentOnCallRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerticalParameterAlignmentOnCallRule.swift; sourceTree = ""; }; - D4492B9123DD499A004EC27B /* _CSwiftSyntax.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = _CSwiftSyntax.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - D4492B9223DD499A004EC27B /* SwiftSyntax.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SwiftSyntax.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D44AD2741C0AA3730048F7B0 /* LegacyConstructorRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LegacyConstructorRule.swift; sourceTree = ""; }; D450D1D021EC4A6900E60010 /* StrongIBOutletRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StrongIBOutletRule.swift; sourceTree = ""; }; D450D1DA21F1992E00E60010 /* TrailingClosureConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailingClosureConfiguration.swift; sourceTree = ""; }; @@ -844,8 +833,6 @@ D462021E1E15F52D0027AAD1 /* NumberSeparatorRuleExamples.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberSeparatorRuleExamples.swift; sourceTree = ""; }; D46252531DF63FB200BE2CA1 /* NumberSeparatorRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberSeparatorRule.swift; sourceTree = ""; }; D466B61F233D229F0068190B /* FlatMapOverMapReduceRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlatMapOverMapReduceRule.swift; sourceTree = ""; }; - D467275723DD971300DE73B6 /* VoidFunctionInTernaryConditionRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoidFunctionInTernaryConditionRule.swift; sourceTree = ""; }; - D467275923DE71D200DE73B6 /* TuplePatternRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TuplePatternRule.swift; sourceTree = ""; }; D46A317E1F1CEDCD00AF914A /* UnneededParenthesesInClosureArgumentRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnneededParenthesesInClosureArgumentRule.swift; sourceTree = ""; }; D46C7C3D23BF2F6A007C517F /* PreferSelfTypeOverTypeOfSelfRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferSelfTypeOverTypeOfSelfRule.swift; sourceTree = ""; }; D46E041C1DE3712C00728374 /* TrailingCommaRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrailingCommaRule.swift; sourceTree = ""; }; @@ -909,14 +896,11 @@ D4DE9131207B4731000FFAA8 /* UnavailableFunctionRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnavailableFunctionRule.swift; sourceTree = ""; }; D4E2BA841F6CD77B00E8E184 /* ArrayInitRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrayInitRule.swift; sourceTree = ""; }; D4E4FB5123E7A1A300746FCD /* LineEndingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineEndingTests.swift; sourceTree = ""; }; - D4E4FB5323E7A6CF00746FCD /* ReturnValueFromVoidFunctionRuleExamples.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReturnValueFromVoidFunctionRuleExamples.swift; sourceTree = ""; }; - D4E4FB5423E7A6CF00746FCD /* ReturnValueFromVoidFunctionRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReturnValueFromVoidFunctionRule.swift; sourceTree = ""; }; D4E92D1E2137B4C9002EDD48 /* IdenticalOperandsRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdenticalOperandsRule.swift; sourceTree = ""; }; D4EA77C71F817FD200C315FB /* UnneededBreakInSwitchRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnneededBreakInSwitchRule.swift; sourceTree = ""; }; D4EA77C91F81FACC00C315FB /* LiteralExpressionEndIdentationRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiteralExpressionEndIdentationRule.swift; sourceTree = ""; }; D4EAB3A320E9948D0051C09A /* AutomaticRuleTests.generated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutomaticRuleTests.generated.swift; sourceTree = ""; }; D4EABD0B22CE6F5B00635667 /* VerticalParameterAlignmentRuleExamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerticalParameterAlignmentRuleExamples.swift; sourceTree = ""; }; - D4EF8EA123E695EA0038C26E /* SyntaxRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyntaxRule.swift; sourceTree = ""; }; D4F10613229A2F5E00FDE319 /* NoFallthroughOnlyRuleExamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoFallthroughOnlyRuleExamples.swift; sourceTree = ""; }; D4F10615229A331200FDE319 /* LegacyMultipleRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyMultipleRule.swift; sourceTree = ""; }; D4F5851320E99A720085C6D8 /* TrailingWhitespaceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailingWhitespaceTests.swift; sourceTree = ""; }; @@ -1018,10 +1002,8 @@ buildActionMask = 2147483647; files = ( E876BFBE1B07828500114ED5 /* SourceKittenFramework.framework in Frameworks */, - D4492B9323DD499A004EC27B /* _CSwiftSyntax.framework in Frameworks */, E8C0DFCD1AD349DB007EE3D4 /* SWXMLHash.framework in Frameworks */, 3BBF2F9D1C640A0F006CD775 /* SwiftyTextTable.framework in Frameworks */, - D4492B9523DD499A004EC27B /* SwiftSyntax.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1212,7 +1194,6 @@ 094385021D5D4F78009168CF /* PrivateOutletRule.swift */, B2902A0B1D66815600BFCCF7 /* PrivateUnitTestRule.swift */, D44037962132730000FDA77B /* ProhibitedInterfaceBuilderRule.swift */, - D40F8B6623E6D60E00A5218E /* PhohibitedNaNComparisonRule.swift */, 009E09271DFEE4C200B588A7 /* ProhibitedSuperRule.swift */, 623E36EF1F3DB1B1002E5B71 /* QuickDiscouragedCallRule.swift */, 623E36F11F3DB988002E5B71 /* QuickDiscouragedCallRuleExamples.swift */, @@ -1380,21 +1361,17 @@ D41E7E0A1DF9DABB0065259A /* RedundantStringEnumValueRule.swift */, 6208ED4E20C297AC004E78D1 /* RedundantTypeAnnotationRule.swift */, D4B022B11E10B613007E5297 /* RedundantVoidReturnRule.swift */, - D4E4FB5423E7A6CF00746FCD /* ReturnValueFromVoidFunctionRule.swift */, - D4E4FB5323E7A6CF00746FCD /* ReturnValueFromVoidFunctionRuleExamples.swift */, D4D383842145F550000235BD /* StaticOperatorRule.swift */, D42B45D81F0AF5E30086B683 /* StrictFilePrivateRule.swift */, D44254251DB9C12300492EA4 /* SyntacticSugarRule.swift */, 7551DF6C21382C9A00AA1F4D /* ToggleBoolRule.swift */, E87E4A041BFB927C00FCFE46 /* TrailingSemicolonRule.swift */, - D467275923DE71D200DE73B6 /* TuplePatternRule.swift */, E88DEA911B099B1F00A66CB0 /* TypeNameRule.swift */, D4130D981E16CC1300242361 /* TypeNameRuleExamples.swift */, D4DE9131207B4731000FFAA8 /* UnavailableFunctionRule.swift */, D4EA77C71F817FD200C315FB /* UnneededBreakInSwitchRule.swift */, 181D9E162038343D001F6887 /* UntypedErrorInCatchRule.swift */, D43B04631E0620AB004016AF /* UnusedEnumeratedRule.swift */, - D467275723DD971300DE73B6 /* VoidFunctionInTernaryConditionRule.swift */, 41715DE023BEA08E00544BDF /* FileNameNoSpaceRule.swift */, 626D02961F31CBCC0054788D /* XCTFailMessageRule.swift */, 622AD7FF216ACE6200A002C6 /* XCTSpecificMatcherRule.swift */, @@ -1419,7 +1396,6 @@ D0D1211A19E87861005E4BAA /* swiftlint */, D0D1216E19E87B05005E4BAA /* SwiftLintFramework */, D0D1217B19E87B05005E4BAA /* SwiftLintFrameworkTests */, - D4492B9023DD499A004EC27B /* Frameworks */, ); indentWidth = 4; sourceTree = ""; @@ -1645,15 +1621,6 @@ path = "Supporting Files"; sourceTree = ""; }; - D4492B9023DD499A004EC27B /* Frameworks */ = { - isa = PBXGroup; - children = ( - D4492B9123DD499A004EC27B /* _CSwiftSyntax.framework */, - D4492B9223DD499A004EC27B /* SwiftSyntax.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; E802ECFE1C56A54600A35AE1 /* Helpers */ = { isa = PBXGroup; children = ( @@ -1713,7 +1680,6 @@ isa = PBXGroup; children = ( E88DEA8B1B0999A000A66CB0 /* ASTRule.swift */, - D4EF8EA123E695EA0038C26E /* SyntaxRule.swift */, E80746F51ECB722F00548D31 /* CacheDescriptionProvider.swift */, A73469401FB12149009B57C7 /* CallPairRule.swift */, E86396C11BADAAE5002C9E88 /* Reporter.swift */, @@ -2103,7 +2069,6 @@ 62A3E95D209E084000547A86 /* EmptyXCTestMethodRule.swift in Sources */, D4C4A34C1DEA4FF000E0E04C /* AttributesConfiguration.swift in Sources */, 29FC197A21382C07006D208C /* DuplicateImportsRuleExamples.swift in Sources */, - D4E4FB5623E7A6CF00746FCD /* ReturnValueFromVoidFunctionRule.swift in Sources */, 83D71E281B131ECE000395DE /* RuleDescription.swift in Sources */, D4470D571EB69225008A1B2E /* ImplicitReturnRule.swift in Sources */, 8FE3CCBC22DBF8D000B8EA87 /* UnusedDeclarationConfiguration.swift in Sources */, @@ -2119,7 +2084,6 @@ D4C4A3521DEFBBB700E0E04C /* FileHeaderConfiguration.swift in Sources */, 623675B01F960C5C009BE6F3 /* QuickDiscouragedPendingTestRule.swift in Sources */, 287F8B642230843000BDC504 /* NSLocalizedStringRequireBundleRule.swift in Sources */, - D4EF8EA223E695EA0038C26E /* SyntaxRule.swift in Sources */, D47079AD1DFE2FA700027086 /* EmptyParametersRule.swift in Sources */, E87E4A091BFB9CAE00FCFE46 /* SyntaxKind+SwiftLint.swift in Sources */, 3B0B14541C505D6300BE82F7 /* SeverityConfiguration.swift in Sources */, @@ -2185,7 +2149,6 @@ E8EA41171C2D1DBE004F9930 /* CheckstyleReporter.swift in Sources */, 006ECFC41C44E99E00EF6364 /* LegacyConstantRule.swift in Sources */, 82FE254120F604CB00295958 /* VerticalWhitespaceClosingBracesRule.swift in Sources */, - D40F8B6723E6D60E00A5218E /* PhohibitedNaNComparisonRule.swift in Sources */, 429644B61FB0A9B400D75128 /* SortedFirstLastRule.swift in Sources */, C3EF547821B5A4000009262F /* LegacyHashingRule.swift in Sources */, 31F1B6CC1F60BF4500A57456 /* SwitchCaseAlignmentRule.swift in Sources */, @@ -2338,7 +2301,6 @@ E83530C61ED6328A00FBAF79 /* FileNameRule.swift in Sources */, 3BB47D831C514E8100AE6A10 /* RegexConfiguration.swift in Sources */, D401D9261ED85EF0005DA5D4 /* RuleKind.swift in Sources */, - D467275A23DE71D200DE73B6 /* TuplePatternRule.swift in Sources */, 622AD800216ACE6300A002C6 /* XCTSpecificMatcherRuleExamples.swift in Sources */, 82EB7886215BAE790042E0FD /* TypeContentsOrderRuleExamples.swift in Sources */, 7551DF6D21382C9A00AA1F4D /* ToggleBoolRule.swift in Sources */, @@ -2354,7 +2316,6 @@ 6C15818D237026AC00F582A2 /* GitHubActionsLoggingReporter.swift in Sources */, 62FE5D32200CABDD00F68793 /* DiscouragedOptionalCollectionExamples.swift in Sources */, D41C09BD23C1B99D00F105C4 /* OrphanedDocCommentRule.swift in Sources */, - D467275823DD971300DE73B6 /* VoidFunctionInTernaryConditionRule.swift in Sources */, D49896F12026B36C00814A83 /* RedundantSetAccessControlRule.swift in Sources */, E4A6CF752363CBFB00DD5B18 /* RandomAccessCollection+Swiftlint.swift in Sources */, 29FFC37A1F15764D007E4825 /* FileLengthRuleConfiguration.swift in Sources */, @@ -2368,7 +2329,6 @@ C946FECB1EAE67EE007DD778 /* LetVarWhitespaceRule.swift in Sources */, E881985D1BEA97EB00333A11 /* TrailingWhitespaceRule.swift in Sources */, E832F10B1B17E2F5003F265F /* FileManager+SwiftLint.swift in Sources */, - D4E4FB5523E7A6CF00746FCD /* ReturnValueFromVoidFunctionRuleExamples.swift in Sources */, E816194C1BFBF35D00946723 /* SwiftDeclarationKind+SwiftLint.swift in Sources */, D4DABFD71E2C23B1009617B6 /* NotificationCenterDetachmentRule.swift in Sources */, 3BA79C9B1C4767910057E705 /* NSRange+SwiftLint.swift in Sources */, @@ -2528,7 +2488,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = D0D1212619E878CC005E4BAA /* Debug.xcconfig */; buildSettings = { - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.10; SWIFT_VERSION = 4.0; }; name = Debug; @@ -2537,7 +2497,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = D0D1212819E878CC005E4BAA /* Release.xcconfig */; buildSettings = { - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.10; SWIFT_VERSION = 4.0; }; name = Release; @@ -2614,7 +2574,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = D0D1212719E878CC005E4BAA /* Profile.xcconfig */; buildSettings = { - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.10; SWIFT_VERSION = 4.0; }; name = Profile; @@ -2657,7 +2617,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = D0D1212919E878CC005E4BAA /* Test.xcconfig */; buildSettings = { - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.10; SWIFT_VERSION = 4.0; }; name = Test; diff --git a/SwiftLint.xcworkspace/contents.xcworkspacedata b/SwiftLint.xcworkspace/contents.xcworkspacedata index 673bf221f9..9cc392b015 100644 --- a/SwiftLint.xcworkspace/contents.xcworkspacedata +++ b/SwiftLint.xcworkspace/contents.xcworkspacedata @@ -16,9 +16,6 @@ - - diff --git a/SwiftSyntax b/SwiftSyntax deleted file mode 160000 index 3e3eb191fc..0000000000 --- a/SwiftSyntax +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3e3eb191fcdbecc6031522660c4ed6ce25282c25 diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 41f74354f4..02c6404330 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1064,12 +1064,6 @@ extension PatternMatchingKeywordsRuleTests { ] } -extension PhohibitedNaNComparisonRuleTests { - static var allTests: [(String, (PhohibitedNaNComparisonRuleTests) -> () throws -> Void)] = [ - ("testWithDefaultConfiguration", testWithDefaultConfiguration) - ] -} - extension PreferSelfTypeOverTypeOfSelfRuleTests { static var allTests: [(String, (PreferSelfTypeOverTypeOfSelfRuleTests) -> () throws -> Void)] = [ ("testWithDefaultConfiguration", testWithDefaultConfiguration) @@ -1268,12 +1262,6 @@ extension ReturnArrowWhitespaceRuleTests { ] } -extension ReturnValueFromVoidFunctionRuleTests { - static var allTests: [(String, (ReturnValueFromVoidFunctionRuleTests) -> () throws -> Void)] = [ - ("testWithDefaultConfiguration", testWithDefaultConfiguration) - ] -} - extension RuleConfigurationTests { static var allTests: [(String, (RuleConfigurationTests) -> () throws -> Void)] = [ ("testNameConfigurationSetsCorrectly", testNameConfigurationSetsCorrectly), @@ -1457,12 +1445,6 @@ extension TrailingWhitespaceTests { ] } -extension TuplePatternRuleTests { - static var allTests: [(String, (TuplePatternRuleTests) -> () throws -> Void)] = [ - ("testWithDefaultConfiguration", testWithDefaultConfiguration) - ] -} - extension TypeBodyLengthRuleTests { static var allTests: [(String, (TypeBodyLengthRuleTests) -> () throws -> Void)] = [ ("testWithDefaultConfiguration", testWithDefaultConfiguration) @@ -1611,12 +1593,6 @@ extension VerticalWhitespaceRuleTests { ] } -extension VoidFunctionInTernaryConditionRuleTests { - static var allTests: [(String, (VoidFunctionInTernaryConditionRuleTests) -> () throws -> Void)] = [ - ("testWithDefaultConfiguration", testWithDefaultConfiguration) - ] -} - extension VoidReturnRuleTests { static var allTests: [(String, (VoidReturnRuleTests) -> () throws -> Void)] = [ ("testWithDefaultConfiguration", testWithDefaultConfiguration) @@ -1814,7 +1790,6 @@ XCTMain([ testCase(OverriddenSuperCallRuleTests.allTests), testCase(OverrideInExtensionRuleTests.allTests), testCase(PatternMatchingKeywordsRuleTests.allTests), - testCase(PhohibitedNaNComparisonRuleTests.allTests), testCase(PreferSelfTypeOverTypeOfSelfRuleTests.allTests), testCase(PrefixedTopLevelConstantRuleTests.allTests), testCase(PrivateActionRuleTests.allTests), @@ -1843,7 +1818,6 @@ XCTMain([ testCase(RequiredDeinitRuleTests.allTests), testCase(RequiredEnumCaseRuleTestCase.allTests), testCase(ReturnArrowWhitespaceRuleTests.allTests), - testCase(ReturnValueFromVoidFunctionRuleTests.allTests), testCase(RuleConfigurationTests.allTests), testCase(RuleTests.allTests), testCase(RulesTests.allTests), @@ -1866,7 +1840,6 @@ XCTMain([ testCase(TrailingCommaRuleTests.allTests), testCase(TrailingSemicolonRuleTests.allTests), testCase(TrailingWhitespaceTests.allTests), - testCase(TuplePatternRuleTests.allTests), testCase(TypeBodyLengthRuleTests.allTests), testCase(TypeContentsOrderRuleTests.allTests), testCase(TypeNameRuleTests.allTests), @@ -1890,7 +1863,6 @@ XCTMain([ testCase(VerticalWhitespaceClosingBracesRuleTests.allTests), testCase(VerticalWhitespaceOpeningBracesRuleTests.allTests), testCase(VerticalWhitespaceRuleTests.allTests), - testCase(VoidFunctionInTernaryConditionRuleTests.allTests), testCase(VoidReturnRuleTests.allTests), testCase(WeakDelegateRuleTests.allTests), testCase(XCTFailMessageRuleTests.allTests), diff --git a/Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift b/Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift index 6ca2b5adec..b24e9b2251 100644 --- a/Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift +++ b/Tests/SwiftLintFrameworkTests/AutomaticRuleTests.generated.swift @@ -510,12 +510,6 @@ class PatternMatchingKeywordsRuleTests: XCTestCase { } } -class PhohibitedNaNComparisonRuleTests: XCTestCase { - func testWithDefaultConfiguration() { - verifyRule(PhohibitedNaNComparisonRule.description) - } -} - class PreferSelfTypeOverTypeOfSelfRuleTests: XCTestCase { func testWithDefaultConfiguration() { verifyRule(PreferSelfTypeOverTypeOfSelfRule.description) @@ -648,12 +642,6 @@ class ReturnArrowWhitespaceRuleTests: XCTestCase { } } -class ReturnValueFromVoidFunctionRuleTests: XCTestCase { - func testWithDefaultConfiguration() { - verifyRule(ReturnValueFromVoidFunctionRule.description) - } -} - class ShorthandOperatorRuleTests: XCTestCase { func testWithDefaultConfiguration() { verifyRule(ShorthandOperatorRule.description) @@ -720,12 +708,6 @@ class TrailingSemicolonRuleTests: XCTestCase { } } -class TuplePatternRuleTests: XCTestCase { - func testWithDefaultConfiguration() { - verifyRule(TuplePatternRule.description) - } -} - class TypeBodyLengthRuleTests: XCTestCase { func testWithDefaultConfiguration() { verifyRule(TypeBodyLengthRule.description) @@ -840,12 +822,6 @@ class VerticalWhitespaceOpeningBracesRuleTests: XCTestCase { } } -class VoidFunctionInTernaryConditionRuleTests: XCTestCase { - func testWithDefaultConfiguration() { - verifyRule(VoidFunctionInTernaryConditionRule.description) - } -} - class VoidReturnRuleTests: XCTestCase { func testWithDefaultConfiguration() { verifyRule(VoidReturnRule.description) diff --git a/Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift b/Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift index 71d63cf635..d769ca79aa 100644 --- a/Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift +++ b/Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift @@ -88,8 +88,7 @@ extension ConfigurationTests { let mergedConfiguration = projectMockConfig0CustomRules.merge(with: projectMockConfig2CustomRules) guard let mergedCustomRules = mergedConfiguration.rules.first(where: { $0 is CustomRules }) as? CustomRules else { - XCTFail("Custom rule are expected to be present") - return + return XCTFail("Custom rule are expected to be present") } XCTAssertTrue( mergedCustomRules.configuration.customRuleConfigurations.contains(where: { $0.identifier == "no_abc" }) @@ -103,8 +102,7 @@ extension ConfigurationTests { let mergedConfiguration = projectMockConfig0CustomRules.merge(with: projectMockConfig2CustomRulesDisabled) guard let mergedCustomRules = mergedConfiguration.rules.first(where: { $0 is CustomRules }) as? CustomRules else { - XCTFail("Custom rule are expected to be present") - return + return XCTFail("Custom rule are expected to be present") } XCTAssertFalse( mergedCustomRules.configuration.customRuleConfigurations.contains(where: { $0.identifier == "no_abc" }) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 68ca625d54..b3e719eb8a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -23,11 +23,15 @@ jobs: strategy: maxParallel: 10 matrix: + xcode102: + DEVELOPER_DIR: /Applications/Xcode_10.2.app + xcode103: + DEVELOPER_DIR: /Applications/Xcode_10.3.app xcode111: DEVELOPER_DIR: /Applications/Xcode_11.1.app steps: - - script: Script/bootstrap - displayName: Bootstrap + - script: git submodule update --init --recursive + displayName: Update git submodules - script: | sw_vers xcodebuild -version diff --git a/script/bootstrap b/script/bootstrap index 174ce11204..ebd4c8d752 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -21,8 +21,6 @@ main () echo "*** Updating submodules..." update_submodules fi - - cd "SwiftSyntax" && swift package generate-xcodeproj } bootstrap_submodule ()