Skip to content

Commit

Permalink
Skip module import if cursor info is missing module info (#2746)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarhansen authored and jpsim committed May 6, 2019
1 parent ef50162 commit af72c06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
return type is required.
[Marcelo Fabri](https://github.com/marcelofabri)

* Skip module import if cursor info is missing module info.
[alvarhansen](https://github.com/alvarhansen)
[#2746](https://github.com/realm/SwiftLint/issues/2746)

## 0.32.0: Wash-N-Fold-N-Reduce

#### Breaking
Expand Down
11 changes: 11 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -23574,6 +23574,11 @@ import Foundation
class A {}
```

```swift
import UnknownModule
func foo(error: Swift.Error) {}
```

</details>
<details>
<summary>Triggering Examples</summary>
Expand Down Expand Up @@ -23607,6 +23612,12 @@ dispatchMain()
class A {}
```

```swift
↓import Foundation
import UnknownModule
func foo(error: Swift.Error) {}
```

</details>


Expand Down
13 changes: 11 additions & 2 deletions Source/SwiftLintFramework/Rules/Lint/UnusedImportRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public struct UnusedImportRule: CorrectableRule, ConfigurationProviderRule, Anal
import Foundation
@objc
class A {}
""",
"""
import UnknownModule
func foo(error: Swift.Error) {}
"""
],
triggeringExamples: [
Expand Down Expand Up @@ -51,6 +55,11 @@ public struct UnusedImportRule: CorrectableRule, ConfigurationProviderRule, Anal
↓import Foundation
// @objc
class A {}
""",
"""
↓import Foundation
import UnknownModule
func foo(error: Swift.Error) {}
"""
],
corrections: [
Expand Down Expand Up @@ -181,9 +190,9 @@ private extension File {
imports.insert(importedModule)
nextIsModuleImport = false
continue
} else {
nextIsModuleImport = false
}
} else {
nextIsModuleImport = false
}

if let usr = cursorInfo["key.modulename"] as? String {
Expand Down

0 comments on commit af72c06

Please sign in to comment.