From 7d4e0aed94d4c083f3079019f5ed287ed3bcae4d Mon Sep 17 00:00:00 2001 From: Daniel Duan Date: Mon, 28 Nov 2016 14:40:06 -0800 Subject: [PATCH] Fix ValidIBInspectable rule implementation 1. `NSNumber` is not IB-inspectable at all. 2. Explicitly typed `Optional`s and `ImplicitlyUnwrappedOptional`s aren't supported by `@IBInspectable`, reference type or not. --- CHANGELOG.md | 3 +++ .../Rules/ValidIBInspectableRule.swift | 14 +++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f409abf..3fdd85f1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,9 @@ ##### Bug Fixes +* Rule out a few invalid `@IBInspectable` cases in `valid_ibinspectable`. + [Daniel Duan](https://github.com/dduan) + * Fix a few edge cases where malformed `MARK:` comments wouldn't trigger a violation. [JP Simard](https://github.com/jpsim) diff --git a/Source/SwiftLintFramework/Rules/ValidIBInspectableRule.swift b/Source/SwiftLintFramework/Rules/ValidIBInspectableRule.swift index 5975ac8b0..64af6c0c6 100644 --- a/Source/SwiftLintFramework/Rules/ValidIBInspectableRule.swift +++ b/Source/SwiftLintFramework/Rules/ValidIBInspectableRule.swift @@ -24,8 +24,6 @@ public struct ValidIBInspectableRule: ASTRule, ConfigurationProviderRule { "class Foo {\n @IBInspectable private var x: Int\n}\n", "class Foo {\n @IBInspectable private var x: String?\n}\n", "class Foo {\n @IBInspectable private var x: String!\n}\n", - "class Foo {\n @IBInspectable private var x: ImplicitlyUnwrappedOptional\n}\n", - "class Foo {\n @IBInspectable private var x: Optional\n}\n", "class Foo {\n @IBInspectable private var count: Int = 0\n}\n", "class Foo {\n private var notInspectable = 0\n}\n", "class Foo {\n private let notInspectable: Int\n}\n" @@ -37,7 +35,9 @@ public struct ValidIBInspectableRule: ASTRule, ConfigurationProviderRule { "class Foo {\n @IBInspectable private var count: Int?\n}\n", "class Foo {\n @IBInspectable private var count: Int!\n}\n", "class Foo {\n @IBInspectable private var x: ImplicitlyUnwrappedOptional\n}\n", - "class Foo {\n @IBInspectable private var count: Optional\n}\n" + "class Foo {\n @IBInspectable private var count: Optional\n}\n", + "class Foo {\n @IBInspectable private var x: Optional\n}\n", + "class Foo {\n @IBInspectable private var x: ImplicitlyUnwrappedOptional\n}\n" ] ) @@ -85,8 +85,7 @@ public struct ValidIBInspectableRule: ASTRule, ConfigurationProviderRule { "UIColor", "NSColor", "UIImage", - "NSImage", - "NSNumber" + "NSImage" ] let types = [ @@ -104,10 +103,7 @@ public struct ValidIBInspectableRule: ASTRule, ConfigurationProviderRule { ] // It seems that only reference types can be used as ImplicitlyUnwrappedOptional or Optional - return referenceTypes.flatMap { - [$0, $0 + "!", $0 + "?", - "ImplicitlyUnwrappedOptional<\($0)>", "Optional<\($0)>"] + types - } + return referenceTypes.flatMap { [$0, $0 + "!", $0 + "?"] } + types } private func violation(dictionary: [String: SourceKitRepresentable],