Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Initial swiftlint file and fixes #781

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
included:
- Sources
- Tests
- Package.swift
excluded:
- Tests/Fixtures
- Tests/AccessibilityTests/AccessibilityProject
- Tests/XcodeTests/UIKitProject

# Enabled/disabled rules
analyzer_rules:
- all
opt_in_rules:
- all
disabled_rules:
- anyobject_protocol
- inert_defer
- unused_capture_list
- explicit_acl
- explicit_type_interface
- missing_docs
- required_deinit
- line_length
- type_contents_order
- prefer_nimble
- explicit_top_level_acl
- anonymous_argument_in_multiline_closure
- one_declaration_per_file
- conditional_returns_on_newline
- vertical_whitespace_between_cases
- no_grouping_extension
- explicit_enum_raw_value
- file_types_order
- indentation_width
- identifier_name
- trailing_closure
- multiline_arguments_brackets
- multiline_function_chains
- no_extension_access_modifier
- force_try
- switch_case_on_newline
- sorted_enum_cases
- prefer_self_in_static_references
- superfluous_else
- force_unwrapping
- file_name
- todo
- no_magic_numbers
- prefixed_toplevel_constant
- untyped_error_in_catch
- contrasted_opening_brace
- unused_parameter
- no_empty_block
- prefer_key_path
ileitch marked this conversation as resolved.
Show resolved Hide resolved

closure_body_length:
warning: 50
error: 100
function_body_length: 60
ileitch marked this conversation as resolved.
Show resolved Hide resolved
balanced_xctest_lifecycle: &unit_test_configuration
test_parent_classes:
- SourceGraphTestCase
- FixtureSourceGraphTestCase
- XCTestCase
empty_xctest_method: *unit_test_configuration
final_test_case: *unit_test_configuration
single_test_class: *unit_test_configuration
cyclomatic_complexity:
ileitch marked this conversation as resolved.
Show resolved Hide resolved
ignores_case_statements: true
2 changes: 1 addition & 1 deletion Sources/Frontend/Commands/CheckUpdateCommand.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import ArgumentParser
import Foundation
import Shared

