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

Add Swiftformat #375

Merged
merged 4 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- run:
name: Install Tools
command: |
brew install swiftformat
brew install swiftlint
bundle config build.sqlite3 --with-sqlite3-dir=/opt/local
- run:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
2.6.0
35 changes: 35 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# file options

--symlinks ignore
--exclude Tests/XCTestManifests.swift

# format options

--allman false
--binarygrouping 4,8
--commas always
--comments indent
--decimalgrouping 3,6
--elseposition same-line
--empty void
--exponentcase lowercase
--exponentgrouping disabled
--fractiongrouping disabled
--header ignore
--hexgrouping 4,8
--hexliteralcase uppercase
--ifdef indent
--indent 4
--indentcase false
--importgrouping testable-bottom
--linebreaks lf
--octalgrouping 4,8
--operatorfunc spaced
--patternlet hoist
--ranges spaced
--self remove
--semicolons inline
--stripunusedargs always
--trimwhitespace always
--wraparguments preserve
--wrapcollections preserve
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ identifier_name:
min_length:
error: 1
warning: 1
function_parameter_count:
warning: 7
error: 8
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
## next version

### Fixed
- Improve project encoding performance https://github.com/tuist/xcodeproj/pull/371 by @CognitiveDisson

### Fixed
- Improve project encoding performance https://github.com/tuist/xcodeproj/pull/371 by @CognitiveDisson.
- Project decoding performance issue https://github.com/tuist/xcodeproj/pull/365 by @CognitiveDisson.
- Fix PBXTarget extension methods https://github.com/tuist/xcodeproj/pull/367 by @danilsmakotin.

### Added
- Added `GPUFrameCaptureMode` and `GPUValidationMode` options to `LaunchAction` https://github.com/tuist/xcodeproj/pull/368 by @schiewe.
- Add Swiftformat https://github.com/tuist/xcodeproj/pull/375 by @pepibumur.

### Fixed
- Fix PBXTarget extension methods https://github.com/tuist/xcodeproj/pull/367 by @danilsmakotin
### Changed
- **Breaking** Rename GPUFrameCaptureMode cases to start with a lowercase letter https://github.com/tuist/xcodeproj/pull/375 by @pepibumur.
- Fix linting issues https://github.com/tuist/xcodeproj/pull/375 by @pepibumur.

## 6.5.0

Expand Down
6 changes: 4 additions & 2 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ if !git.modified_files.include?("CHANGELOG.md")
fail(message, sticky: false)
end

# Swiftlint
swiftlint.lint_files
# Linting
swiftformat.additional_args = "--config .swiftformat"
swiftformat.check_format(fail_on_error: true)
swiftlint.lint_files(fail_on_error: true)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testable import WithoutWorkspace
import XCTest
@testable import WithoutWorkspace

