diff --git a/.circleci/config.yml b/.circleci/config.yml index efb245aaf..2a2e7926c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,10 +22,14 @@ jobs: name: Install Dependencies command: | bundle config build.sqlite3 --with-sqlite3-dir=/opt/local + brew install swiftlint bundle install --path vendor/bundle - run: name: Run tests command: bundle exec rake test + - run: + name: Danger + command: bundle exec danger - run: name: Send test coverage report command: bash <(curl -s https://codecov.io/bash) diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 000000000..5e2b60cf9 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,16 @@ +included: + - App/xcbuddykit/Sources + - App/Sources +excluded: + - Sources + - Tests + - .build +disabled_rules: + - trailing_whitespace + - nesting + - cyclomatic_complexity + - file_length + - todo +line_length: + warning: 150 + error: 170 diff --git a/App.xcodeproj/project.pbxproj b/App.xcodeproj/project.pbxproj index de78a035b..6e7c78ae9 100644 --- a/App.xcodeproj/project.pbxproj +++ b/App.xcodeproj/project.pbxproj @@ -745,6 +745,7 @@ buildPhases = ( B915ED152063AFBC004B6630 /* Sources */, B915ED162063AFBC004B6630 /* Frameworks */, + B918A2322093756700E64FBE /* Swift lint */, ); buildRules = ( ); @@ -904,6 +905,20 @@ shellPath = /bin/sh; shellScript = "if which sentry-cli >/dev/null; then\nexport SENTRY_ORG=xcbuddy\nexport SENTRY_PROJECT=app\nERROR=$(bin/sentry-cli upload-dsym 2>&1 >/dev/null)\nif [ ! $? -eq 0 ]; then\necho \"warning: sentry-cli - $ERROR\"\nfi\nelse\necho \"warning: sentry-cli not installed, download from https://github.com/getsentry/sentry-cli/releases\"\nfi"; }; + B918A2322093756700E64FBE /* Swift lint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Swift lint"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/App/xcbuddykit/Sources/Extensions/AbsolutePath+Extras.swift b/App/xcbuddykit/Sources/Extensions/AbsolutePath+Extras.swift index 3f090191a..ebe44eb43 100644 --- a/App/xcbuddykit/Sources/Extensions/AbsolutePath+Extras.swift +++ b/App/xcbuddykit/Sources/Extensions/AbsolutePath+Extras.swift @@ -2,7 +2,7 @@ import Basic import Darwin import Foundation -let system_glob = Darwin.glob +let systemGlob = Darwin.glob extension AbsolutePath { static var current: AbsolutePath { @@ -18,7 +18,7 @@ extension AbsolutePath { } let flags = GLOB_TILDE | GLOB_BRACE | GLOB_MARK - if system_glob(cPattern, flags, nil, >) == 0 { + if systemGlob(cPattern, flags, nil, >) == 0 { let matchc = gt.gl_matchc return (0 ..< Int(matchc)).compactMap { index in if let path = String(validatingUTF8: gt.gl_pathv[index]!) { diff --git a/App/xcbuddykit/Sources/Loader/GraphManifestLoader.swift b/App/xcbuddykit/Sources/Loader/GraphManifestLoader.swift index c110b7903..36995d2fe 100644 --- a/App/xcbuddykit/Sources/Loader/GraphManifestLoader.swift +++ b/App/xcbuddykit/Sources/Loader/GraphManifestLoader.swift @@ -62,7 +62,10 @@ class GraphManifestLoader: GraphManifestLoading { } let swiftPath = AbsolutePath(swiftOutput) let manifestFrameworkPath = try context.resourceLocator.projectDescription() - let jsonString: String! = try context.shell.run(swiftPath.asString, "-F", manifestFrameworkPath.parentDirectory.asString, "-framework", "ProjectDescription", path.asString, "--dump").chuzzle() + let jsonString: String! = try context.shell.run(swiftPath.asString, "-F", + manifestFrameworkPath.parentDirectory.asString, + "-framework", "ProjectDescription", + path.asString, "--dump").chuzzle() if jsonString == nil { throw GraphManifestLoaderError.unexpectedOutput(path) } diff --git a/App/xcbuddykit/Sources/Loader/GraphNode.swift b/App/xcbuddykit/Sources/Loader/GraphNode.swift index 01a3f3a04..58032b6d2 100644 --- a/App/xcbuddykit/Sources/Loader/GraphNode.swift +++ b/App/xcbuddykit/Sources/Loader/GraphNode.swift @@ -138,7 +138,7 @@ class PrecompiledNode: GraphNode { /// - armv7: armv7 (OS device) /// - armv7s: armv7s (OS device) enum Architecture: String { - case x86_64 + case x8664 = "x86_64" case i386 case armv7 case armv7s diff --git a/App/xcbuddykit/Sources/Updater/SPUStandardUpdaterController+App.swift b/App/xcbuddykit/Sources/Updater/SPUStandardUpdaterController+App.swift index 410b48d49..285fb2cd8 100644 --- a/App/xcbuddykit/Sources/Updater/SPUStandardUpdaterController+App.swift +++ b/App/xcbuddykit/Sources/Updater/SPUStandardUpdaterController+App.swift @@ -1,7 +1,7 @@ import Foundation import Sparkle -fileprivate var _app: SPUStandardUpdaterController! +private var _app: SPUStandardUpdaterController! // MARK: - SPUStandardUpdaterController (App) diff --git a/App/xcbuddykit/Sources/Updater/SPUUpdater+CommandLine.swift b/App/xcbuddykit/Sources/Updater/SPUUpdater+CommandLine.swift index d5ca3db90..ddad96686 100644 --- a/App/xcbuddykit/Sources/Updater/SPUUpdater+CommandLine.swift +++ b/App/xcbuddykit/Sources/Updater/SPUUpdater+CommandLine.swift @@ -54,7 +54,9 @@ class SPUCommandLineUserDriver: NSObject, SPUUserDriver { } } - func showInformationalUpdateFound(with appcastItem: SUAppcastItem, userInitiated _: Bool, reply: @escaping (SPUInformationalUpdateAlertChoice) -> Void) { + func showInformationalUpdateFound(with appcastItem: SUAppcastItem, + userInitiated _: Bool, + reply: @escaping (SPUInformationalUpdateAlertChoice) -> Void) { DispatchQueue.main.async { print("Found information for new update: %s", appcastItem.infoURL.absoluteString.utf8) reply(.dismissInformationalNoticeChoice) diff --git a/App/xcbuddykit/Sources/Utils/Bundles.swift b/App/xcbuddykit/Sources/Utils/Bundles.swift index e6354922d..3e2003862 100644 --- a/App/xcbuddykit/Sources/Utils/Bundles.swift +++ b/App/xcbuddykit/Sources/Utils/Bundles.swift @@ -1,7 +1,7 @@ import Basic import Foundation -fileprivate class Dummy {} +private class Dummy {} enum BundleError: Error { case frameworkNotEmbedded(AbsolutePath) diff --git a/App/xcbuddykit/Sources/Utils/ErrorHandler.swift b/App/xcbuddykit/Sources/Utils/ErrorHandler.swift index d0420c8bb..cd853e823 100644 --- a/App/xcbuddykit/Sources/Utils/ErrorHandler.swift +++ b/App/xcbuddykit/Sources/Utils/ErrorHandler.swift @@ -57,8 +57,10 @@ final class ErrorHandler: ErrorHandling { /// - Parameter printer: printer. init(printer: Printing = Printer()) { if let sentryDsn = Bundle(for: ErrorHandler.self).infoDictionary?["SENTRY_DSN"] as? String, !sentryDsn.isEmpty { + // swiftlint:disable force_try client = try! Client(dsn: sentryDsn) try! client?.startCrashHandler() + // swiftlint:enable force_try } else { client = nil } diff --git a/App/xcbuddykit/Sources/Utils/Printer.swift b/App/xcbuddykit/Sources/Utils/Printer.swift index 0e877fc18..8d48883d3 100644 --- a/App/xcbuddykit/Sources/Utils/Printer.swift +++ b/App/xcbuddykit/Sources/Utils/Printer.swift @@ -26,7 +26,9 @@ protocol Printing: AnyObject { /// Default printer that conforms the printing protocol. class Printer: Printing { + // swiftlint:disable force_cast let terminalController: TerminalController = TerminalController(stream: stdoutStream as! LocalFileOutputByteStream)! + // swiftlint:enable force_cast /// Prints a message on the console. /// diff --git a/App/xcbuddykit/Tests/Loader/GraphNodeTests.swift b/App/xcbuddykit/Tests/Loader/GraphNodeTests.swift index fcf00d5df..7a4ea5c43 100644 --- a/App/xcbuddykit/Tests/Loader/GraphNodeTests.swift +++ b/App/xcbuddykit/Tests/Loader/GraphNodeTests.swift @@ -12,7 +12,7 @@ final class PrecompiledNodeTests: XCTestCase { } func test_architecture_rawValues() { - XCTAssertEqual(PrecompiledNode.Architecture.x86_64.rawValue, "x86_64") + XCTAssertEqual(PrecompiledNode.Architecture.x8664.rawValue, "x86_64") XCTAssertEqual(PrecompiledNode.Architecture.i386.rawValue, "i386") XCTAssertEqual(PrecompiledNode.Architecture.armv7.rawValue, "armv7") XCTAssertEqual(PrecompiledNode.Architecture.armv7s.rawValue, "armv7s") @@ -42,7 +42,7 @@ final class FrameworkNodeTests: XCTestCase { } return "" } - try XCTAssertEqual(subject.architectures(shell: shell).first, .x86_64) + try XCTAssertEqual(subject.architectures(shell: shell).first, .x8664) } func test_linking() { @@ -79,7 +79,7 @@ final class LibraryNodeTests: XCTestCase { } return "" } - try XCTAssertEqual(subject.architectures(shell: shell).first, .x86_64) + try XCTAssertEqual(subject.architectures(shell: shell).first, .x8664) } func test_linking() { diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b562eee..45a993467 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/ * Base context https://github.com/xcbuddy/xcbuddy/pull/17/files by @pepibumur. * Add `ResourceLocator` https://github.com/xcbuddy/xcbuddy/pull/18 by @pepibumur. * Add `ErrorHandler` https://github.com/xcbuddy/xcbuddy/pull/20 by @pepibumur. +* Add Danger https://github.com/xcbuddy/xcbuddy/pull/21 by @pepibumur. ### Changed diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 000000000..93a4d5341 --- /dev/null +++ b/Dangerfile @@ -0,0 +1,2 @@ +# Swift lint +swiftlint.lint_files diff --git a/Gemfile b/Gemfile index 30bba7db0..1d2b83c9e 100644 --- a/Gemfile +++ b/Gemfile @@ -13,3 +13,5 @@ gem 'rake' gem 'rubocop' gem 'semantic' gem 'sparklecast' +gem 'danger' +gem 'danger-swiftlint' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 998de773e..8e49954fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,6 +13,10 @@ GEM atomos (0.1.2) byebug (10.0.1) claide (1.0.2) + claide-plugins (0.9.2) + cork + nap + open4 (~> 1.3) cocoapods (1.4.0) activesupport (>= 4.0.2, < 5) claide (>= 1.0.2, < 2.0) @@ -48,10 +52,30 @@ GEM cocoapods-try (1.1.0) colored2 (3.1.2) concurrent-ruby (1.0.5) + cork (0.3.0) + colored2 (~> 3.1) + danger (5.5.12) + claide (~> 1.0) + claide-plugins (>= 0.9.2) + colored2 (~> 3.1) + cork (~> 0.1) + faraday (~> 0.9) + faraday-http-cache (~> 1.0) + git (~> 1) + kramdown (~> 1.5) + no_proxy_fix + octokit (~> 4.7) + terminal-table (~> 1) + danger-swiftlint (0.16.0) + danger + rake (> 10) + thor (~> 0.19) dotenv (2.2.1) escape (0.0.4) faraday (0.14.0) multipart-post (>= 1.2, < 3) + faraday-http-cache (1.3.1) + faraday (~> 0.8) ffi (1.9.23) fourflusher (2.0.1) fuzzy_match (2.0.4) @@ -68,6 +92,7 @@ GEM sass (~> 3.4) sqlite3 (~> 1.3) xcinvoke (~> 0.3.0) + kramdown (1.16.2) liferaft (0.0.6) mini_portile2 (2.3.0) minitest (5.11.3) @@ -77,6 +102,7 @@ GEM nanaimo (0.2.3) nap (1.1.0) netrc (0.11.0) + no_proxy_fix (0.1.2) nokogiri (1.8.2) mini_portile2 (~> 2.3.0) octokit (4.8.0) @@ -115,6 +141,9 @@ GEM sparklecast (0.0.1) nokogiri sqlite3 (1.3.13) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thor (0.20.0) thread_safe (0.3.6) tzinfo (1.2.5) thread_safe (~> 0.1) @@ -133,6 +162,8 @@ PLATFORMS DEPENDENCIES byebug + danger + danger-swiftlint dotenv git jazzy