Files
SwiftLint/Source/SwiftLintFramework/Extensions/SyntaxKind+SwiftLint.swift
T
JP Simard d10ccacb45 Add unused_import config options to require imports for each module used (#3123)
For example, if `CGFloat` is used in a file where only `UIKit` is imported but not `CoreGraphics`, this will be a violation even if the file previously compiled.

This is because Swift allows referencing some declarations that are only transitively imported.

Enabling the `require_explicit_imports` configuration option will require that the module of every declaration referenced in a source file be explicitly imported.

This will add significant noise to the imports list, but has a few advantages:

1. It will be easier to understand all the dependencies explicitly referenced in a source file.
2. Correcting the `unused_import` rule will no longer introduce compilation errors in files that compiled prior to the correction.

If missing imports are added to a file when correcting it, the `sorted_imports` rule will be automatically run on that file.

If you with to allow some imports to be implicitly importable transitively, you may specify the `allowed_transitive_imports` configuration:

```yaml
unused_import:
  require_explicit_imports: true
  allowed_transitive_imports:
    - module: Foundation
      allowed_transitive_imports:
        - CoreFoundation
        - Darwin
        - ObjectiveC
```
2020-02-22 14:39:07 -08:00

41 lines
1.5 KiB
Swift

import SourceKittenFramework
extension SyntaxKind {
init(shortName: Swift.String) throws {
let prefix = "source.lang.swift.syntaxtype."
guard let kind = SyntaxKind(rawValue: prefix + shortName.lowercased()) else {
throw ConfigurationError.unknownConfiguration
}
self = kind
}
static let commentAndStringKinds: Set<SyntaxKind> = commentKinds.union([.string])
static let commentKinds: Set<SyntaxKind> = [.comment, .commentMark, .commentURL,
.docComment, .docCommentField]
static let allKinds: Set<SyntaxKind> = [.argument, .attributeBuiltin, .attributeID, .buildconfigID,
.buildconfigKeyword, .comment, .commentMark, .commentURL,
.docComment, .docCommentField, .identifier, .keyword, .number,
.objectLiteral, .parameter, .placeholder, .string,
.stringInterpolationAnchor, .typeidentifier]
/// Syntax kinds that don't have associated module info when getting their cursor info.
static var kindsWithoutModuleInfo: Set<SyntaxKind> {
return [
.attributeBuiltin,
.keyword,
.number,
.docComment,
.string,
.stringInterpolationAnchor,
.attributeID,
.buildconfigKeyword,
.buildconfigID,
.commentURL,
.comment,
.docCommentField
]
}
}