class WithoutWorkspaceTests: XCTestCase {
func testExample() {
Expand Down
2 changes: 1 addition & 1 deletion Fixtures/iOS/iOSTests/iOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 es.ppinera. All rights reserved.
//

@testable import iOS
import XCTest
@testable import iOS

class iOSTests: XCTestCase {
override func setUp() {
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ gem "jazzy"
gem "cocoapods", "1.6.0.beta.1"
gem "colorize", "~> 0.8.1"
gem "danger", "~> 5.10"
gem "danger-swiftlint", "~> 0.18.0"
gem "danger-swiftformat", "~> 0.4.0"
gem "danger-swiftlint", "~> 0.19.0"
43 changes: 24 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.0)
activesupport (4.2.10)
activesupport (4.2.11)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
Expand Down Expand Up @@ -38,22 +38,22 @@ GEM
activesupport (>= 4.0.2, < 6)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.2)
cocoapods-downloader (1.2.1)
cocoapods-deintegrate (1.0.3)
cocoapods-downloader (1.2.2)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-stats (1.1.0)
cocoapods-trunk (1.3.1)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.1.0)
colored2 (3.1.2)
colorize (0.8.1)
concurrent-ruby (1.0.5)
concurrent-ruby (1.1.4)
cork (0.3.0)
colored2 (~> 3.1)
danger (5.10.3)
danger (5.15.0)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
Expand All @@ -65,7 +65,11 @@ GEM
no_proxy_fix
octokit (~> 4.7)
terminal-table (~> 1)
danger-swiftlint (0.18.0)
danger-plugin-api (1.0.0)
danger (> 2.0)
danger-swiftformat (0.4.0)
danger-plugin-api (~> 1.0)
danger-swiftlint (0.19.0)
danger
rake (> 10)
thor (~> 0.19)
Expand All @@ -74,14 +78,14 @@ GEM
multipart-post (>= 1.2, < 3)
faraday-http-cache (1.3.1)
faraday (~> 0.8)
ffi (1.9.25)
ffi (1.10.0)
fourflusher (2.0.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
git (1.5.0)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jazzy (0.9.3)
jazzy (0.9.4)
cocoapods (~> 1.0)
mustache (~> 0.99)
open4
Expand All @@ -104,22 +108,22 @@ GEM
sawyer (~> 0.8.0, >= 0.5.3)
open4 (1.3.4)
public_suffix (3.0.3)
rake (12.3.1)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rb-inotify (0.10.0)
ffi (~> 1.0)
redcarpet (3.4.0)
rouge (3.2.0)
ruby-macho (1.3.1)
sass (3.5.7)
rouge (3.3.0)
ruby-macho (1.4.0)
sass (3.7.3)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
sqlite3 (1.3.13)
sqlite3 (1.4.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thor (0.20.3)
Expand All @@ -129,7 +133,7 @@ GEM
unicode-display_width (1.4.1)
xcinvoke (0.3.0)
liferaft (~> 0.0.6)
xcodeproj (1.6.0)
xcodeproj (1.8.1)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
Expand All @@ -143,9 +147,10 @@ DEPENDENCIES
cocoapods (= 1.6.0.beta.1)
colorize (~> 0.8.1)
danger (~> 5.10)
danger-swiftlint (~> 0.18.0)
danger-swiftformat (~> 0.4.0)
danger-swiftlint (~> 0.19.0)
jazzy
rake

BUNDLED WITH
1.16.6
1.17.3
3 changes: 0 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ require 'fileutils'
require 'colorize'

task :release_check do
puts "Linting code".colorize(:cyan)
system("swiftlint") || abort
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to get rid of it since we are running the linter on the PRs before they get merged.


puts "Running tests".colorize(:cyan)
system("swift test") || abort

Expand Down
6 changes: 3 additions & 3 deletions Sources/xcodeproj/Extensions/AEXML+XcodeFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extension AEXMLElement {
xml += "\(key) = \"\(value.xmlEscaped)\""
}

if attributes.count > 0 {
if !attributes.isEmpty {
// insert known attributes in the specified order.
var attributes = self.attributes
for key in attributesOrder[self.name] ?? [] {
Expand All @@ -106,11 +106,11 @@ extension AEXMLElement {
}
}

if value == nil && children.count == 0 {
if value == nil, children.isEmpty {
// close element
xml += ">\n"
} else {
if children.count > 0 {
if !children.isEmpty {
// add children
xml += ">\n"
for child in children {
Expand Down
8 changes: 3 additions & 5 deletions Sources/xcodeproj/Extensions/Dictionary+Enumerate.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import Foundation

extension Dictionary {

func enumerateKeysAndObjects(
options opts: NSEnumerationOptions = [],
using block: (Any, Any, UnsafeMutablePointer<ObjCBool>) throws -> Void) throws
{
using block: (Any, Any, UnsafeMutablePointer<ObjCBool>) throws -> Void
) throws {
var blockError: Error?
// For performance it is very important to create a separate dictionary instance.
// (self as NSDictionary).enumerateKeys... - works much slower
let dictionary = NSDictionary(dictionary: self)
dictionary.enumerateKeysAndObjects(options: opts) { (key, obj, stops) in
dictionary.enumerateKeysAndObjects(options: opts) { key, obj, stops in
do {
try block(key, obj, stops)
} catch {
Expand All @@ -22,5 +21,4 @@ extension Dictionary {
throw error
}
}

}
22 changes: 9 additions & 13 deletions Sources/xcodeproj/Extensions/String+md5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension String {
var md5: String {
if let data = data(using: .utf8, allowLossyConversion: true) {
let message = data.withUnsafeBytes { bytes -> [UInt8] in
return Array(UnsafeBufferPointer(start: bytes, count: data.count))
Array(UnsafeBufferPointer(start: bytes, count: data.count))
}

let MD5Calculator = MD5(message)
Expand Down Expand Up @@ -85,14 +85,14 @@ extension NSMutableData {
}

protocol HashProtocol {
var message: Array<UInt8> { get }
var message: [UInt8] { get }

/** Common part for hash calculation. Prepare header data. */
func prepare(_ len: Int) -> Array<UInt8>
func prepare(_ len: Int) -> [UInt8]
}

extension HashProtocol {
func prepare(_ len: Int) -> Array<UInt8> {
func prepare(_ len: Int) -> [UInt8] {
var tmpMessage = message

// Step 1. Append Padding Bits
Expand All @@ -107,13 +107,13 @@ extension HashProtocol {
msgLength += 1
}

tmpMessage += Array<UInt8>(repeating: 0, count: counter)
tmpMessage += [UInt8](repeating: 0, count: counter)
return tmpMessage
}
}

func toUInt32Array(_ slice: ArraySlice<UInt8>) -> Array<UInt32> {
var result = Array<UInt32>()
func toUInt32Array(_ slice: ArraySlice<UInt8>) -> [UInt32] {
var result = [UInt32]()
result.reserveCapacity(16)

for idx in stride(from: slice.startIndex, to: slice.endIndex, by: MemoryLayout<UInt32>.size) {
Expand Down Expand Up @@ -143,7 +143,7 @@ struct BytesIterator: IteratorProtocol {
let end = min(chunkSize, data.count - offset)
let result = data[offset ..< offset + end]
offset += result.count
return result.count > 0 ? result : nil
return !result.isEmpty ? result : nil
}
}

Expand Down Expand Up @@ -235,26 +235,22 @@ class MD5: HashProtocol {
case 0 ... 15:
F = (B & C) | ((~B) & D)
g = j
break
case 16 ... 31:
F = (D & B) | (~D & C)
g = (5 * j + 1) % 16
break
case 32 ... 47:
F = B ^ C ^ D
g = (3 * j + 5) % 16
break
case 48 ... 63:
F = C ^ (B | (~D))
g = (7 * j) % 16
break
default:
break
}
dTemp = D
D = C
C = B
B = B &+ rotateLeft((A &+ F &+ sines[j] &+ M[g]), bits: shifts[j])
B = B &+ rotateLeft(A &+ F &+ sines[j] &+ M[g], bits: shifts[j])
A = dTemp
}

Expand Down
Loading