Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IBInspectableInExtensionRule #3174

Merged
merged 2 commits into from
Aug 4, 2020
Merged

Add IBInspectableInExtensionRule #3174

merged 2 commits into from
Aug 4, 2020

Conversation

keith
Copy link
Collaborator

@keith keith commented Apr 7, 2020

This rule validates that there are no @IBInspectable variables in
extensions. The reason for this is that Interface Builder doesn't take
into account what code is actually included in your target to determine
if an inspectable should be valid. So in this case:

// Module A
extension UIView {
  @IBInspectable public var foo: String? {
    // do something
  }
}
// Module B
// Uses `foo` in IB

If module B does not depend on module A interface builder will still
show the foo IBInspectable, but it will fail at runtime.

@keith keith requested review from jpsim and marcelofabri April 7, 2020 01:47
@SwiftLintBot
Copy link

SwiftLintBot commented Apr 7, 2020

2 Warnings
⚠️ This PR introduced a violation in Kickstarter: /Library/UINavigationItem+Localized.swift:5:3: warning: IBInspectable in Extension Violation: Extensions shouldn't add @IBInspectable properties. (ibinspectable_in_extension)
⚠️ This PR introduced a violation in Kickstarter: /Library/UINavigationItem+Localized.swift:16:12: warning: IBInspectable in Extension Violation: Extensions shouldn't add @IBInspectable properties. (ibinspectable_in_extension)
12 Messages
📖 Linting Aerial with this PR took 1.72s vs 1.64s on master (4% slower)
📖 Linting Alamofire with this PR took 2.68s vs 2.65s on master (1% slower)
📖 Linting Firefox with this PR took 9.04s vs 8.98s on master (0% slower)
📖 Linting Kickstarter with this PR took 14.85s vs 14.62s on master (1% slower)
📖 Linting Moya with this PR took 1.36s vs 1.28s on master (6% slower)
📖 Linting Nimble with this PR took 1.39s vs 1.39s on master (0% slower)
📖 Linting Quick with this PR took 0.64s vs 0.64s on master (0% slower)
📖 Linting Realm with this PR took 2.65s vs 2.65s on master (0% slower)
📖 Linting SourceKitten with this PR took 1.04s vs 1.02s on master (1% slower)
📖 Linting Sourcery with this PR took 7.12s vs 7.05s on master (0% slower)
📖 Linting Swift with this PR took 10.75s vs 10.76s on master (0% faster)
📖 Linting WordPress with this PR took 16.51s vs 16.46s on master (0% slower)

Generated by 🚫 Danger

@keith keith force-pushed the ks/ibinspectable-extension branch from b0c3e3b to ee484f7 Compare April 14, 2020 21:36
This rule validates that there are no `@IBInspectable` variables in
`extension`s. The reason for this is that Interface Builder doesn't take
into account what code is actually included in your target to determine
if an inspectable should be valid. So in this case:

```swift
// Module A
extension UIView {
  @IBInspectable public var foo: String? {
    // do something
  }
}
```

```swift
// Module B
// Uses `foo` in IB
```

If module B does not depend on module A interface builder will still
show the `foo` IBInspectable, but it will fail at runtime.
@keith keith force-pushed the ks/ibinspectable-extension branch from 449ec31 to d7bb210 Compare August 4, 2020 18:48
@keith keith force-pushed the ks/ibinspectable-extension branch from d7bb210 to 713921f Compare August 4, 2020 19:57
@keith keith merged commit cf94d5d into master Aug 4, 2020
@keith keith deleted the ks/ibinspectable-extension branch August 4, 2020 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants