Reduce visibility of rules to be `internal`
There's no reason to expose these publicly and this will make it nicer to move to a new module outside of the core SwiftLint functionality.
This commit is contained in:
parent
2b0009daf4
commit
4501ea14bb
|
@ -1,4 +1,4 @@
|
||||||
import SwiftLintFramework
|
@testable import SwiftLintFramework
|
||||||
import SwiftLintTestHelpers
|
import SwiftLintTestHelpers
|
||||||
|
|
||||||
// swiftlint:disable file_length type_name
|
// swiftlint:disable file_length type_name
|
||||||
|
|
|
@ -14,6 +14,11 @@
|
||||||
in a future release because it is now handled by the Swift compiler.
|
in a future release because it is now handled by the Swift compiler.
|
||||||
[JP Simard](https://github.com/jpsim)
|
[JP Simard](https://github.com/jpsim)
|
||||||
|
|
||||||
|
* Built-in SwiftLint rules are no longer marked as `public` in
|
||||||
|
SwiftLintFramework. This only impacts the programmatic API for the
|
||||||
|
SwiftLintFramework module.
|
||||||
|
[JP Simard](https://github.com/jpsim)
|
||||||
|
|
||||||
#### Experimental
|
#### Experimental
|
||||||
|
|
||||||
* None.
|
* None.
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct AnonymousArgumentInMultilineClosureRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct AnonymousArgumentInMultilineClosureRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "anonymous_argument_in_multiline_closure",
|
identifier: "anonymous_argument_in_multiline_closure",
|
||||||
name: "Anonymous Argument in Multiline Closure",
|
name: "Anonymous Argument in Multiline Closure",
|
||||||
description: "Use named arguments in multiline closures",
|
description: "Use named arguments in multiline closures",
|
||||||
|
@ -33,7 +33,7 @@ public struct AnonymousArgumentInMultilineClosureRule: SwiftSyntaxRule, OptInRul
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(locationConverter: file.locationConverter)
|
Visitor(locationConverter: file.locationConverter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct BlockBasedKVORule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct BlockBasedKVORule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "block_based_kvo",
|
identifier: "block_based_kvo",
|
||||||
name: "Block Based KVO",
|
name: "Block Based KVO",
|
||||||
description: "Prefer the new block based KVO API with keypaths when using Swift 3.2 or later.",
|
description: "Prefer the new block based KVO API with keypaths when using Swift 3.2 or later.",
|
||||||
|
@ -35,7 +35,7 @@ public struct BlockBasedKVORule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ConvenienceTypeRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct ConvenienceTypeRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "convenience_type",
|
identifier: "convenience_type",
|
||||||
name: "Convenience Type",
|
name: "Convenience Type",
|
||||||
description: "Types used for hosting only static members should be implemented as a caseless enum " +
|
description: "Types used for hosting only static members should be implemented as a caseless enum " +
|
||||||
|
@ -117,7 +117,7 @@ public struct ConvenienceTypeRule: SwiftSyntaxRule, OptInRule, ConfigurationProv
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DiscouragedAssertRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct DiscouragedAssertRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "discouraged_assert",
|
identifier: "discouraged_assert",
|
||||||
name: "Discouraged Assert",
|
name: "Discouraged Assert",
|
||||||
description: "Prefer `assertionFailure()` and/or `preconditionFailure()` over `assert(false)`",
|
description: "Prefer `assertionFailure()` and/or `preconditionFailure()` over `assert(false)`",
|
||||||
|
@ -27,11 +27,11 @@ public struct DiscouragedAssertRule: SwiftSyntaxRule, OptInRule, ConfigurationPr
|
||||||
|
|
||||||
// MARK: - Life cycle
|
// MARK: - Life cycle
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
// MARK: - Public
|
// MARK: - Public
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DiscouragedNoneNameRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct DiscouragedNoneNameRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static var description = RuleDescription(
|
static var description = RuleDescription(
|
||||||
identifier: "discouraged_none_name",
|
identifier: "discouraged_none_name",
|
||||||
name: "Discouraged None Name",
|
name: "Discouraged None Name",
|
||||||
description: "Discourages name cases/static members `none`, which can conflict with `Optional<T>.none`.",
|
description: "Discourages name cases/static members `none`, which can conflict with `Optional<T>.none`.",
|
||||||
|
@ -178,7 +178,7 @@ public struct DiscouragedNoneNameRule: SwiftSyntaxRule, OptInRule, Configuration
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DiscouragedObjectLiteralRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct DiscouragedObjectLiteralRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = ObjectLiteralConfiguration()
|
var configuration = ObjectLiteralConfiguration()
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "discouraged_object_literal",
|
identifier: "discouraged_object_literal",
|
||||||
name: "Discouraged Object Literal",
|
name: "Discouraged Object Literal",
|
||||||
description: "Prefer initializers over object literals.",
|
description: "Prefer initializers over object literals.",
|
||||||
|
@ -24,7 +24,7 @@ public struct DiscouragedObjectLiteralRule: SwiftSyntaxRule, OptInRule, Configur
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(configuration: configuration)
|
Visitor(configuration: configuration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DiscouragedOptionalBooleanRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxRule {
|
struct DiscouragedOptionalBooleanRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "discouraged_optional_boolean",
|
identifier: "discouraged_optional_boolean",
|
||||||
name: "Discouraged Optional Boolean",
|
name: "Discouraged Optional Boolean",
|
||||||
description: "Prefer non-optional booleans over optional booleans.",
|
description: "Prefer non-optional booleans over optional booleans.",
|
||||||
|
@ -14,7 +14,7 @@ public struct DiscouragedOptionalBooleanRule: OptInRule, ConfigurationProviderRu
|
||||||
triggeringExamples: DiscouragedOptionalBooleanRuleExamples.triggeringExamples
|
triggeringExamples: DiscouragedOptionalBooleanRuleExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct DiscouragedOptionalCollectionRule: ASTRule, OptInRule, ConfigurationProviderRule {
|
struct DiscouragedOptionalCollectionRule: ASTRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "discouraged_optional_collection",
|
identifier: "discouraged_optional_collection",
|
||||||
name: "Discouraged Optional Collection",
|
name: "Discouraged Optional Collection",
|
||||||
description: "Prefer empty collection over optional collection.",
|
description: "Prefer empty collection over optional collection.",
|
||||||
|
@ -14,9 +14,9 @@ public struct DiscouragedOptionalCollectionRule: ASTRule, OptInRule, Configurati
|
||||||
triggeringExamples: DiscouragedOptionalCollectionExamples.triggeringExamples
|
triggeringExamples: DiscouragedOptionalCollectionExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile,
|
func validate(file: SwiftLintFile,
|
||||||
kind: SwiftDeclarationKind,
|
kind: SwiftDeclarationKind,
|
||||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||||
let offsets = variableViolations(file: file, kind: kind, dictionary: dictionary) +
|
let offsets = variableViolations(file: file, kind: kind, dictionary: dictionary) +
|
||||||
functionViolations(file: file, kind: kind, dictionary: dictionary)
|
functionViolations(file: file, kind: kind, dictionary: dictionary)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct DuplicateImportsRule: ConfigurationProviderRule, CorrectableRule {
|
struct DuplicateImportsRule: ConfigurationProviderRule, CorrectableRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
// List of all possible import kinds
|
// List of all possible import kinds
|
||||||
static let importKinds = [
|
static let importKinds = [
|
||||||
|
@ -11,9 +11,9 @@ public struct DuplicateImportsRule: ConfigurationProviderRule, CorrectableRule {
|
||||||
"var", "func"
|
"var", "func"
|
||||||
]
|
]
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "duplicate_imports",
|
identifier: "duplicate_imports",
|
||||||
name: "Duplicate Imports",
|
name: "Duplicate Imports",
|
||||||
description: "Imports should be unique.",
|
description: "Imports should be unique.",
|
||||||
|
@ -132,7 +132,7 @@ public struct DuplicateImportsRule: ConfigurationProviderRule, CorrectableRule {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
return duplicateImports(file: file).map { duplicateImport in
|
return duplicateImports(file: file).map { duplicateImport in
|
||||||
StyleViolation(
|
StyleViolation(
|
||||||
ruleDescription: Self.description,
|
ruleDescription: Self.description,
|
||||||
|
@ -142,7 +142,7 @@ public struct DuplicateImportsRule: ConfigurationProviderRule, CorrectableRule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func correct(file: SwiftLintFile) -> [Correction] {
|
func correct(file: SwiftLintFile) -> [Correction] {
|
||||||
let duplicateImports = duplicateImports(file: file).reversed().filter {
|
let duplicateImports = duplicateImports(file: file).reversed().filter {
|
||||||
file.ruleEnabled(violatingRange: $0.range, for: self) != nil
|
file.ruleEnabled(violatingRange: $0.range, for: self) != nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@ import SourceKittenFramework
|
||||||
|
|
||||||
private typealias SourceKittenElement = SourceKittenDictionary
|
private typealias SourceKittenElement = SourceKittenDictionary
|
||||||
|
|
||||||
public struct ExplicitACLRule: OptInRule, ConfigurationProviderRule {
|
struct ExplicitACLRule: OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "explicit_acl",
|
identifier: "explicit_acl",
|
||||||
name: "Explicit ACL",
|
name: "Explicit ACL",
|
||||||
description: "All declarations should specify Access Control Level keywords explicitly.",
|
description: "All declarations should specify Access Control Level keywords explicitly.",
|
||||||
|
@ -122,7 +122,7 @@ public struct ExplicitACLRule: OptInRule, ConfigurationProviderRule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
let implicitAndExplicitInternalElements = internalTypeElements(in: file.structureDictionary)
|
let implicitAndExplicitInternalElements = internalTypeElements(in: file.structureDictionary)
|
||||||
|
|
||||||
guard implicitAndExplicitInternalElements.isNotEmpty else {
|
guard implicitAndExplicitInternalElements.isNotEmpty else {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ExplicitEnumRawValueRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct ExplicitEnumRawValueRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "explicit_enum_raw_value",
|
identifier: "explicit_enum_raw_value",
|
||||||
name: "Explicit Enum Raw Value",
|
name: "Explicit Enum Raw Value",
|
||||||
description: "Enums should be explicitly assigned their raw values.",
|
description: "Enums should be explicitly assigned their raw values.",
|
||||||
|
@ -79,7 +79,7 @@ public struct ExplicitEnumRawValueRule: SwiftSyntaxRule, OptInRule, Configuratio
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
import SwiftSyntaxBuilder
|
import SwiftSyntaxBuilder
|
||||||
|
|
||||||
public struct ExplicitInitRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule, OptInRule {
|
struct ExplicitInitRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "explicit_init",
|
identifier: "explicit_init",
|
||||||
name: "Explicit Init",
|
name: "Explicit Init",
|
||||||
description: "Explicitly calling .init() should be avoided.",
|
description: "Explicitly calling .init() should be avoided.",
|
||||||
|
@ -171,11 +171,11 @@ public struct ExplicitInitRule: SwiftSyntaxCorrectableRule, ConfigurationProvide
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ExplicitTopLevelACLRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct ExplicitTopLevelACLRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "explicit_top_level_acl",
|
identifier: "explicit_top_level_acl",
|
||||||
name: "Explicit Top Level ACL",
|
name: "Explicit Top Level ACL",
|
||||||
description: "Top-level declarations should specify Access Control Level keywords explicitly.",
|
description: "Top-level declarations should specify Access Control Level keywords explicitly.",
|
||||||
|
@ -30,7 +30,7 @@ public struct ExplicitTopLevelACLRule: SwiftSyntaxRule, OptInRule, Configuration
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct ExplicitTypeInterfaceRule: OptInRule, ConfigurationProviderRule {
|
struct ExplicitTypeInterfaceRule: OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = ExplicitTypeInterfaceConfiguration()
|
var configuration = ExplicitTypeInterfaceConfiguration()
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "explicit_type_interface",
|
identifier: "explicit_type_interface",
|
||||||
name: "Explicit Type Interface",
|
name: "Explicit Type Interface",
|
||||||
description: "Properties should have a type interface",
|
description: "Properties should have a type interface",
|
||||||
|
@ -67,7 +67,7 @@ public struct ExplicitTypeInterfaceRule: OptInRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
let captureGroupRanges = Lazy(self.captureGroupRanges(in: file))
|
let captureGroupRanges = Lazy(self.captureGroupRanges(in: file))
|
||||||
return file.structureDictionary.traverseWithParentsDepthFirst { parents, subDict in
|
return file.structureDictionary.traverseWithParentsDepthFirst { parents, subDict in
|
||||||
guard let kind = subDict.declarationKind,
|
guard let kind = subDict.declarationKind,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, OptInRule {
|
struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "extension_access_modifier",
|
identifier: "extension_access_modifier",
|
||||||
name: "Extension Access Modifier",
|
name: "Extension Access Modifier",
|
||||||
description: "Prefer to use extension access modifiers",
|
description: "Prefer to use extension access modifiers",
|
||||||
|
@ -92,8 +92,8 @@ public struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, O
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
||||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||||
guard kind == .extension, let offset = dictionary.offset,
|
guard kind == .extension, let offset = dictionary.offset,
|
||||||
dictionary.inheritedTypes.isEmpty
|
dictionary.inheritedTypes.isEmpty
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct FallthroughRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct FallthroughRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "fallthrough",
|
identifier: "fallthrough",
|
||||||
name: "Fallthrough",
|
name: "Fallthrough",
|
||||||
description: "Fallthrough should be avoided.",
|
description: "Fallthrough should be avoided.",
|
||||||
|
@ -30,7 +30,7 @@ public struct FallthroughRule: SwiftSyntaxRule, ConfigurationProviderRule, OptIn
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct FatalErrorMessageRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct FatalErrorMessageRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "fatal_error_message",
|
identifier: "fatal_error_message",
|
||||||
name: "Fatal Error Message",
|
name: "Fatal Error Message",
|
||||||
description: "A fatalError call should have a message.",
|
description: "A fatalError call should have a message.",
|
||||||
|
@ -36,7 +36,7 @@ public struct FatalErrorMessageRule: SwiftSyntaxRule, ConfigurationProviderRule,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct FileNameNoSpaceRule: ConfigurationProviderRule, OptInRule, SourceKitFreeRule {
|
struct FileNameNoSpaceRule: ConfigurationProviderRule, OptInRule, SourceKitFreeRule {
|
||||||
public var configuration = FileNameNoSpaceConfiguration(
|
var configuration = FileNameNoSpaceConfiguration(
|
||||||
severity: .warning,
|
severity: .warning,
|
||||||
excluded: []
|
excluded: []
|
||||||
)
|
)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "file_name_no_space",
|
identifier: "file_name_no_space",
|
||||||
name: "File Name No Space",
|
name: "File Name No Space",
|
||||||
description: "File name should not contain any whitespace.",
|
description: "File name should not contain any whitespace.",
|
||||||
kind: .idiomatic
|
kind: .idiomatic
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
guard let filePath = file.path,
|
guard let filePath = file.path,
|
||||||
case let fileName = filePath.bridge().lastPathComponent,
|
case let fileName = filePath.bridge().lastPathComponent,
|
||||||
!configuration.excluded.contains(fileName),
|
!configuration.excluded.contains(fileName),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct FileNameRule: ConfigurationProviderRule, OptInRule, SourceKitFreeRule {
|
struct FileNameRule: ConfigurationProviderRule, OptInRule, SourceKitFreeRule {
|
||||||
public var configuration = FileNameConfiguration(
|
var configuration = FileNameConfiguration(
|
||||||
severity: .warning,
|
severity: .warning,
|
||||||
excluded: ["main.swift", "LinuxMain.swift"],
|
excluded: ["main.swift", "LinuxMain.swift"],
|
||||||
prefixPattern: "",
|
prefixPattern: "",
|
||||||
|
@ -9,16 +9,16 @@ public struct FileNameRule: ConfigurationProviderRule, OptInRule, SourceKitFreeR
|
||||||
nestedTypeSeparator: "."
|
nestedTypeSeparator: "."
|
||||||
)
|
)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "file_name",
|
identifier: "file_name",
|
||||||
name: "File Name",
|
name: "File Name",
|
||||||
description: "File name should match a type or extension declared in the file (if any).",
|
description: "File name should match a type or extension declared in the file (if any).",
|
||||||
kind: .idiomatic
|
kind: .idiomatic
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
guard let filePath = file.path,
|
guard let filePath = file.path,
|
||||||
case let fileName = filePath.bridge().lastPathComponent,
|
case let fileName = filePath.bridge().lastPathComponent,
|
||||||
!configuration.excluded.contains(fileName) else {
|
!configuration.excluded.contains(fileName) else {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ForWhereRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct ForWhereRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = ForWhereRuleConfiguration()
|
var configuration = ForWhereRuleConfiguration()
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "for_where",
|
identifier: "for_where",
|
||||||
name: "For Where",
|
name: "For Where",
|
||||||
description: "`where` clauses are preferred over a single `if` inside a `for`.",
|
description: "`where` clauses are preferred over a single `if` inside a `for`.",
|
||||||
|
@ -118,7 +118,7 @@ public struct ForWhereRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(allowForAsFilter: configuration.allowForAsFilter)
|
Visitor(allowForAsFilter: configuration.allowForAsFilter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ForceCastRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
struct ForceCastRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.error)
|
var configuration = SeverityConfiguration(.error)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "force_cast",
|
identifier: "force_cast",
|
||||||
name: "Force Cast",
|
name: "Force Cast",
|
||||||
description: "Force casts should be avoided.",
|
description: "Force casts should be avoided.",
|
||||||
|
@ -16,7 +16,7 @@ public struct ForceCastRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
triggeringExamples: [ Example("NSNumber() ↓as! Int\n") ]
|
triggeringExamples: [ Example("NSNumber() ↓as! Int\n") ]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
ForceCastRuleVisitor(viewMode: .sourceAccurate)
|
ForceCastRuleVisitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ForceTryRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
struct ForceTryRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.error)
|
var configuration = SeverityConfiguration(.error)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "force_try",
|
identifier: "force_try",
|
||||||
name: "Force Try",
|
name: "Force Try",
|
||||||
description: "Force tries should be avoided.",
|
description: "Force tries should be avoided.",
|
||||||
|
@ -26,7 +26,7 @@ public struct ForceTryRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ForceUnwrappingRule: OptInRule, SwiftSyntaxRule, ConfigurationProviderRule {
|
struct ForceUnwrappingRule: OptInRule, SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "force_unwrapping",
|
identifier: "force_unwrapping",
|
||||||
name: "Force Unwrapping",
|
name: "Force Unwrapping",
|
||||||
description: "Force unwrapping should be avoided.",
|
description: "Force unwrapping should be avoided.",
|
||||||
|
@ -67,7 +67,7 @@ public struct ForceUnwrappingRule: OptInRule, SwiftSyntaxRule, ConfigurationProv
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
ForceUnwrappingVisitor(viewMode: .sourceAccurate)
|
ForceUnwrappingVisitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct FunctionDefaultParameterAtEndRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct FunctionDefaultParameterAtEndRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "function_default_parameter_at_end",
|
identifier: "function_default_parameter_at_end",
|
||||||
name: "Function Default Parameter at End",
|
name: "Function Default Parameter at End",
|
||||||
description: "Prefer to locate parameters with defaults toward the end of the parameter list.",
|
description: "Prefer to locate parameters with defaults toward the end of the parameter list.",
|
||||||
|
@ -51,7 +51,7 @@ public struct FunctionDefaultParameterAtEndRule: SwiftSyntaxRule, ConfigurationP
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct GenericTypeNameRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct GenericTypeNameRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = NameConfiguration(minLengthWarning: 1,
|
var configuration = NameConfiguration(minLengthWarning: 1,
|
||||||
minLengthError: 0,
|
minLengthError: 0,
|
||||||
maxLengthWarning: 20,
|
maxLengthWarning: 20,
|
||||||
maxLengthError: 1000)
|
maxLengthError: 1000)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "generic_type_name",
|
identifier: "generic_type_name",
|
||||||
name: "Generic Type Name",
|
name: "Generic Type Name",
|
||||||
description: "Generic type name should only contain alphanumeric characters, start with an " +
|
description: "Generic type name should only contain alphanumeric characters, start with an " +
|
||||||
|
@ -50,7 +50,7 @@ public struct GenericTypeNameRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(configuration: configuration)
|
Visitor(configuration: configuration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ImplicitlyUnwrappedOptionalRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct ImplicitlyUnwrappedOptionalRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = ImplicitlyUnwrappedOptionalConfiguration(
|
var configuration = ImplicitlyUnwrappedOptionalConfiguration(
|
||||||
mode: .allExceptIBOutlets,
|
mode: .allExceptIBOutlets,
|
||||||
severityConfiguration: SeverityConfiguration(.warning)
|
severityConfiguration: SeverityConfiguration(.warning)
|
||||||
)
|
)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "implicitly_unwrapped_optional",
|
identifier: "implicitly_unwrapped_optional",
|
||||||
name: "Implicitly Unwrapped Optional",
|
name: "Implicitly Unwrapped Optional",
|
||||||
description: "Implicitly unwrapped optionals should be avoided when possible.",
|
description: "Implicitly unwrapped optionals should be avoided when possible.",
|
||||||
|
@ -35,7 +35,7 @@ public struct ImplicitlyUnwrappedOptionalRule: SwiftSyntaxRule, ConfigurationPro
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(mode: configuration.mode)
|
Visitor(mode: configuration.mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct IsDisjointRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct IsDisjointRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "is_disjoint",
|
identifier: "is_disjoint",
|
||||||
name: "Is Disjoint",
|
name: "Is Disjoint",
|
||||||
description: "Prefer using `Set.isDisjoint(with:)` over `Set.intersection(_:).isEmpty`.",
|
description: "Prefer using `Set.isDisjoint(with:)` over `Set.intersection(_:).isEmpty`.",
|
||||||
|
@ -22,7 +22,7 @@ public struct IsDisjointRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct JoinedDefaultParameterRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule, OptInRule {
|
struct JoinedDefaultParameterRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "joined_default_parameter",
|
identifier: "joined_default_parameter",
|
||||||
name: "Joined Default Parameter",
|
name: "Joined Default Parameter",
|
||||||
description: "Discouraged explicit usage of the default separator.",
|
description: "Discouraged explicit usage of the default separator.",
|
||||||
|
@ -38,11 +38,11 @@ public struct JoinedDefaultParameterRule: SwiftSyntaxCorrectableRule, Configurat
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
public struct LegacyCGGeometryFunctionsRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
struct LegacyCGGeometryFunctionsRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "legacy_cggeometry_functions",
|
identifier: "legacy_cggeometry_functions",
|
||||||
name: "Legacy CGGeometry Functions",
|
name: "Legacy CGGeometry Functions",
|
||||||
description: "Struct extension properties and methods are preferred over legacy functions",
|
description: "Struct extension properties and methods are preferred over legacy functions",
|
||||||
|
@ -102,11 +102,11 @@ public struct LegacyCGGeometryFunctionsRule: SwiftSyntaxCorrectableRule, Configu
|
||||||
"CGRectIntersection": .function(name: "intersect", argumentLabels: [""])
|
"CGRectIntersection": .function(name: "intersect", argumentLabels: [""])
|
||||||
]
|
]
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
LegacyFunctionRuleHelper.Visitor(legacyFunctions: Self.legacyFunctions)
|
LegacyFunctionRuleHelper.Visitor(legacyFunctions: Self.legacyFunctions)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
LegacyFunctionRuleHelper.Rewriter(
|
LegacyFunctionRuleHelper.Rewriter(
|
||||||
legacyFunctions: Self.legacyFunctions,
|
legacyFunctions: Self.legacyFunctions,
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
import SwiftSyntaxBuilder
|
import SwiftSyntaxBuilder
|
||||||
|
|
||||||
public struct LegacyConstantRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
struct LegacyConstantRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "legacy_constant",
|
identifier: "legacy_constant",
|
||||||
name: "Legacy Constant",
|
name: "Legacy Constant",
|
||||||
description: "Struct-scoped constants are preferred over legacy global constants.",
|
description: "Struct-scoped constants are preferred over legacy global constants.",
|
||||||
|
@ -16,11 +16,11 @@ public struct LegacyConstantRule: SwiftSyntaxCorrectableRule, ConfigurationProvi
|
||||||
corrections: LegacyConstantRuleExamples.corrections
|
corrections: LegacyConstantRuleExamples.corrections
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct LegacyConstructorRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
struct LegacyConstructorRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "legacy_constructor",
|
identifier: "legacy_constructor",
|
||||||
name: "Legacy Constructor",
|
name: "Legacy Constructor",
|
||||||
description: "Swift constructors are preferred over legacy convenience functions.",
|
description: "Swift constructors are preferred over legacy convenience functions.",
|
||||||
|
@ -124,11 +124,11 @@ public struct LegacyConstructorRule: SwiftSyntaxCorrectableRule, ConfigurationPr
|
||||||
"NSEdgeInsetsMake": "NSEdgeInsets",
|
"NSEdgeInsetsMake": "NSEdgeInsets",
|
||||||
"UIOffsetMake": "UIOffset"]
|
"UIOffsetMake": "UIOffset"]
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct LegacyHashingRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct LegacyHashingRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "legacy_hashing",
|
identifier: "legacy_hashing",
|
||||||
name: "Legacy Hashing",
|
name: "Legacy Hashing",
|
||||||
description: "Prefer using the `hash(into:)` function instead of overriding `hashValue`",
|
description: "Prefer using the `hash(into:)` function instead of overriding `hashValue`",
|
||||||
|
@ -75,7 +75,7 @@ public struct LegacyHashingRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct LegacyMultipleRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxRule {
|
struct LegacyMultipleRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "legacy_multiple",
|
identifier: "legacy_multiple",
|
||||||
name: "Legacy Multiple",
|
name: "Legacy Multiple",
|
||||||
description: "Prefer using the `isMultiple(of:)` function instead of using the remainder operator (`%`).",
|
description: "Prefer using the `isMultiple(of:)` function instead of using the remainder operator (`%`).",
|
||||||
|
@ -39,11 +39,11 @@ public struct LegacyMultipleRule: OptInRule, ConfigurationProviderRule, SwiftSyn
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func preprocess(syntaxTree: SourceFileSyntax) -> SourceFileSyntax? {
|
func preprocess(syntaxTree: SourceFileSyntax) -> SourceFileSyntax? {
|
||||||
syntaxTree.folded()
|
syntaxTree.folded()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
public struct LegacyNSGeometryFunctionsRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
struct LegacyNSGeometryFunctionsRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "legacy_nsgeometry_functions",
|
identifier: "legacy_nsgeometry_functions",
|
||||||
name: "Legacy NSGeometry Functions",
|
name: "Legacy NSGeometry Functions",
|
||||||
description: "Struct extension properties and methods are preferred over legacy functions",
|
description: "Struct extension properties and methods are preferred over legacy functions",
|
||||||
|
@ -102,11 +102,11 @@ public struct LegacyNSGeometryFunctionsRule: SwiftSyntaxCorrectableRule, Configu
|
||||||
"NSPointInRect": .function(name: "contains", argumentLabels: [""], reversed: true)
|
"NSPointInRect": .function(name: "contains", argumentLabels: [""], reversed: true)
|
||||||
]
|
]
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
LegacyFunctionRuleHelper.Visitor(legacyFunctions: Self.legacyFunctions)
|
LegacyFunctionRuleHelper.Visitor(legacyFunctions: Self.legacyFunctions)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
LegacyFunctionRuleHelper.Rewriter(
|
LegacyFunctionRuleHelper.Rewriter(
|
||||||
legacyFunctions: Self.legacyFunctions,
|
legacyFunctions: Self.legacyFunctions,
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
|
|
|
@ -28,12 +28,12 @@ private let legacyObjcTypes = [
|
||||||
"NSUUID"
|
"NSUUID"
|
||||||
]
|
]
|
||||||
|
|
||||||
public struct LegacyObjcTypeRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct LegacyObjcTypeRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "legacy_objc_type",
|
identifier: "legacy_objc_type",
|
||||||
name: "Legacy Objective-C Reference Type",
|
name: "Legacy Objective-C Reference Type",
|
||||||
description: "Prefer Swift value types to bridged Objective-C reference types",
|
description: "Prefer Swift value types to bridged Objective-C reference types",
|
||||||
|
@ -68,7 +68,7 @@ public struct LegacyObjcTypeRule: SwiftSyntaxRule, OptInRule, ConfigurationProvi
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct LegacyRandomRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct LegacyRandomRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static var description = RuleDescription(
|
static var description = RuleDescription(
|
||||||
identifier: "legacy_random",
|
identifier: "legacy_random",
|
||||||
name: "Legacy Random",
|
name: "Legacy Random",
|
||||||
description: "Prefer using `type.random(in:)` over legacy functions.",
|
description: "Prefer using `type.random(in:)` over legacy functions.",
|
||||||
|
@ -22,7 +22,7 @@ public struct LegacyRandomRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct NimbleOperatorRule: ConfigurationProviderRule, OptInRule, CorrectableRule {
|
struct NimbleOperatorRule: ConfigurationProviderRule, OptInRule, CorrectableRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "nimble_operator",
|
identifier: "nimble_operator",
|
||||||
name: "Nimble Operator",
|
name: "Nimble Operator",
|
||||||
description: "Prefer Nimble operator overloads over free matcher functions.",
|
description: "Prefer Nimble operator overloads over free matcher functions.",
|
||||||
|
@ -98,7 +98,7 @@ public struct NimbleOperatorRule: ConfigurationProviderRule, OptInRule, Correcta
|
||||||
"beNil": (to: "==", toNot: "!=", .nullary(analogueValue: "nil"))
|
"beNil": (to: "==", toNot: "!=", .nullary(analogueValue: "nil"))
|
||||||
]
|
]
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
let matches = violationMatchesRanges(in: file)
|
let matches = violationMatchesRanges(in: file)
|
||||||
return matches.map {
|
return matches.map {
|
||||||
StyleViolation(ruleDescription: Self.description,
|
StyleViolation(ruleDescription: Self.description,
|
||||||
|
@ -144,7 +144,7 @@ public struct NimbleOperatorRule: ConfigurationProviderRule, OptInRule, Correcta
|
||||||
.map { $0.0 }
|
.map { $0.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
public func correct(file: SwiftLintFile) -> [Correction] {
|
func correct(file: SwiftLintFile) -> [Correction] {
|
||||||
let matches = violationMatchesRanges(in: file)
|
let matches = violationMatchesRanges(in: file)
|
||||||
.filter { file.ruleEnabled(violatingRanges: [$0], for: self).isNotEmpty }
|
.filter { file.ruleEnabled(violatingRanges: [$0], for: self).isNotEmpty }
|
||||||
guard matches.isNotEmpty else { return [] }
|
guard matches.isNotEmpty else { return [] }
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct NoExtensionAccessModifierRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct NoExtensionAccessModifierRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.error)
|
var configuration = SeverityConfiguration(.error)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "no_extension_access_modifier",
|
identifier: "no_extension_access_modifier",
|
||||||
name: "No Extension Access Modifier",
|
name: "No Extension Access Modifier",
|
||||||
description: "Prefer not to use extension access modifiers",
|
description: "Prefer not to use extension access modifiers",
|
||||||
|
@ -23,7 +23,7 @@ public struct NoExtensionAccessModifierRule: SwiftSyntaxRule, OptInRule, Configu
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct NoFallthroughOnlyRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct NoFallthroughOnlyRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "no_fallthrough_only",
|
identifier: "no_fallthrough_only",
|
||||||
name: "No Fallthrough Only",
|
name: "No Fallthrough Only",
|
||||||
description: "Fallthroughs can only be used if the `case` contains at least one other statement.",
|
description: "Fallthroughs can only be used if the `case` contains at least one other statement.",
|
||||||
|
@ -14,7 +14,7 @@ public struct NoFallthroughOnlyRule: SwiftSyntaxRule, ConfigurationProviderRule
|
||||||
triggeringExamples: NoFallthroughOnlyRuleExamples.triggeringExamples
|
triggeringExamples: NoFallthroughOnlyRuleExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct NoGroupingExtensionRule: OptInRule, ConfigurationProviderRule {
|
struct NoGroupingExtensionRule: OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "no_grouping_extension",
|
identifier: "no_grouping_extension",
|
||||||
name: "No Grouping Extension",
|
name: "No Grouping Extension",
|
||||||
description: "Extensions shouldn't be used to group code within the same source file.",
|
description: "Extensions shouldn't be used to group code within the same source file.",
|
||||||
|
@ -23,7 +23,7 @@ public struct NoGroupingExtensionRule: OptInRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
let collector = NamespaceCollector(dictionary: file.structureDictionary)
|
let collector = NamespaceCollector(dictionary: file.structureDictionary)
|
||||||
let elements = collector.findAllElements(of: [.class, .enum, .struct, .extension])
|
let elements = collector.findAllElements(of: [.class, .enum, .struct, .extension])
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct NoMagicNumbersRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct NoMagicNumbersRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "no_magic_numbers",
|
identifier: "no_magic_numbers",
|
||||||
name: "No Magic Numbers",
|
name: "No Magic Numbers",
|
||||||
description: "Magic numbers should be replaced by named constants.",
|
description: "Magic numbers should be replaced by named constants.",
|
||||||
|
@ -50,7 +50,7 @@ public struct NoMagicNumbersRule: SwiftSyntaxRule, OptInRule, ConfigurationProvi
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ObjectLiteralRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct ObjectLiteralRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = ObjectLiteralConfiguration()
|
var configuration = ObjectLiteralConfiguration()
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "object_literal",
|
identifier: "object_literal",
|
||||||
name: "Object Literal",
|
name: "Object Literal",
|
||||||
description: "Prefer object literals over image and color inits.",
|
description: "Prefer object literals over image and color inits.",
|
||||||
|
@ -33,7 +33,7 @@ public struct ObjectLiteralRule: SwiftSyntaxRule, ConfigurationProviderRule, Opt
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(validateImageLiteral: configuration.imageLiteral, validateColorLiteral: configuration.colorLiteral)
|
Visitor(validateImageLiteral: configuration.imageLiteral, validateColorLiteral: configuration.colorLiteral)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct PatternMatchingKeywordsRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct PatternMatchingKeywordsRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "pattern_matching_keywords",
|
identifier: "pattern_matching_keywords",
|
||||||
name: "Pattern Matching Keywords",
|
name: "Pattern Matching Keywords",
|
||||||
description: "Combine multiple pattern matching bindings by moving keywords out of tuples.",
|
description: "Combine multiple pattern matching bindings by moving keywords out of tuples.",
|
||||||
|
@ -35,7 +35,7 @@ public struct PatternMatchingKeywordsRule: SwiftSyntaxRule, ConfigurationProvide
|
||||||
].map(wrapInSwitch)
|
].map(wrapInSwitch)
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct PreferNimbleRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct PreferNimbleRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "prefer_nimble",
|
identifier: "prefer_nimble",
|
||||||
name: "Prefer Nimble",
|
name: "Prefer Nimble",
|
||||||
description: "Prefer Nimble matchers over XCTAssert functions.",
|
description: "Prefer Nimble matchers over XCTAssert functions.",
|
||||||
|
@ -24,7 +24,7 @@ public struct PreferNimbleRule: SwiftSyntaxRule, OptInRule, ConfigurationProvide
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct PreferZeroOverExplicitInitRule: SwiftSyntaxCorrectableRule, OptInRule, ConfigurationProviderRule {
|
struct PreferZeroOverExplicitInitRule: SwiftSyntaxCorrectableRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "prefer_zero_over_explicit_init",
|
identifier: "prefer_zero_over_explicit_init",
|
||||||
name: "Prefer Zero Over Explicit Init",
|
name: "Prefer Zero Over Explicit Init",
|
||||||
description: "Prefer `.zero` over explicit init with zero parameters (e.g. `CGPoint(x: 0, y: 0)`)",
|
description: "Prefer `.zero` over explicit init with zero parameters (e.g. `CGPoint(x: 0, y: 0)`)",
|
||||||
|
@ -34,13 +34,13 @@ public struct PreferZeroOverExplicitInitRule: SwiftSyntaxCorrectableRule, OptInR
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct PrivateOverFilePrivateRule: ConfigurationProviderRule, SwiftSyntaxCorrectableRule {
|
struct PrivateOverFilePrivateRule: ConfigurationProviderRule, SwiftSyntaxCorrectableRule {
|
||||||
public var configuration = PrivateOverFilePrivateRuleConfiguration()
|
var configuration = PrivateOverFilePrivateRuleConfiguration()
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "private_over_fileprivate",
|
identifier: "private_over_fileprivate",
|
||||||
name: "Private over fileprivate",
|
name: "Private over fileprivate",
|
||||||
description: "Prefer `private` over `fileprivate` declarations.",
|
description: "Prefer `private` over `fileprivate` declarations.",
|
||||||
|
@ -56,11 +56,11 @@ public struct PrivateOverFilePrivateRule: ConfigurationProviderRule, SwiftSyntax
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(validateExtensions: configuration.validateExtensions)
|
Visitor(validateExtensions: configuration.validateExtensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
validateExtensions: configuration.validateExtensions,
|
validateExtensions: configuration.validateExtensions,
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct RedundantNilCoalescingRule: OptInRule, SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
struct RedundantNilCoalescingRule: OptInRule, SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "redundant_nil_coalescing",
|
identifier: "redundant_nil_coalescing",
|
||||||
name: "Redundant Nil Coalescing",
|
name: "Redundant Nil Coalescing",
|
||||||
description: "nil coalescing operator is only evaluated if the lhs is nil" +
|
description: "nil coalescing operator is only evaluated if the lhs is nil" +
|
||||||
|
@ -23,11 +23,11 @@ public struct RedundantNilCoalescingRule: OptInRule, SwiftSyntaxCorrectableRule,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -5,12 +5,12 @@ private let attributeNamesImplyingObjc: Set<String> = [
|
||||||
"IBAction", "IBOutlet", "IBInspectable", "GKInspectable", "IBDesignable", "NSManaged"
|
"IBAction", "IBOutlet", "IBInspectable", "GKInspectable", "IBDesignable", "NSManaged"
|
||||||
]
|
]
|
||||||
|
|
||||||
public struct RedundantObjcAttributeRule: SwiftSyntaxRule, SubstitutionCorrectableRule, ConfigurationProviderRule {
|
struct RedundantObjcAttributeRule: SwiftSyntaxRule, SubstitutionCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "redundant_objc_attribute",
|
identifier: "redundant_objc_attribute",
|
||||||
name: "Redundant @objc Attribute",
|
name: "Redundant @objc Attribute",
|
||||||
description: "Objective-C attribute (@objc) is redundant in declaration.",
|
description: "Objective-C attribute (@objc) is redundant in declaration.",
|
||||||
|
@ -20,7 +20,7 @@ public struct RedundantObjcAttributeRule: SwiftSyntaxRule, SubstitutionCorrectab
|
||||||
corrections: RedundantObjcAttributeRuleExamples.corrections
|
corrections: RedundantObjcAttributeRuleExamples.corrections
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
final class Visitor: ViolationsSyntaxVisitor {
|
final class Visitor: ViolationsSyntaxVisitor {
|
||||||
override func visitPost(_ node: AttributeListSyntax) {
|
override func visitPost(_ node: AttributeListSyntax) {
|
||||||
if let objcAttribute = node.violatingObjCAttribute {
|
if let objcAttribute = node.violatingObjCAttribute {
|
||||||
|
@ -31,7 +31,7 @@ public struct RedundantObjcAttributeRule: SwiftSyntaxRule, SubstitutionCorrectab
|
||||||
return Visitor(viewMode: .sourceAccurate)
|
return Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func violationRanges(in file: SwiftLintFile) -> [NSRange] {
|
func violationRanges(in file: SwiftLintFile) -> [NSRange] {
|
||||||
makeVisitor(file: file)
|
makeVisitor(file: file)
|
||||||
.walk(tree: file.syntaxTree, handler: \.violations)
|
.walk(tree: file.syntaxTree, handler: \.violations)
|
||||||
.compactMap { violation in
|
.compactMap { violation in
|
||||||
|
@ -100,7 +100,7 @@ private extension AttributeListSyntax {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension RedundantObjcAttributeRule {
|
extension RedundantObjcAttributeRule {
|
||||||
func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? {
|
func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? {
|
||||||
var whitespaceAndNewlineOffset = 0
|
var whitespaceAndNewlineOffset = 0
|
||||||
let nsCharSet = CharacterSet.whitespacesAndNewlines.bridge()
|
let nsCharSet = CharacterSet.whitespacesAndNewlines.bridge()
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct RedundantOptionalInitializationRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
struct RedundantOptionalInitializationRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "redundant_optional_initialization",
|
identifier: "redundant_optional_initialization",
|
||||||
name: "Redundant Optional Initialization",
|
name: "Redundant Optional Initialization",
|
||||||
description: "Initializing an optional variable with nil is redundant.",
|
description: "Initializing an optional variable with nil is redundant.",
|
||||||
|
@ -106,11 +106,11 @@ public struct RedundantOptionalInitializationRule: SwiftSyntaxCorrectableRule, C
|
||||||
""")
|
""")
|
||||||
]
|
]
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct RedundantSetAccessControlRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
struct RedundantSetAccessControlRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "redundant_set_access_control",
|
identifier: "redundant_set_access_control",
|
||||||
name: "Redundant Set Access Control Rule",
|
name: "Redundant Set Access Control Rule",
|
||||||
description: "Property setter access level shouldn't be explicit if " +
|
description: "Property setter access level shouldn't be explicit if " +
|
||||||
|
@ -60,7 +60,7 @@ public struct RedundantSetAccessControlRule: ConfigurationProviderRule, SwiftSyn
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct RedundantStringEnumValueRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct RedundantStringEnumValueRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "redundant_string_enum_value",
|
identifier: "redundant_string_enum_value",
|
||||||
name: "Redundant String Enum Value",
|
name: "Redundant String Enum Value",
|
||||||
description: "String enum values can be omitted when they are equal to the enumcase name.",
|
description: "String enum values can be omitted when they are equal to the enumcase name.",
|
||||||
|
@ -61,7 +61,7 @@ public struct RedundantStringEnumValueRule: SwiftSyntaxRule, ConfigurationProvid
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRule, ConfigurationProviderRule {
|
struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "redundant_type_annotation",
|
identifier: "redundant_type_annotation",
|
||||||
name: "Redundant Type Annotation",
|
name: "Redundant Type Annotation",
|
||||||
description: "Variables should not have redundant type annotation",
|
description: "Variables should not have redundant type annotation",
|
||||||
|
@ -76,7 +76,7 @@ public struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRul
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
return violationRanges(in: file).map { range in
|
return violationRanges(in: file).map { range in
|
||||||
StyleViolation(
|
StyleViolation(
|
||||||
ruleDescription: Self.description,
|
ruleDescription: Self.description,
|
||||||
|
@ -86,14 +86,14 @@ public struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? {
|
func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? {
|
||||||
return (violationRange, "")
|
return (violationRange, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
private let typeAnnotationPattern: String
|
private let typeAnnotationPattern: String
|
||||||
private let expressionPattern: String
|
private let expressionPattern: String
|
||||||
|
|
||||||
public init() {
|
init() {
|
||||||
typeAnnotationPattern =
|
typeAnnotationPattern =
|
||||||
":\\s*" + // semicolon and any number of whitespaces
|
":\\s*" + // semicolon and any number of whitespaces
|
||||||
"\\w+" // type name
|
"\\w+" // type name
|
||||||
|
@ -109,7 +109,7 @@ public struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRul
|
||||||
"[\\(\\.]?" // possible opening parenthesis or dot
|
"[\\(\\.]?" // possible opening parenthesis or dot
|
||||||
}
|
}
|
||||||
|
|
||||||
public func violationRanges(in file: SwiftLintFile) -> [NSRange] {
|
func violationRanges(in file: SwiftLintFile) -> [NSRange] {
|
||||||
let violatingRanges = file
|
let violatingRanges = file
|
||||||
.match(pattern: expressionPattern)
|
.match(pattern: expressionPattern)
|
||||||
.filter {
|
.filter {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct RedundantVoidReturnRule: ConfigurationProviderRule, SubstitutionCorrectableASTRule {
|
struct RedundantVoidReturnRule: ConfigurationProviderRule, SubstitutionCorrectableASTRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "redundant_void_return",
|
identifier: "redundant_void_return",
|
||||||
name: "Redundant Void Return",
|
name: "Redundant Void Return",
|
||||||
description: "Returning Void in a function declaration is redundant.",
|
description: "Returning Void in a function declaration is redundant.",
|
||||||
|
@ -60,8 +60,8 @@ public struct RedundantVoidReturnRule: ConfigurationProviderRule, SubstitutionCo
|
||||||
private let excludingKinds = SyntaxKind.allKinds.subtracting([.typeidentifier])
|
private let excludingKinds = SyntaxKind.allKinds.subtracting([.typeidentifier])
|
||||||
private let functionKinds = SwiftDeclarationKind.functionKinds.subtracting([.functionSubscript])
|
private let functionKinds = SwiftDeclarationKind.functionKinds.subtracting([.functionSubscript])
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
||||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||||
return violationRanges(in: file, kind: kind, dictionary: dictionary).map {
|
return violationRanges(in: file, kind: kind, dictionary: dictionary).map {
|
||||||
StyleViolation(ruleDescription: Self.description,
|
StyleViolation(ruleDescription: Self.description,
|
||||||
severity: configuration.severity,
|
severity: configuration.severity,
|
||||||
|
@ -69,8 +69,8 @@ public struct RedundantVoidReturnRule: ConfigurationProviderRule, SubstitutionCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func violationRanges(in file: SwiftLintFile, kind: SwiftDeclarationKind,
|
func violationRanges(in file: SwiftLintFile, kind: SwiftDeclarationKind,
|
||||||
dictionary: SourceKittenDictionary) -> [NSRange] {
|
dictionary: SourceKittenDictionary) -> [NSRange] {
|
||||||
guard functionKinds.contains(kind),
|
guard functionKinds.contains(kind),
|
||||||
containsVoidReturnTypeBasedOnTypeName(dictionary: dictionary),
|
containsVoidReturnTypeBasedOnTypeName(dictionary: dictionary),
|
||||||
let nameOffset = dictionary.nameOffset,
|
let nameOffset = dictionary.nameOffset,
|
||||||
|
@ -90,7 +90,7 @@ public struct RedundantVoidReturnRule: ConfigurationProviderRule, SubstitutionCo
|
||||||
return [match]
|
return [match]
|
||||||
}
|
}
|
||||||
|
|
||||||
public func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? {
|
func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? {
|
||||||
return (violationRange, "")
|
return (violationRange, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ReturnValueFromVoidFunctionRule: ConfigurationProviderRule, OptInRule, SwiftSyntaxRule {
|
struct ReturnValueFromVoidFunctionRule: ConfigurationProviderRule, OptInRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "return_value_from_void_function",
|
identifier: "return_value_from_void_function",
|
||||||
name: "Return Value from Void Function",
|
name: "Return Value from Void Function",
|
||||||
description: "Returning values from Void functions should be avoided.",
|
description: "Returning values from Void functions should be avoided.",
|
||||||
|
@ -15,7 +15,7 @@ public struct ReturnValueFromVoidFunctionRule: ConfigurationProviderRule, OptInR
|
||||||
triggeringExamples: ReturnValueFromVoidFunctionRuleExamples.triggeringExamples
|
triggeringExamples: ReturnValueFromVoidFunctionRuleExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
ReturnValueFromVoidFunctionVisitor(viewMode: .sourceAccurate)
|
ReturnValueFromVoidFunctionVisitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ShorthandOptionalBindingRule: OptInRule, SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
struct ShorthandOptionalBindingRule: OptInRule, SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public static var description = RuleDescription(
|
static var description = RuleDescription(
|
||||||
identifier: "shorthand_optional_binding",
|
identifier: "shorthand_optional_binding",
|
||||||
name: "Shorthand Optional Binding",
|
name: "Shorthand Optional Binding",
|
||||||
description: "Use shorthand syntax for optional binding",
|
description: "Use shorthand syntax for optional binding",
|
||||||
|
@ -79,13 +79,13 @@ public struct ShorthandOptionalBindingRule: OptInRule, SwiftSyntaxCorrectableRul
|
||||||
deprecatedAliases: ["if_let_shadowing"]
|
deprecatedAliases: ["if_let_shadowing"]
|
||||||
)
|
)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct StaticOperatorRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct StaticOperatorRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "static_operator",
|
identifier: "static_operator",
|
||||||
name: "Static Operator",
|
name: "Static Operator",
|
||||||
description: "Operators should be declared as static functions, not free functions.",
|
description: "Operators should be declared as static functions, not free functions.",
|
||||||
|
@ -78,7 +78,7 @@ public struct StaticOperatorRule: SwiftSyntaxRule, ConfigurationProviderRule, Op
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct StrictFilePrivateRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxRule {
|
struct StrictFilePrivateRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "strict_fileprivate",
|
identifier: "strict_fileprivate",
|
||||||
name: "Strict fileprivate",
|
name: "Strict fileprivate",
|
||||||
description: "`fileprivate` should be avoided.",
|
description: "`fileprivate` should be avoided.",
|
||||||
|
@ -58,7 +58,7 @@ public struct StrictFilePrivateRule: OptInRule, ConfigurationProviderRule, Swift
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@ import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct SyntacticSugarRule: CorrectableRule, ConfigurationProviderRule, SourceKitFreeRule {
|
struct SyntacticSugarRule: CorrectableRule, ConfigurationProviderRule, SourceKitFreeRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "syntactic_sugar",
|
identifier: "syntactic_sugar",
|
||||||
name: "Syntactic Sugar",
|
name: "Syntactic Sugar",
|
||||||
description: "Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>.",
|
description: "Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>.",
|
||||||
|
@ -17,7 +17,7 @@ public struct SyntacticSugarRule: CorrectableRule, ConfigurationProviderRule, So
|
||||||
corrections: SyntacticSugarRuleExamples.corrections
|
corrections: SyntacticSugarRuleExamples.corrections
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
let visitor = SyntacticSugarRuleVisitor(viewMode: .sourceAccurate)
|
let visitor = SyntacticSugarRuleVisitor(viewMode: .sourceAccurate)
|
||||||
return visitor.walk(file: file) { visitor in
|
return visitor.walk(file: file) { visitor in
|
||||||
flattenViolations(visitor.violations)
|
flattenViolations(visitor.violations)
|
||||||
|
@ -33,7 +33,7 @@ public struct SyntacticSugarRule: CorrectableRule, ConfigurationProviderRule, So
|
||||||
return violations.flatMap { [$0] + flattenViolations($0.children) }
|
return violations.flatMap { [$0] + flattenViolations($0.children) }
|
||||||
}
|
}
|
||||||
|
|
||||||
public func correct(file: SwiftLintFile) -> [Correction] {
|
func correct(file: SwiftLintFile) -> [Correction] {
|
||||||
let visitor = SyntacticSugarRuleVisitor(viewMode: .sourceAccurate)
|
let visitor = SyntacticSugarRuleVisitor(viewMode: .sourceAccurate)
|
||||||
return visitor.walk(file: file) { visitor in
|
return visitor.walk(file: file) { visitor in
|
||||||
var context = CorrectingContext(rule: self, file: file, contents: file.contents)
|
var context = CorrectingContext(rule: self, file: file, contents: file.contents)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
import SwiftSyntaxBuilder
|
import SwiftSyntaxBuilder
|
||||||
|
|
||||||
public struct ToggleBoolRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule, OptInRule {
|
struct ToggleBoolRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static var description = RuleDescription(
|
static var description = RuleDescription(
|
||||||
identifier: "toggle_bool",
|
identifier: "toggle_bool",
|
||||||
name: "Toggle Bool",
|
name: "Toggle Bool",
|
||||||
description: "Prefer `someBool.toggle()` over `someBool = !someBool`.",
|
description: "Prefer `someBool.toggle()` over `someBool = !someBool`.",
|
||||||
|
@ -31,11 +31,11 @@ public struct ToggleBoolRule: SwiftSyntaxCorrectableRule, ConfigurationProviderR
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct TrailingSemicolonRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
struct TrailingSemicolonRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "trailing_semicolon",
|
identifier: "trailing_semicolon",
|
||||||
name: "Trailing Semicolon",
|
name: "Trailing Semicolon",
|
||||||
description: "Lines should not have trailing semicolons.",
|
description: "Lines should not have trailing semicolons.",
|
||||||
|
@ -24,11 +24,11 @@ public struct TrailingSemicolonRule: SwiftSyntaxCorrectableRule, ConfigurationPr
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct TypeNameRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct TypeNameRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = TypeNameRuleConfiguration()
|
var configuration = TypeNameRuleConfiguration()
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "type_name",
|
identifier: "type_name",
|
||||||
name: "Type Name",
|
name: "Type Name",
|
||||||
description: "Type name should only contain alphanumeric characters, start with an " +
|
description: "Type name should only contain alphanumeric characters, start with an " +
|
||||||
|
@ -17,7 +17,7 @@ public struct TypeNameRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
triggeringExamples: TypeNameRuleExamples.triggeringExamples
|
triggeringExamples: TypeNameRuleExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(configuration: configuration)
|
Visitor(configuration: configuration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct UnavailableConditionRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
struct UnavailableConditionRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "unavailable_condition",
|
identifier: "unavailable_condition",
|
||||||
name: "Unavailable Condition",
|
name: "Unavailable Condition",
|
||||||
description: "Use #unavailable/#available instead of #available/#unavailable with an empty body.",
|
description: "Use #unavailable/#available instead of #available/#unavailable with an empty body.",
|
||||||
|
@ -71,7 +71,7 @@ public struct UnavailableConditionRule: ConfigurationProviderRule, SwiftSyntaxRu
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
UnavailableConditionRuleVisitor(viewMode: .sourceAccurate)
|
UnavailableConditionRuleVisitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct UnavailableFunctionRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct UnavailableFunctionRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "unavailable_function",
|
identifier: "unavailable_function",
|
||||||
name: "Unavailable Function",
|
name: "Unavailable Function",
|
||||||
description: "Unimplemented functions should be marked as unavailable.",
|
description: "Unimplemented functions should be marked as unavailable.",
|
||||||
|
@ -72,7 +72,7 @@ public struct UnavailableFunctionRule: SwiftSyntaxRule, ConfigurationProviderRul
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,12 @@ private func embedInSwitch(
|
||||||
""", file: file, line: line)
|
""", file: file, line: line)
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct UnneededBreakInSwitchRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct UnneededBreakInSwitchRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "unneeded_break_in_switch",
|
identifier: "unneeded_break_in_switch",
|
||||||
name: "Unneeded Break in Switch",
|
name: "Unneeded Break in Switch",
|
||||||
description: "Avoid using unneeded break statements.",
|
description: "Avoid using unneeded break statements.",
|
||||||
|
@ -50,7 +50,7 @@ public struct UnneededBreakInSwitchRule: SwiftSyntaxRule, ConfigurationProviderR
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
UnneededBreakInSwitchRuleVisitor(viewMode: .sourceAccurate)
|
UnneededBreakInSwitchRuleVisitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct UntypedErrorInCatchRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxCorrectableRule {
|
struct UntypedErrorInCatchRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxCorrectableRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "untyped_error_in_catch",
|
identifier: "untyped_error_in_catch",
|
||||||
name: "Untyped Error in Catch",
|
name: "Untyped Error in Catch",
|
||||||
description: "Catch statements should not declare error variables without type casting.",
|
description: "Catch statements should not declare error variables without type casting.",
|
||||||
|
@ -87,11 +87,11 @@ public struct UntypedErrorInCatchRule: OptInRule, ConfigurationProviderRule, Swi
|
||||||
Example("do {\n try foo() \n} ↓catch (let error) {}"): Example("do {\n try foo() \n} catch {}")
|
Example("do {\n try foo() \n} ↓catch (let error) {}"): Example("do {\n try foo() \n} catch {}")
|
||||||
])
|
])
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
UntypedErrorInCatchRuleVisitor(viewMode: .sourceAccurate)
|
UntypedErrorInCatchRuleVisitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
UntypedErrorInCatchRuleRewriter(
|
UntypedErrorInCatchRuleRewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct UnusedEnumeratedRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct UnusedEnumeratedRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "unused_enumerated",
|
identifier: "unused_enumerated",
|
||||||
name: "Unused Enumerated",
|
name: "Unused Enumerated",
|
||||||
description: "When the index or the item is not used, `.enumerated()` can be removed.",
|
description: "When the index or the item is not used, `.enumerated()` can be removed.",
|
||||||
|
@ -29,7 +29,7 @@ public struct UnusedEnumeratedRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct VoidFunctionInTernaryConditionRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
struct VoidFunctionInTernaryConditionRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "void_function_in_ternary",
|
identifier: "void_function_in_ternary",
|
||||||
name: "Void Function in Ternary",
|
name: "Void Function in Ternary",
|
||||||
description: "Using ternary to call Void functions should be avoided.",
|
description: "Using ternary to call Void functions should be avoided.",
|
||||||
|
@ -108,7 +108,7 @@ public struct VoidFunctionInTernaryConditionRule: ConfigurationProviderRule, Swi
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
VoidFunctionInTernaryConditionVisitor(viewMode: .sourceAccurate)
|
VoidFunctionInTernaryConditionVisitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct XCTFailMessageRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct XCTFailMessageRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "xctfail_message",
|
identifier: "xctfail_message",
|
||||||
name: "XCTFail Message",
|
name: "XCTFail Message",
|
||||||
description: "An XCTFail call should include a description of the assertion.",
|
description: "An XCTFail call should include a description of the assertion.",
|
||||||
|
@ -36,7 +36,7 @@ public struct XCTFailMessageRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct XCTSpecificMatcherRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct XCTSpecificMatcherRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "xct_specific_matcher",
|
identifier: "xct_specific_matcher",
|
||||||
name: "XCTest Specific Matcher",
|
name: "XCTest Specific Matcher",
|
||||||
description: "Prefer specific XCTest matchers over `XCTAssertEqual` and `XCTAssertNotEqual`",
|
description: "Prefer specific XCTest matchers over `XCTAssertEqual` and `XCTAssertNotEqual`",
|
||||||
|
@ -14,7 +14,7 @@ public struct XCTSpecificMatcherRule: SwiftSyntaxRule, OptInRule, ConfigurationP
|
||||||
triggeringExamples: XCTSpecificMatcherRuleExamples.triggeringExamples
|
triggeringExamples: XCTSpecificMatcherRuleExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,12 @@ import SourceKittenFramework
|
||||||
/// Known false negatives for Images declared as instance variables and containers that provide a label but are
|
/// Known false negatives for Images declared as instance variables and containers that provide a label but are
|
||||||
/// not accessibility elements. Known false positives for Images created in a separate function from where they
|
/// not accessibility elements. Known false positives for Images created in a separate function from where they
|
||||||
/// have accessibility properties applied.
|
/// have accessibility properties applied.
|
||||||
public struct AccessibilityLabelForImageRule: ASTRule, ConfigurationProviderRule, OptInRule {
|
struct AccessibilityLabelForImageRule: ASTRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "accessibility_label_for_image",
|
identifier: "accessibility_label_for_image",
|
||||||
name: "Accessibility Label for Image",
|
name: "Accessibility Label for Image",
|
||||||
description: "All Images that provide context should have an accessibility label. " +
|
description: "All Images that provide context should have an accessibility label. " +
|
||||||
|
@ -27,8 +27,8 @@ public struct AccessibilityLabelForImageRule: ASTRule, ConfigurationProviderRule
|
||||||
|
|
||||||
// MARK: AST Rule
|
// MARK: AST Rule
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
||||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||||
// Only proceed to check View structs.
|
// Only proceed to check View structs.
|
||||||
guard kind == .struct,
|
guard kind == .struct,
|
||||||
dictionary.inheritedTypes.contains("View"),
|
dictionary.inheritedTypes.contains("View"),
|
||||||
|
|
|
@ -7,12 +7,12 @@ import SourceKittenFramework
|
||||||
/// element, you need to explicitly add the button or link trait. In most cases the button trait should be used, but for
|
/// element, you need to explicitly add the button or link trait. In most cases the button trait should be used, but for
|
||||||
/// buttons that open a URL in an external browser we use the link trait instead. This rule attempts to catch uses of
|
/// buttons that open a URL in an external browser we use the link trait instead. This rule attempts to catch uses of
|
||||||
/// the SwiftUI `.onTapGesture` modifier where the `.isButton` or `.isLink` trait is not explicitly applied.
|
/// the SwiftUI `.onTapGesture` modifier where the `.isButton` or `.isLink` trait is not explicitly applied.
|
||||||
public struct AccessibilityTraitForButtonRule: ASTRule, ConfigurationProviderRule, OptInRule {
|
struct AccessibilityTraitForButtonRule: ASTRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "accessibility_trait_for_button",
|
identifier: "accessibility_trait_for_button",
|
||||||
name: "Accessibility Trait for Button",
|
name: "Accessibility Trait for Button",
|
||||||
description: "All views with tap gestures added should include the .isButton " +
|
description: "All views with tap gestures added should include the .isButton " +
|
||||||
|
@ -26,8 +26,8 @@ public struct AccessibilityTraitForButtonRule: ASTRule, ConfigurationProviderRul
|
||||||
|
|
||||||
// MARK: AST Rule
|
// MARK: AST Rule
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
||||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||||
// Only proceed to check View structs.
|
// Only proceed to check View structs.
|
||||||
guard kind == .struct,
|
guard kind == .struct,
|
||||||
dictionary.inheritedTypes.contains("View"),
|
dictionary.inheritedTypes.contains("View"),
|
||||||
|
|
|
@ -11,12 +11,12 @@ private func warnDeprecatedOnce() {
|
||||||
_ = warnDeprecatedOnceImpl
|
_ = warnDeprecatedOnceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct AnyObjectProtocolRule: SwiftSyntaxCorrectableRule, OptInRule, ConfigurationProviderRule {
|
struct AnyObjectProtocolRule: SwiftSyntaxCorrectableRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "anyobject_protocol",
|
identifier: "anyobject_protocol",
|
||||||
name: "AnyObject Protocol",
|
name: "AnyObject Protocol",
|
||||||
description: "Prefer using `AnyObject` over `class` for class-only protocols.",
|
description: "Prefer using `AnyObject` over `class` for class-only protocols.",
|
||||||
|
@ -42,12 +42,12 @@ public struct AnyObjectProtocolRule: SwiftSyntaxCorrectableRule, OptInRule, Conf
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
warnDeprecatedOnce()
|
warnDeprecatedOnce()
|
||||||
return Visitor(viewMode: .sourceAccurate)
|
return Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ArrayInitRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct ArrayInitRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "array_init",
|
identifier: "array_init",
|
||||||
name: "Array Init",
|
name: "Array Init",
|
||||||
description: "Prefer using `Array(seq)` over `seq.map { $0 }` to convert a sequence into an Array.",
|
description: "Prefer using `Array(seq)` over `seq.map { $0 }` to convert a sequence into an Array.",
|
||||||
|
@ -51,7 +51,7 @@ public struct ArrayInitRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRu
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct BalancedXCTestLifecycleRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct BalancedXCTestLifecycleRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "balanced_xctest_lifecycle",
|
identifier: "balanced_xctest_lifecycle",
|
||||||
name: "Balanced XCTest life-cycle",
|
name: "Balanced XCTest life-cycle",
|
||||||
description: "Test classes must implement balanced setUp and tearDown methods.",
|
description: "Test classes must implement balanced setUp and tearDown methods.",
|
||||||
|
@ -108,11 +108,11 @@ public struct BalancedXCTestLifecycleRule: SwiftSyntaxRule, OptInRule, Configura
|
||||||
|
|
||||||
// MARK: - Life cycle
|
// MARK: - Life cycle
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
// MARK: - Public
|
// MARK: - Public
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct CaptureVariableRule: ConfigurationProviderRule, AnalyzerRule, CollectingRule {
|
struct CaptureVariableRule: ConfigurationProviderRule, AnalyzerRule, CollectingRule {
|
||||||
public struct Variable: Hashable {
|
struct Variable: Hashable {
|
||||||
let usr: String
|
let usr: String
|
||||||
let offset: ByteCount
|
let offset: ByteCount
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias USR = String
|
typealias USR = String
|
||||||
public typealias FileInfo = Set<USR>
|
typealias FileInfo = Set<USR>
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "capture_variable",
|
identifier: "capture_variable",
|
||||||
name: "Capture Variable",
|
name: "Capture Variable",
|
||||||
description: "Non-constant variables should not be listed in a closure's capture list" +
|
description: "Non-constant variables should not be listed in a closure's capture list" +
|
||||||
|
@ -152,16 +152,16 @@ public struct CaptureVariableRule: ConfigurationProviderRule, AnalyzerRule, Coll
|
||||||
requiresFileOnDisk: true
|
requiresFileOnDisk: true
|
||||||
)
|
)
|
||||||
|
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public func collectInfo(for file: SwiftLintFile, compilerArguments: [String]) -> CaptureVariableRule.FileInfo {
|
func collectInfo(for file: SwiftLintFile, compilerArguments: [String]) -> CaptureVariableRule.FileInfo {
|
||||||
file.declaredVariables(compilerArguments: compilerArguments)
|
file.declaredVariables(compilerArguments: compilerArguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile, collectedInfo: [SwiftLintFile: CaptureVariableRule.FileInfo],
|
func validate(file: SwiftLintFile, collectedInfo: [SwiftLintFile: CaptureVariableRule.FileInfo],
|
||||||
compilerArguments: [String]) -> [StyleViolation] {
|
compilerArguments: [String]) -> [StyleViolation] {
|
||||||
file.captureListVariables(compilerArguments: compilerArguments)
|
file.captureListVariables(compilerArguments: compilerArguments)
|
||||||
.filter { capturedVariable in collectedInfo.values.contains { $0.contains(capturedVariable.usr) } }
|
.filter { capturedVariable in collectedInfo.values.contains { $0.contains(capturedVariable.usr) } }
|
||||||
.map {
|
.map {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct ClassDelegateProtocolRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct ClassDelegateProtocolRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "class_delegate_protocol",
|
identifier: "class_delegate_protocol",
|
||||||
name: "Class Delegate Protocol",
|
name: "Class Delegate Protocol",
|
||||||
description: "Delegate protocols should be class-only so they can be weakly referenced.",
|
description: "Delegate protocols should be class-only so they can be weakly referenced.",
|
||||||
|
@ -31,7 +31,7 @@ public struct ClassDelegateProtocolRule: SwiftSyntaxRule, ConfigurationProviderR
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@ import Foundation
|
||||||
import IDEUtils
|
import IDEUtils
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct CommentSpacingRule: SourceKitFreeRule, ConfigurationProviderRule, SubstitutionCorrectableRule {
|
struct CommentSpacingRule: SourceKitFreeRule, ConfigurationProviderRule, SubstitutionCorrectableRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "comment_spacing",
|
identifier: "comment_spacing",
|
||||||
name: "Comment Spacing",
|
name: "Comment Spacing",
|
||||||
description: "Prefer at least one space after slashes for comments.",
|
description: "Prefer at least one space after slashes for comments.",
|
||||||
|
@ -119,7 +119,7 @@ public struct CommentSpacingRule: SourceKitFreeRule, ConfigurationProviderRule,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func violationRanges(in file: SwiftLintFile) -> [NSRange] {
|
func violationRanges(in file: SwiftLintFile) -> [NSRange] {
|
||||||
// Find all comment tokens in the file and regex search them for violations
|
// Find all comment tokens in the file and regex search them for violations
|
||||||
file.syntaxClassifications
|
file.syntaxClassifications
|
||||||
.compactMap { (classifiedRange: SyntaxClassifiedRange) -> [NSRange]? in
|
.compactMap { (classifiedRange: SyntaxClassifiedRange) -> [NSRange]? in
|
||||||
|
@ -156,7 +156,7 @@ public struct CommentSpacingRule: SourceKitFreeRule, ConfigurationProviderRule,
|
||||||
.flatMap { $0 }
|
.flatMap { $0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
return violationRanges(in: file).map { range in
|
return violationRanges(in: file).map { range in
|
||||||
StyleViolation(
|
StyleViolation(
|
||||||
ruleDescription: Self.description,
|
ruleDescription: Self.description,
|
||||||
|
@ -166,7 +166,7 @@ public struct CommentSpacingRule: SourceKitFreeRule, ConfigurationProviderRule,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? {
|
func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? {
|
||||||
return (violationRange, " ")
|
return (violationRange, " ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct CompilerProtocolInitRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct CompilerProtocolInitRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "compiler_protocol_init",
|
identifier: "compiler_protocol_init",
|
||||||
name: "Compiler Protocol Init",
|
name: "Compiler Protocol Init",
|
||||||
description: Self.violationReason(
|
description: Self.violationReason(
|
||||||
|
@ -30,7 +30,7 @@ public struct CompilerProtocolInitRule: SwiftSyntaxRule, ConfigurationProviderRu
|
||||||
"shouldn't be called directly."
|
"shouldn't be called directly."
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DeploymentTargetRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
struct DeploymentTargetRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
private typealias Version = DeploymentTargetConfiguration.Version
|
private typealias Version = DeploymentTargetConfiguration.Version
|
||||||
public var configuration = DeploymentTargetConfiguration()
|
var configuration = DeploymentTargetConfiguration()
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "deployment_target",
|
identifier: "deployment_target",
|
||||||
name: "Deployment Target",
|
name: "Deployment Target",
|
||||||
description: "Availability checks or attributes shouldn't be using older versions " +
|
description: "Availability checks or attributes shouldn't be using older versions " +
|
||||||
|
@ -16,7 +16,7 @@ public struct DeploymentTargetRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
triggeringExamples: DeploymentTargetRuleExamples.triggeringExamples
|
triggeringExamples: DeploymentTargetRuleExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(platformToConfiguredMinVersion: platformToConfiguredMinVersion)
|
Visitor(platformToConfiguredMinVersion: platformToConfiguredMinVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DiscardedNotificationCenterObserverRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct DiscardedNotificationCenterObserverRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "discarded_notification_center_observer",
|
identifier: "discarded_notification_center_observer",
|
||||||
name: "Discarded Notification Center Observer",
|
name: "Discarded Notification Center Observer",
|
||||||
description: "When registering for a notification using a block, the opaque observer that is " +
|
description: "When registering for a notification using a block, the opaque observer that is " +
|
||||||
|
@ -50,7 +50,7 @@ public struct DiscardedNotificationCenterObserverRule: SwiftSyntaxRule, Configur
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DiscouragedDirectInitRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct DiscouragedDirectInitRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = DiscouragedDirectInitConfiguration()
|
var configuration = DiscouragedDirectInitConfiguration()
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "discouraged_direct_init",
|
identifier: "discouraged_direct_init",
|
||||||
name: "Discouraged Direct Initialization",
|
name: "Discouraged Direct Initialization",
|
||||||
description: "Discouraged direct initialization of types that can be harmful.",
|
description: "Discouraged direct initialization of types that can be harmful.",
|
||||||
|
@ -37,7 +37,7 @@ public struct DiscouragedDirectInitRule: SwiftSyntaxRule, ConfigurationProviderR
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(discouragedInits: configuration.discouragedInits)
|
Visitor(discouragedInits: configuration.discouragedInits)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DuplicateEnumCasesRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
struct DuplicateEnumCasesRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.error)
|
var configuration = SeverityConfiguration(.error)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "duplicate_enum_cases",
|
identifier: "duplicate_enum_cases",
|
||||||
name: "Duplicate Enum Cases",
|
name: "Duplicate Enum Cases",
|
||||||
description: "Enum can't contain multiple cases with the same name.",
|
description: "Enum can't contain multiple cases with the same name.",
|
||||||
|
@ -57,7 +57,7 @@ public struct DuplicateEnumCasesRule: ConfigurationProviderRule, SwiftSyntaxRule
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DuplicatedKeyInDictionaryLiteralRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct DuplicatedKeyInDictionaryLiteralRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static var description = RuleDescription(
|
static var description = RuleDescription(
|
||||||
identifier: "duplicated_key_in_dictionary_literal",
|
identifier: "duplicated_key_in_dictionary_literal",
|
||||||
name: "Duplicated Key in Dictionary Literal",
|
name: "Duplicated Key in Dictionary Literal",
|
||||||
description: "Dictionary literals with duplicated keys will crash in runtime.",
|
description: "Dictionary literals with duplicated keys will crash in runtime.",
|
||||||
|
@ -79,7 +79,7 @@ public struct DuplicatedKeyInDictionaryLiteralRule: SwiftSyntaxRule, Configurati
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct DynamicInlineRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct DynamicInlineRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.error)
|
var configuration = SeverityConfiguration(.error)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "dynamic_inline",
|
identifier: "dynamic_inline",
|
||||||
name: "Dynamic Inline",
|
name: "Dynamic Inline",
|
||||||
description: "Avoid using 'dynamic' and '@inline(__always)' together.",
|
description: "Avoid using 'dynamic' and '@inline(__always)' together.",
|
||||||
|
@ -24,7 +24,7 @@ public struct DynamicInlineRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct EmptyXCTestMethodRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxRule {
|
struct EmptyXCTestMethodRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "empty_xctest_method",
|
identifier: "empty_xctest_method",
|
||||||
name: "Empty XCTest Method",
|
name: "Empty XCTest Method",
|
||||||
description: "Empty XCTest method should be avoided.",
|
description: "Empty XCTest method should be avoided.",
|
||||||
|
@ -14,7 +14,7 @@ public struct EmptyXCTestMethodRule: OptInRule, ConfigurationProviderRule, Swift
|
||||||
triggeringExamples: EmptyXCTestMethodRuleExamples.triggeringExamples
|
triggeringExamples: EmptyXCTestMethodRuleExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
EmptyXCTestMethodRuleVisitor(viewMode: .sourceAccurate)
|
EmptyXCTestMethodRuleVisitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct ExpiringTodoRule: ConfigurationProviderRule, OptInRule {
|
struct ExpiringTodoRule: ConfigurationProviderRule, OptInRule {
|
||||||
enum ExpiryViolationLevel {
|
enum ExpiryViolationLevel {
|
||||||
case approachingExpiry
|
case approachingExpiry
|
||||||
case expired
|
case expired
|
||||||
|
@ -19,7 +19,7 @@ public struct ExpiringTodoRule: ConfigurationProviderRule, OptInRule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "expiring_todo",
|
identifier: "expiring_todo",
|
||||||
name: "Expiring Todo",
|
name: "Expiring Todo",
|
||||||
description: "TODOs and FIXMEs should be resolved prior to their expiry date.",
|
description: "TODOs and FIXMEs should be resolved prior to their expiry date.",
|
||||||
|
@ -44,11 +44,11 @@ public struct ExpiringTodoRule: ConfigurationProviderRule, OptInRule {
|
||||||
].skipWrappingInCommentTests()
|
].skipWrappingInCommentTests()
|
||||||
)
|
)
|
||||||
|
|
||||||
public var configuration: ExpiringTodoConfiguration = .init()
|
var configuration: ExpiringTodoConfiguration = .init()
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
let regex = #"""
|
let regex = #"""
|
||||||
\b(?:TODO|FIXME)(?::|\b)(?:(?!\b(?:TODO|FIXME)(?::|\b)).)*?\#
|
\b(?:TODO|FIXME)(?::|\b)(?:(?!\b(?:TODO|FIXME)(?::|\b)).)*?\#
|
||||||
\\#(configuration.dateDelimiters.opening)\#
|
\\#(configuration.dateDelimiters.opening)\#
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct IBInspectableInExtensionRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
struct IBInspectableInExtensionRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "ibinspectable_in_extension",
|
identifier: "ibinspectable_in_extension",
|
||||||
name: "IBInspectable in Extension",
|
name: "IBInspectable in Extension",
|
||||||
description: "Extensions shouldn't add @IBInspectable properties.",
|
description: "Extensions shouldn't add @IBInspectable properties.",
|
||||||
|
@ -26,7 +26,7 @@ public struct IBInspectableInExtensionRule: SwiftSyntaxRule, ConfigurationProvid
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct IdenticalOperandsRule: ConfigurationProviderRule, SwiftSyntaxRule, OptInRule {
|
struct IdenticalOperandsRule: ConfigurationProviderRule, SwiftSyntaxRule, OptInRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
private static let operators = ["==", "!=", "===", "!==", ">", ">=", "<", "<="]
|
private static let operators = ["==", "!=", "===", "!==", ">", ">=", "<", "<="]
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "identical_operands",
|
identifier: "identical_operands",
|
||||||
name: "Identical Operands",
|
name: "Identical Operands",
|
||||||
description: "Comparing two identical operands is likely a mistake.",
|
description: "Comparing two identical operands is likely a mistake.",
|
||||||
|
@ -72,11 +72,11 @@ public struct IdenticalOperandsRule: ConfigurationProviderRule, SwiftSyntaxRule,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func preprocess(syntaxTree: SourceFileSyntax) -> SourceFileSyntax? {
|
func preprocess(syntaxTree: SourceFileSyntax) -> SourceFileSyntax? {
|
||||||
syntaxTree.folded()
|
syntaxTree.folded()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct InertDeferRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
struct InertDeferRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "inert_defer",
|
identifier: "inert_defer",
|
||||||
name: "Inert Defer",
|
name: "Inert Defer",
|
||||||
description: "If defer is at the end of its parent scope, it will be executed right where it is anyway.",
|
description: "If defer is at the end of its parent scope, it will be executed right where it is anyway.",
|
||||||
|
@ -50,7 +50,7 @@ public struct InertDeferRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct LowerACLThanParentRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxCorrectableRule {
|
struct LowerACLThanParentRule: OptInRule, ConfigurationProviderRule, SwiftSyntaxCorrectableRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "lower_acl_than_parent",
|
identifier: "lower_acl_than_parent",
|
||||||
name: "Lower ACL than parent",
|
name: "Lower ACL than parent",
|
||||||
description: "Ensure declarations have a lower access control level than their enclosing parent",
|
description: "Ensure declarations have a lower access control level than their enclosing parent",
|
||||||
|
@ -56,11 +56,11 @@ public struct LowerACLThanParentRule: OptInRule, ConfigurationProviderRule, Swif
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
|
||||||
Rewriter(
|
Rewriter(
|
||||||
locationConverter: file.locationConverter,
|
locationConverter: file.locationConverter,
|
||||||
disabledRegions: disabledRegions(file: file)
|
disabledRegions: disabledRegions(file: file)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
public struct MarkRule: CorrectableRule, ConfigurationProviderRule {
|
struct MarkRule: CorrectableRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "mark",
|
identifier: "mark",
|
||||||
name: "Mark",
|
name: "Mark",
|
||||||
description: "MARK comment should be in valid format. e.g. '// MARK: ...' or '// MARK: - ...'",
|
description: "MARK comment should be in valid format. e.g. '// MARK: ...' or '// MARK: - ...'",
|
||||||
|
@ -102,7 +102,7 @@ public struct MarkRule: CorrectableRule, ConfigurationProviderRule {
|
||||||
].joined(separator: "|")
|
].joined(separator: "|")
|
||||||
}
|
}
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
return violationRanges(in: file, matching: pattern).map {
|
return violationRanges(in: file, matching: pattern).map {
|
||||||
StyleViolation(ruleDescription: Self.description,
|
StyleViolation(ruleDescription: Self.description,
|
||||||
severity: configuration.severity,
|
severity: configuration.severity,
|
||||||
|
@ -110,7 +110,7 @@ public struct MarkRule: CorrectableRule, ConfigurationProviderRule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func correct(file: SwiftLintFile) -> [Correction] {
|
func correct(file: SwiftLintFile) -> [Correction] {
|
||||||
var result = [Correction]()
|
var result = [Correction]()
|
||||||
|
|
||||||
result.append(contentsOf: correct(file: file,
|
result.append(contentsOf: correct(file: file,
|
||||||
|
|
|
@ -43,15 +43,15 @@ private extension SwiftLintFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct MissingDocsRule: OptInRule, ConfigurationProviderRule {
|
struct MissingDocsRule: OptInRule, ConfigurationProviderRule {
|
||||||
public init() {
|
init() {
|
||||||
configuration = MissingDocsRuleConfiguration()
|
configuration = MissingDocsRuleConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias ConfigurationType = MissingDocsRuleConfiguration
|
typealias ConfigurationType = MissingDocsRuleConfiguration
|
||||||
public var configuration: MissingDocsRuleConfiguration
|
var configuration: MissingDocsRuleConfiguration
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "missing_docs",
|
identifier: "missing_docs",
|
||||||
name: "Missing Docs",
|
name: "Missing Docs",
|
||||||
description: "Declarations should be documented.",
|
description: "Declarations should be documented.",
|
||||||
|
@ -119,7 +119,7 @@ public struct MissingDocsRule: OptInRule, ConfigurationProviderRule {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
let acls = configuration.parameters.map { $0.value }
|
let acls = configuration.parameters.map { $0.value }
|
||||||
let dict = file.structureDictionary
|
let dict = file.structureDictionary
|
||||||
return file.missingDocOffsets(
|
return file.missingDocOffsets(
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct NSLocalizedStringKeyRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct NSLocalizedStringKeyRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "nslocalizedstring_key",
|
identifier: "nslocalizedstring_key",
|
||||||
name: "NSLocalizedString Key",
|
name: "NSLocalizedString Key",
|
||||||
description: "Static strings should be used as key/comment" +
|
description: "Static strings should be used as key/comment" +
|
||||||
|
@ -33,7 +33,7 @@ public struct NSLocalizedStringKeyRule: SwiftSyntaxRule, OptInRule, Configuratio
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct NSLocalizedStringRequireBundleRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
struct NSLocalizedStringRequireBundleRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "nslocalizedstring_require_bundle",
|
identifier: "nslocalizedstring_require_bundle",
|
||||||
name: "NSLocalizedString Require Bundle",
|
name: "NSLocalizedString Require Bundle",
|
||||||
description: "Calls to NSLocalizedString should specify the bundle which contains the strings file.",
|
description: "Calls to NSLocalizedString should specify the bundle which contains the strings file.",
|
||||||
|
@ -42,7 +42,7 @@ public struct NSLocalizedStringRequireBundleRule: SwiftSyntaxRule, OptInRule, Co
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
// this rule exists due to a compiler bug: https://github.com/apple/swift/issues/51036
|
// this rule exists due to a compiler bug: https://github.com/apple/swift/issues/51036
|
||||||
public struct NSNumberInitAsFunctionReferenceRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct NSNumberInitAsFunctionReferenceRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "ns_number_init_as_function_reference",
|
identifier: "ns_number_init_as_function_reference",
|
||||||
name: "NSNumber Init as Function Reference",
|
name: "NSNumber Init as Function Reference",
|
||||||
description: "Passing `NSNumber.init` or `NSDecimalNumber.init` as a function reference is dangerous " +
|
description: "Passing `NSNumber.init` or `NSDecimalNumber.init` as a function reference is dangerous " +
|
||||||
|
@ -24,7 +24,7 @@ public struct NSNumberInitAsFunctionReferenceRule: SwiftSyntaxRule, Configuratio
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct NSObjectPreferIsEqualRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct NSObjectPreferIsEqualRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "nsobject_prefer_isequal",
|
identifier: "nsobject_prefer_isequal",
|
||||||
name: "NSObject Prefer isEqual",
|
name: "NSObject Prefer isEqual",
|
||||||
description: "NSObject subclasses should implement isEqual instead of ==.",
|
description: "NSObject subclasses should implement isEqual instead of ==.",
|
||||||
|
@ -14,7 +14,7 @@ public struct NSObjectPreferIsEqualRule: SwiftSyntaxRule, ConfigurationProviderR
|
||||||
triggeringExamples: NSObjectPreferIsEqualRuleExamples.triggeringExamples
|
triggeringExamples: NSObjectPreferIsEqualRuleExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct NotificationCenterDetachmentRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
struct NotificationCenterDetachmentRule: SwiftSyntaxRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "notification_center_detachment",
|
identifier: "notification_center_detachment",
|
||||||
name: "Notification Center Detachment",
|
name: "Notification Center Detachment",
|
||||||
description: "An object should only remove itself as an observer in `deinit`.",
|
description: "An object should only remove itself as an observer in `deinit`.",
|
||||||
|
@ -14,7 +14,7 @@ public struct NotificationCenterDetachmentRule: SwiftSyntaxRule, ConfigurationPr
|
||||||
triggeringExamples: NotificationCenterDetachmentRuleExamples.triggeringExamples
|
triggeringExamples: NotificationCenterDetachmentRuleExamples.triggeringExamples
|
||||||
)
|
)
|
||||||
|
|
||||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||||
Visitor(viewMode: .sourceAccurate)
|
Visitor(viewMode: .sourceAccurate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import IDEUtils
|
import IDEUtils
|
||||||
import SwiftSyntax
|
import SwiftSyntax
|
||||||
|
|
||||||
public struct OrphanedDocCommentRule: SourceKitFreeRule, ConfigurationProviderRule {
|
struct OrphanedDocCommentRule: SourceKitFreeRule, ConfigurationProviderRule {
|
||||||
public var configuration = SeverityConfiguration(.warning)
|
var configuration = SeverityConfiguration(.warning)
|
||||||
|
|
||||||
public init() {}
|
init() {}
|
||||||
|
|
||||||
public static let description = RuleDescription(
|
static let description = RuleDescription(
|
||||||
identifier: "orphaned_doc_comment",
|
identifier: "orphaned_doc_comment",
|
||||||
name: "Orphaned Doc Comment",
|
name: "Orphaned Doc Comment",
|
||||||
description: "A doc comment should be attached to a declaration.",
|
description: "A doc comment should be attached to a declaration.",
|
||||||
|
@ -53,7 +53,7 @@ public struct OrphanedDocCommentRule: SourceKitFreeRule, ConfigurationProviderRu
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||||
let classifications = file.syntaxClassifications
|
let classifications = file.syntaxClassifications
|
||||||
.filter { $0.kind != .none }
|
.filter { $0.kind != .none }
|
||||||
let docstringsWithOtherComments = classifications
|
let docstringsWithOtherComments = classifications
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue