Skip to content
Permalink
Browse files

Fixing swiftlint & swiftformat issues (#305)

- Fixing swiftlint issues
- Ensuring swift format is updated (if needed)
  • Loading branch information...
kwridan committed Mar 24, 2019
1 parent 33fc00b commit ecb11cd479c69cc17f55aaba64e6e1f4ff9699f4
Showing with 122 additions and 109 deletions.
  1. +1 βˆ’0 .circleci/config.yml
  2. +9 βˆ’0 .circleci/setup-brew-dependencies.sh
  3. +1 βˆ’0 .swiftformat-version
  4. +2 βˆ’2 Sources/TuistEnvKit/Versions/VersionResolver.swift
  5. +3 βˆ’3 Sources/TuistKit/Commands/DumpCommand.swift
  6. +1 βˆ’1 Sources/TuistKit/Commands/GenerateCommand.swift
  7. +12 βˆ’12 Sources/TuistKit/Commands/InitCommand.swift
  8. +2 βˆ’2 Sources/TuistKit/Commands/UpCommand.swift
  9. +7 βˆ’7 Sources/TuistKit/Embed/FrameworkEmbedder.swift
  10. +17 βˆ’17 Sources/TuistKit/Generator/ConfigGenerator.swift
  11. +26 βˆ’26 Sources/TuistKit/Generator/ProjectGenerator.swift
  12. +1 βˆ’1 Sources/TuistKit/Generator/SchemesGenerator.swift
  13. +1 βˆ’1 Sources/TuistKit/Generator/WorkspaceGenerator.swift
  14. +1 βˆ’1 Sources/TuistKit/Graph/Graph.swift
  15. +9 βˆ’7 Sources/TuistKit/Linter/GraphLinter.swift
  16. +2 βˆ’2 Sources/TuistKit/Linter/ProjectLinter.swift
  17. +1 βˆ’1 Sources/TuistKit/Linter/SettingsLinter.swift
  18. +6 βˆ’6 Sources/TuistKit/Linter/TargetLinter.swift
  19. +1 βˆ’1 Sources/TuistKit/Models/Up/UpCustom.swift
  20. +2 βˆ’2 Sources/TuistKit/Models/Up/UpHomebrewTap.swift
  21. +5 βˆ’5 Sources/TuistKit/Setup/SetupLoader.swift
  22. +1 βˆ’1 Sources/TuistKit/Utils/InfoPlistProvisioner.swift
  23. +1 βˆ’1 Sources/TuistKit/Utils/ProjectFilesSortener.swift
  24. +2 βˆ’2 Sources/TuistKit/Utils/ResourceLocator.swift
  25. +1 βˆ’1 Tests/TuistEnvKitTests/Commands/CommandRegistryTests.swift
  26. +1 βˆ’1 Tests/TuistEnvKitTests/GitHub/ReleaseTests.swift
  27. +1 βˆ’1 Tests/TuistEnvKitTests/Versions/Mocks/MockVersionsController.swift
  28. +2 βˆ’2 Tests/TuistKitTests/Embed/EmbeddableTests.swift
  29. +3 βˆ’3 Tests/TuistKitTests/Embed/FrameworkEmbedderTests.swift
@@ -19,6 +19,7 @@ jobs:
command: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install swiftformat
bundle install --local || bundle package
./.circleci/setup-brew-dependencies.sh
- run:
name: Run Danger
command: bundle exec danger
@@ -0,0 +1,9 @@
#!/bin/bash

function version {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}

if [ $(version $(swiftformat --version)) -lt $(version $(cat .swiftformat-version)) ]; then
brew upgrade swiftformat
fi
@@ -0,0 +1 @@
0.40.4
@@ -70,7 +70,7 @@ class VersionResolver: VersionResolving {

// MARK: - Fileprivate
fileprivate func resolveTraversing(from path: AbsolutePath) throws -> ResolvedVersion {
private func resolveTraversing(from path: AbsolutePath) throws -> ResolvedVersion {
let versionPath = path.appending(component: Constants.versionFileName)
let binPath = path.appending(component: Constants.binFolderName)
if fileManager.fileExists(atPath: binPath.asString) {
@@ -84,7 +84,7 @@ class VersionResolver: VersionResolving {
return .undefined
}

fileprivate func resolveVersionFile(path: AbsolutePath) throws -> ResolvedVersion {
private func resolveVersionFile(path: AbsolutePath) throws -> ResolvedVersion {
var value: String!
do {
value = try String(contentsOf: URL(fileURLWithPath: path.asString))
@@ -11,9 +11,9 @@ class DumpCommand: NSObject, Command {

// MARK: - Attributes
fileprivate let fileHandler: FileHandling
fileprivate let manifestLoader: GraphManifestLoading
fileprivate let printer: Printing
private let fileHandler: FileHandling
private let manifestLoader: GraphManifestLoading
private let printer: Printing
let pathArgument: OptionArgument<String>

// MARK: - Init
@@ -75,7 +75,7 @@ class GenerateCommand: NSObject, Command {

// MARK: - Fileprivate
fileprivate func path(arguments: ArgumentParser.Result) -> AbsolutePath {
private func path(arguments: ArgumentParser.Result) -> AbsolutePath {
if let path = arguments.get(pathArgument) {
return AbsolutePath(path, relativeTo: fileHandler.currentPath)
} else {
@@ -118,13 +118,13 @@ class InitCommand: NSObject, Command {
///
/// - Parameter path: Directory to be checked.
/// - Throws: An InitCommandError.nonEmptyDirectory error when the directory is not empty.
fileprivate func verifyDirectoryIsEmpty(path: AbsolutePath) throws {
private func verifyDirectoryIsEmpty(path: AbsolutePath) throws {
if !path.glob("*").isEmpty {
throw InitCommandError.nonEmptyDirectory(path)
}
}

fileprivate func generateProjectSwift(name: String, platform: Platform, product: Product, path: AbsolutePath) throws {
private func generateProjectSwift(name: String, platform: Platform, product: Product, path: AbsolutePath) throws {
let content = """
import ProjectDescription
@@ -155,7 +155,7 @@ class InitCommand: NSObject, Command {
try content.write(to: path.appending(component: "Project.swift").url, atomically: true, encoding: .utf8)
}

fileprivate func generatePlists(platform: Platform, product: Product, path: AbsolutePath) throws {
private func generatePlists(platform: Platform, product: Product, path: AbsolutePath) throws {
try infoplistProvisioner.generate(path: path.appending(component: "Info.plist"),
platform: platform,
product: product)
@@ -165,7 +165,7 @@ class InitCommand: NSObject, Command {
}

// swiftlint:disable:next function_body_length
fileprivate func generateGitIgnore(path: AbsolutePath) throws {
private func generateGitIgnore(path: AbsolutePath) throws {
let path = path.appending(component: ".gitignore")
let content = """
### macOS ###
@@ -239,7 +239,7 @@ class InitCommand: NSObject, Command {
///
/// - Parameter path: Path where the Setup.swift file will be created.
/// - Throws: An error if the file cannot be created.
fileprivate func generateSetup(path: AbsolutePath) throws {
private func generateSetup(path: AbsolutePath) throws {
let content = """
import ProjectDescription
@@ -253,7 +253,7 @@ class InitCommand: NSObject, Command {
}

// swiftlint:disable:next function_body_length
fileprivate func generateSources(name: String, platform: Platform, product: Product, path: AbsolutePath) throws {
private func generateSources(name: String, platform: Platform, product: Product, path: AbsolutePath) throws {
let path = path.appending(component: "Sources")

try fileHandler.createFolder(path)
@@ -320,7 +320,7 @@ class InitCommand: NSObject, Command {
try content.write(to: path.appending(component: filename).url, atomically: true, encoding: .utf8)
}

fileprivate func generateTests(name: String, path: AbsolutePath) throws {
private func generateTests(name: String, path: AbsolutePath) throws {
let path = path.appending(component: "Tests")

try fileHandler.createFolder(path)
@@ -338,7 +338,7 @@ class InitCommand: NSObject, Command {
try content.write(to: path.appending(component: "\(name)Tests.swift").url, atomically: true, encoding: .utf8)
}

fileprivate func generatePlaygrounds(name: String, path: AbsolutePath, platform: Platform) throws {
private func generatePlaygrounds(name: String, path: AbsolutePath, platform: Platform) throws {
let playgroundsPath = path.appending(component: "Playgrounds")
try fileHandler.createFolder(playgroundsPath)
try playgroundGenerator.generate(path: playgroundsPath,
@@ -347,7 +347,7 @@ class InitCommand: NSObject, Command {
content: PlaygroundGenerator.defaultContent())
}

fileprivate func name(arguments: ArgumentParser.Result, path: AbsolutePath) throws -> String {
private func name(arguments: ArgumentParser.Result, path: AbsolutePath) throws -> String {
if let name = arguments.get(nameArgument) {
return name
} else if let name = path.components.last {
@@ -357,15 +357,15 @@ class InitCommand: NSObject, Command {
}
}

fileprivate func path(arguments: ArgumentParser.Result) throws -> AbsolutePath {
private func path(arguments: ArgumentParser.Result) throws -> AbsolutePath {
if let path = arguments.get(pathArgument) {
return AbsolutePath(path, relativeTo: fileHandler.currentPath)
} else {
return fileHandler.currentPath
}
}

fileprivate func product(arguments: ArgumentParser.Result) throws -> Product {
private func product(arguments: ArgumentParser.Result) throws -> Product {
if let productString = arguments.get(self.productArgument) {
let valid = ["application", "framework"]
if valid.contains(productString) {
@@ -378,7 +378,7 @@ class InitCommand: NSObject, Command {
}
}

fileprivate func platform(arguments: ArgumentParser.Result) throws -> Platform {
private func platform(arguments: ArgumentParser.Result) throws -> Platform {
if let platformString = arguments.get(self.platformArgument) {
if let platform = Platform(rawValue: platformString) {
return platform
@@ -14,7 +14,7 @@ class UpCommand: NSObject, Command {
static let overview = "Configures the environment for the project."

/// File handler instance to interact with the file system.
fileprivate let fileHandler: FileHandling
private let fileHandler: FileHandling

/// Path to the project directory.
let pathArgument: OptionArgument<String>
@@ -65,7 +65,7 @@ class UpCommand: NSObject, Command {
///
/// - Parameter arguments: Result from parsing the command line arguments.
/// - Returns: Path to be used for the up command.
fileprivate func path(arguments: ArgumentParser.Result) -> AbsolutePath {
private func path(arguments: ArgumentParser.Result) -> AbsolutePath {
guard let path = arguments.get(pathArgument) else {
return fileHandler.currentPath
}
@@ -70,7 +70,7 @@ final class FrameworkEmbedder: FrameworkEmbedding {

// MARK: - Fileprivate
fileprivate func copyFramework(productFrameworksPath: AbsolutePath, frameworkAbsolutePath: AbsolutePath, validArchs: [String]) throws {
private func copyFramework(productFrameworksPath: AbsolutePath, frameworkAbsolutePath: AbsolutePath, validArchs: [String]) throws {
let frameworkOutputPath = productFrameworksPath.appending(component: frameworkAbsolutePath.components.last!)
if fileHandler.exists(frameworkOutputPath) {
try fileHandler.delete(frameworkOutputPath)
@@ -83,9 +83,9 @@ final class FrameworkEmbedder: FrameworkEmbedding {
}
}

fileprivate func copyBCSymbolMaps(action: XcodeBuild.Action,
frameworkAbsolutePath: AbsolutePath,
builtProductsDir: AbsolutePath) throws {
private func copyBCSymbolMaps(action: XcodeBuild.Action,
frameworkAbsolutePath: AbsolutePath,
builtProductsDir: AbsolutePath) throws {
// A BCSymbolMap is a lot like a dSYM for bitcode.
// Xcode builds it as part of creating the app binary, and also for every dynamic framework.
// It's required for re-symbolicating function/method names to understand crashers.
@@ -112,9 +112,9 @@ final class FrameworkEmbedder: FrameworkEmbedding {
}
}

fileprivate func copySymbols(frameworkDsymPath: AbsolutePath,
destinationPath: AbsolutePath!,
validArchs: [String]) throws {
private func copySymbols(frameworkDsymPath: AbsolutePath,
destinationPath: AbsolutePath!,
validArchs: [String]) throws {
if fileHandler.exists(frameworkDsymPath) {
let frameworkDsymOutputPath = destinationPath.appending(component: frameworkDsymPath.components.last!)
if fileHandler.exists(frameworkDsymOutputPath) {
@@ -87,12 +87,12 @@ final class ConfigGenerator: ConfigGenerating {

// MARK: - Fileprivate
fileprivate func generateProjectSettingsFor(buildConfiguration: BuildConfiguration,
configuration: Configuration?,
project: Project,
fileElements: ProjectFileElements,
pbxproj: PBXProj,
configurationList: XCConfigurationList) throws {
private func generateProjectSettingsFor(buildConfiguration: BuildConfiguration,
configuration: Configuration?,
project: Project,
fileElements: ProjectFileElements,
pbxproj: PBXProj,
configurationList: XCConfigurationList) throws {
let variant: BuildSettingsProvider.Variant = (buildConfiguration == .debug) ? .debug : .release
let defaultConfigSettings = BuildSettingsProvider.projectDefault(variant: variant)
let defaultSettingsAll = BuildSettingsProvider.projectDefault(variant: .all)
@@ -117,14 +117,14 @@ final class ConfigGenerator: ConfigGenerating {
configurationList.buildConfigurations.append(variantBuildConfiguration)
}

fileprivate func generateTargetSettingsFor(target: Target,
buildConfiguration: BuildConfiguration,
configuration: Configuration?,
fileElements: ProjectFileElements,
graph: Graphing,
pbxproj: PBXProj,
configurationList: XCConfigurationList,
sourceRootPath: AbsolutePath) throws {
private func generateTargetSettingsFor(target: Target,
buildConfiguration: BuildConfiguration,
configuration: Configuration?,
fileElements: ProjectFileElements,
graph: Graphing,
pbxproj: PBXProj,
configurationList: XCConfigurationList,
sourceRootPath: AbsolutePath) throws {
let product = settingsProviderProduct(target)
let platform = settingsProviderPlatform(target)
let variant: BuildSettingsProvider.Variant = (buildConfiguration == .debug) ? .debug : .release
@@ -190,7 +190,7 @@ final class ConfigGenerator: ConfigGenerating {
configurationList.buildConfigurations.append(variantBuildConfiguration)
}

fileprivate func settingsProviderPlatform(_ target: Target) -> BuildSettingsProvider.Platform? {
private func settingsProviderPlatform(_ target: Target) -> BuildSettingsProvider.Platform? {
var platform: BuildSettingsProvider.Platform?
switch target.platform {
case .iOS: platform = .iOS
@@ -201,7 +201,7 @@ final class ConfigGenerator: ConfigGenerating {
return platform
}

fileprivate func settingsProviderProduct(_ target: Target) -> BuildSettingsProvider.Product? {
private func settingsProviderProduct(_ target: Target) -> BuildSettingsProvider.Product? {
switch target.product {
case .app:
return .application
@@ -216,7 +216,7 @@ final class ConfigGenerator: ConfigGenerating {
}
}

fileprivate func extend(buildSettings: inout [String: Any], with other: [String: Any]) {
private func extend(buildSettings: inout [String: Any], with other: [String: Any]) {
other.forEach { key, value in
if buildSettings[key] == nil || (value as? String)?.contains("$(inherited)") == false {
buildSettings[key] = value
@@ -118,10 +118,10 @@ final class ProjectGenerator: ProjectGenerating {

// MARK: - Fileprivate
fileprivate func generatePbxproject(project: Project,
configurationList: XCConfigurationList,
groups: ProjectGroups,
pbxproj: PBXProj) throws -> PBXProject {
private func generatePbxproject(project: Project,
configurationList: XCConfigurationList,
groups: ProjectGroups,
pbxproj: PBXProj) throws -> PBXProject {
let pbxProject = PBXProject(name: project.name,
buildConfigurationList: configurationList,
compatibilityVersion: Xcode.Default.compatibilityVersion,
@@ -140,14 +140,14 @@ final class ProjectGenerator: ProjectGenerating {
return pbxProject
}

fileprivate func generateTargets(project: Project,
pbxproj: PBXProj,
pbxProject: PBXProject,
groups: ProjectGroups,
fileElements: ProjectFileElements,
sourceRootPath: AbsolutePath,
options: GenerationOptions,
graph: Graphing) throws -> [String: PBXNativeTarget] {
private func generateTargets(project: Project,
pbxproj: PBXProj,
pbxProject: PBXProject,
groups: ProjectGroups,
fileElements: ProjectFileElements,
sourceRootPath: AbsolutePath,
options: GenerationOptions,
graph: Graphing) throws -> [String: PBXNativeTarget] {
var nativeTargets: [String: PBXNativeTarget] = [:]
try project.targets.forEach { target in
let nativeTarget = try targetGenerator.generateTarget(target: target,
@@ -171,9 +171,9 @@ final class ProjectGenerator: ProjectGenerating {
return nativeTargets
}

fileprivate func generateTestTargetIdentity(project _: Project,
pbxproj: PBXProj,
pbxProject: PBXProject) {
private func generateTestTargetIdentity(project _: Project,
pbxproj: PBXProj,
pbxProject: PBXProject) {
func testTargetName(_ target: PBXTarget) -> String? {
guard let buildConfigurations = target.buildConfigurationList?.buildConfigurations else {
return nil
@@ -203,12 +203,12 @@ final class ProjectGenerator: ProjectGenerating {
}
}

fileprivate func write(xcodeprojPath: AbsolutePath,
nativeTargets: [String: PBXNativeTarget],
workspace: XCWorkspace,
pbxproj: PBXProj,
project: Project,
graph _: Graphing) throws -> GeneratedProject {
private func write(xcodeprojPath: AbsolutePath,
nativeTargets: [String: PBXNativeTarget],
workspace: XCWorkspace,
pbxproj: PBXProj,
project: Project,
graph _: Graphing) throws -> GeneratedProject {
var generatedProject: GeneratedProject!

try fileHandler.inTemporaryDirectory { temporaryPath in
@@ -228,15 +228,15 @@ final class ProjectGenerator: ProjectGenerating {
return try generatedProject.at(path: xcodeprojPath)
}

fileprivate func writeXcodeproj(workspace: XCWorkspace,
pbxproj: PBXProj,
xcodeprojPath: AbsolutePath) throws {
private func writeXcodeproj(workspace: XCWorkspace,
pbxproj: PBXProj,
xcodeprojPath: AbsolutePath) throws {
let xcodeproj = XcodeProj(workspace: workspace, pbxproj: pbxproj)
try xcodeproj.write(path: xcodeprojPath.path)
}

fileprivate func writeSchemes(project: Project,
generatedProject: GeneratedProject) throws {
private func writeSchemes(project: Project,
generatedProject: GeneratedProject) throws {
try schemesGenerator.generateTargetSchemes(project: project,
generatedProject: generatedProject)
}
@@ -281,7 +281,7 @@ final class SchemesGenerator: SchemesGenerating {
/// - projectPath: Path to the Xcode project.
/// - Returns: Path to the schemes directory.
/// - Throws: A FatalError if the creation of the directory fails.
fileprivate func createSchemesDirectory(projectPath: AbsolutePath) throws -> AbsolutePath {
private func createSchemesDirectory(projectPath: AbsolutePath) throws -> AbsolutePath {
let path = projectPath.appending(RelativePath("xcshareddata/xcschemes"))
if !fileHandler.exists(path) {
try fileHandler.createFolder(path)
Oops, something went wrong.

0 comments on commit ecb11cd

Please sign in to comment.
You can’t perform that action at this time.