struct CheckUpdateCommand: FrontendCommand {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Frontend/Commands/ClearCacheCommand.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import ArgumentParser
import Foundation
import Shared

struct ClearCacheCommand: FrontendCommand {
Expand Down
9 changes: 5 additions & 4 deletions Sources/Frontend/Commands/ScanBehavior.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SystemPackage
import Shared
import PeripheryKit
import Shared
import SystemPackage

final class ScanBehavior {
private let configuration: Configuration
Expand All @@ -16,7 +16,7 @@ final class ScanBehavior {
do {
var path: FilePath?

if let configPath = configPath {
if let configPath {
path = FilePath(configPath)
}
try configuration.load(from: path)
Expand All @@ -29,6 +29,7 @@ final class ScanBehavior {
return .success(())
}

// swiftlint:disable:next function_body_length cyclomatic_complexity
func main(_ block: (Project) throws -> [ScanResult]) -> Result<(), PeripheryError> {
logger.contextualized(with: "version").debug(PeripheryVersion)
let project: Project
Expand Down Expand Up @@ -90,7 +91,7 @@ final class ScanBehavior {
logger.info(output, canQuiet: false)
logger.endInterval(interval)

if filteredResults.count > 0,
if !filteredResults.isEmpty,
configuration.outputFormat.supportsAuxiliaryOutput {
logger.info(
colorize("\n* ", .boldGreen) +
Expand Down
4 changes: 2 additions & 2 deletions Sources/Frontend/Commands/ScanCommand.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import ArgumentParser
import SystemPackage
import Foundation
import Shared
import SystemPackage

struct ScanCommand: FrontendCommand {
static let configuration = CommandConfiguration(
Expand Down
2 changes: 1 addition & 1 deletion Sources/Frontend/Commands/VersionCommand.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import ArgumentParser
import Foundation

struct VersionCommand: FrontendCommand {
static let configuration = CommandConfiguration(
Expand Down
2 changes: 1 addition & 1 deletion Sources/Frontend/Project.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SystemPackage
import PeripheryKit
import Shared
import SystemPackage

#if canImport(XcodeSupport)
import XcodeSupport
Expand Down
3 changes: 1 addition & 2 deletions Sources/Frontend/SPMProjectSetupGuide.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SystemPackage
import PeripheryKit
import Shared
import SystemPackage

final class SPMProjectSetupGuide: SetupGuideHelpers, ProjectSetupGuide {
private let configuration: Configuration
Expand Down Expand Up @@ -51,5 +51,4 @@ final class SPMProjectSetupGuide: SetupGuideHelpers, ProjectSetupGuide {
let targetNames = targets.map { $0.name }.sorted()
return select(multiple: targetNames, allowAll: true)
}

}
2 changes: 1 addition & 1 deletion Sources/Frontend/Scan.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import Shared
import PeripheryKit
import Shared
import SourceGraph

final class Scan {
Expand Down
16 changes: 10 additions & 6 deletions Sources/Frontend/UpdateChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ final class UpdateChecker {
urlRequest.setValue("application/vnd.github.v3+json", forHTTPHeaderField: "Accept")

let task = urlSession.dataTask(with: urlRequest) { [weak self] data, _, error in
// swiftlint:disable:next self_binding
guard let strongSelf = self else { return }

if let error = error {
if let error {
strongSelf.debugLogger.debug("error: \(error.localizedDescription)")
strongSelf.error = error
strongSelf.semaphore.signal()
Expand All @@ -53,8 +54,11 @@ final class UpdateChecker {
let tagName = jsonObject["tag_name"] as? String else {
var json = "N/A"

if let data = data {
json = String(data: data, encoding: .utf8) ?? "N/A"
if let data {
let decoded = String(decoding: data, as: UTF8.self)
if !decoded.isEmpty {
json = decoded
}
}

let message = "Failed to identify latest release tag in: \(json)"
Expand All @@ -72,7 +76,7 @@ final class UpdateChecker {
}

func notifyIfAvailable() {
guard let latestVersion = latestVersion else { return }
guard let latestVersion else { return }

debugLogger.debug("latest: \(latestVersion)")

Expand All @@ -91,15 +95,15 @@ final class UpdateChecker {
func wait() -> Result<String, PeripheryError> {
let waitResult = semaphore.wait(timeout: .now() + 60)

if let error = error {
if let error {
return .failure(.underlyingError(error))
}

if waitResult == .timedOut {
return .failure(PeripheryError.updateCheckError(message: "Timed out while checking for update."))
}

if let latestVersion = latestVersion {
if let latestVersion {
return .success(latestVersion)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Frontend/main.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import ArgumentParser
import Foundation
import Shared

Logger.configureBuffering()
Expand Down
4 changes: 2 additions & 2 deletions Sources/Indexer/Indexer.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FilenameMatcher
import Foundation
import SystemPackage
import Shared
import FilenameMatcher
import SystemPackage

public class Indexer {
private let configuration: Configuration
Expand Down
8 changes: 4 additions & 4 deletions Sources/Indexer/InfoPlistIndexer.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Shared
import SystemPackage
import SourceGraph
import SystemPackage

public final class InfoPlistIndexer: Indexer {
private let infoPlistFiles: Set<FilePath>
Expand All @@ -19,15 +19,15 @@ public final class InfoPlistIndexer: Indexer {
excludedFiles.forEach { self.logger.debug("Excluding \($0.string)") }

try JobPool(jobs: Array(includedFiles)).forEach { [weak self] path in
guard let self = self else { return }
guard let self else { return }

let elapsed = try Benchmark.measure {
try InfoPlistParser(path: path)
.parse()
.forEach { self.graph.add($0) }
.forEach { self.graph.add($0) }
}

self.logger.debug("\(path.string) (\(elapsed)s)")
logger.debug("\(path.string) (\(elapsed)s)")
}
}
}
7 changes: 4 additions & 3 deletions Sources/Indexer/InfoPlistParser.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Foundation
import SystemPackage
import AEXML
import Foundation
import Shared
import SourceGraph
import SystemPackage

final class InfoPlistParser {
private static let elements = [
"UISceneClassName", "UISceneDelegateClassName", "NSPrincipalClass",
"NSExtensionPrincipalClass", "CLKComplicationPrincipalClass", "WKExtensionDelegateClassName"]
"NSExtensionPrincipalClass", "CLKComplicationPrincipalClass", "WKExtensionDelegateClassName"
]
private let path: FilePath

required init(path: FilePath) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Indexer/JobPool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct JobPool<T> {
}
}

if let error = error {
if let error {
throw error
}
}
Expand All @@ -43,7 +43,7 @@ struct JobPool<T> {
}
}

if let error = error {
if let error {
throw error
}

Expand Down
Loading
Loading