Remove unused code (#4729)
This commit is contained in:
parent
81f1dbfd1b
commit
500f143c7d
|
@ -17,7 +17,7 @@ struct DiscouragedOptionalCollectionRule: ASTRule, OptInRule, ConfigurationProvi
|
||||||
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(kind: kind, dictionary: dictionary) +
|
||||||
functionViolations(file: file, kind: kind, dictionary: dictionary)
|
functionViolations(file: file, kind: kind, dictionary: dictionary)
|
||||||
|
|
||||||
return offsets.map {
|
return offsets.map {
|
||||||
|
@ -29,9 +29,7 @@ struct DiscouragedOptionalCollectionRule: ASTRule, OptInRule, ConfigurationProvi
|
||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
private func variableViolations(file: SwiftLintFile,
|
private func variableViolations(kind: SwiftDeclarationKind, dictionary: SourceKittenDictionary) -> [ByteCount] {
|
||||||
kind: SwiftDeclarationKind,
|
|
||||||
dictionary: SourceKittenDictionary) -> [ByteCount] {
|
|
||||||
guard
|
guard
|
||||||
SwiftDeclarationKind.variableKinds.contains(kind),
|
SwiftDeclarationKind.variableKinds.contains(kind),
|
||||||
let offset = dictionary.offset,
|
let offset = dictionary.offset,
|
||||||
|
|
|
@ -82,7 +82,7 @@ private struct ExpressibleByCompiler {
|
||||||
let initCallNames: Set<String>
|
let initCallNames: Set<String>
|
||||||
private let arguments: Set<[String]>
|
private let arguments: Set<[String]>
|
||||||
|
|
||||||
init(protocolName: String, types: Set<String>, arguments: Set<[String]>) {
|
private init(protocolName: String, types: Set<String>, arguments: Set<[String]>) {
|
||||||
self.protocolName = protocolName
|
self.protocolName = protocolName
|
||||||
self.arguments = arguments
|
self.arguments = arguments
|
||||||
|
|
||||||
|
|
|
@ -124,8 +124,7 @@ private extension SwiftLintFile {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let contentsNSString = stringView.nsString
|
let unusedImportUsages = rangedAndSortedUnusedImports(of: Array(unusedImports))
|
||||||
let unusedImportUsages = rangedAndSortedUnusedImports(of: Array(unusedImports), contents: contentsNSString)
|
|
||||||
.map { ImportUsage.unused(module: $0, range: $1) }
|
.map { ImportUsage.unused(module: $0, range: $1) }
|
||||||
|
|
||||||
guard configuration.requireExplicitImports else {
|
guard configuration.requireExplicitImports else {
|
||||||
|
@ -188,7 +187,7 @@ private extension SwiftLintFile {
|
||||||
return (imports: imports, usrFragments: usrFragments)
|
return (imports: imports, usrFragments: usrFragments)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rangedAndSortedUnusedImports(of unusedImports: [String], contents: NSString) -> [(String, NSRange)] {
|
func rangedAndSortedUnusedImports(of unusedImports: [String]) -> [(String, NSRange)] {
|
||||||
return unusedImports
|
return unusedImports
|
||||||
.compactMap { module in
|
.compactMap { module in
|
||||||
match(pattern: "^(@\\w+ +)?import +\(module)\\b.*?\n").first.map { (module, $0.0) }
|
match(pattern: "^(@\\w+ +)?import +\(module)\\b.*?\n").first.map { (module, $0.0) }
|
||||||
|
|
|
@ -50,10 +50,6 @@ struct DeploymentTargetConfiguration: SeverityBasedRuleConfiguration, Equatable
|
||||||
self.init(platform: platform, major: major, minor: minor, patch: patch)
|
self.init(platform: platform, major: major, minor: minor, patch: patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate convenience init(platform: Platform, value: Any) throws {
|
|
||||||
try self.init(platform: platform, rawValue: String(describing: value))
|
|
||||||
}
|
|
||||||
|
|
||||||
fileprivate func update(using value: Any) throws {
|
fileprivate func update(using value: Any) throws {
|
||||||
let (major, minor, patch) = try Self.parseVersion(string: String(describing: value))
|
let (major, minor, patch) = try Self.parseVersion(string: String(describing: value))
|
||||||
self.major = major
|
self.major = major
|
||||||
|
|
|
@ -57,13 +57,11 @@ struct ModifierOrderRule: ASTRule, OptInRule, ConfigurationProviderRule, Correct
|
||||||
|
|
||||||
func correct(file: SwiftLintFile) -> [Correction] {
|
func correct(file: SwiftLintFile) -> [Correction] {
|
||||||
return file.structureDictionary.traverseDepthFirst { subDict in
|
return file.structureDictionary.traverseDepthFirst { subDict in
|
||||||
guard let kind = subDict.declarationKind else { return nil }
|
guard subDict.declarationKind != nil else { return nil }
|
||||||
return correct(file: file, kind: kind, dictionary: subDict)
|
return correct(file: file, dictionary: subDict)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private func correct(file: SwiftLintFile,
|
private func correct(file: SwiftLintFile, dictionary: SourceKittenDictionary) -> [Correction] {
|
||||||
kind: SwiftDeclarationKind,
|
|
||||||
dictionary: SourceKittenDictionary) -> [Correction] {
|
|
||||||
guard let offset = dictionary.offset else { return [] }
|
guard let offset = dictionary.offset else { return [] }
|
||||||
let originalContents = file.stringView
|
let originalContents = file.stringView
|
||||||
let violatingRanges = violatingModifiers(dictionary: dictionary)
|
let violatingRanges = violatingModifiers(dictionary: dictionary)
|
||||||
|
|
|
@ -68,8 +68,7 @@ extension Configuration {
|
||||||
}
|
}
|
||||||
let result = await Signposts.record(name: "Configuration.VisitLintableFiles.Visit") {
|
let result = await Signposts.record(name: "Configuration.VisitLintableFiles.Visit") {
|
||||||
await collected.asyncMap { linters, duplicateFileNames in
|
await collected.asyncMap { linters, duplicateFileNames in
|
||||||
await visit(linters: linters, visitor: visitor, storage: storage,
|
await visit(linters: linters, visitor: visitor, duplicateFileNames: duplicateFileNames)
|
||||||
duplicateFileNames: duplicateFileNames)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.flatMap { $0 }
|
return result.flatMap { $0 }
|
||||||
|
@ -182,7 +181,6 @@ extension Configuration {
|
||||||
|
|
||||||
private func visit(linters: [CollectedLinter],
|
private func visit(linters: [CollectedLinter],
|
||||||
visitor: LintableFilesVisitor,
|
visitor: LintableFilesVisitor,
|
||||||
storage: RuleStorage,
|
|
||||||
duplicateFileNames: Set<String>) async -> [SwiftLintFile] {
|
duplicateFileNames: Set<String>) async -> [SwiftLintFile] {
|
||||||
let counter = CounterActor()
|
let counter = CounterActor()
|
||||||
let progress = ProgressBar(count: linters.count)
|
let progress = ProgressBar(count: linters.count)
|
||||||
|
|
Loading…
Reference in New Issue