Skip to content

Commit 157bae8

Browse files
authored
Merge pull request #61 from ra1028/swiftlint
Add SwiftLint config and run before compiling
2 parents 14c8424 + 39818d0 commit 157bae8

9 files changed

Lines changed: 71 additions & 12 deletions

File tree

.hound.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
swiftlint:
2+
config_file: .swiftlint.yml

.swiftlint.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# https://github.com/realm/SwiftLint
2+
3+
excluded:
4+
- Tests/XCTestManifests.swift
5+
6+
disabled_rules:
7+
- type_name
8+
- identifier_name
9+
- force_cast
10+
- xctfail_message
11+
- function_body_length
12+
- file_length
13+
14+
nesting:
15+
type_level:
16+
warning: 2
17+
18+
line_length:
19+
warning: 200
20+
21+
type_body_length:
22+
warning: 400
23+
24+
function_parameter_count:
25+
warning: 8
26+
27+
cyclomatic_complexity:
28+
warning: 12
29+
30+
statement_position:
31+
statement_mode: uncuddled_else

DifferenceKit.xcodeproj/project.pbxproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
6B2DF86A210E2C12004D2D40 /* Frameworks */,
180180
6B2DF86B210E2C12004D2D40 /* Headers */,
181181
6B2DF86C210E2C12004D2D40 /* Resources */,
182+
6B7EEDA4224E5A5000060872 /* SwiftLint */,
182183
);
183184
buildRules = (
184185
);
@@ -263,6 +264,27 @@
263264
};
264265
/* End PBXResourcesBuildPhase section */
265266

267+
/* Begin PBXShellScriptBuildPhase section */
268+
6B7EEDA4224E5A5000060872 /* SwiftLint */ = {
269+
isa = PBXShellScriptBuildPhase;
270+
buildActionMask = 2147483647;
271+
files = (
272+
);
273+
inputFileListPaths = (
274+
);
275+
inputPaths = (
276+
);
277+
name = SwiftLint;
278+
outputFileListPaths = (
279+
);
280+
outputPaths = (
281+
);
282+
runOnlyForDeploymentPostprocessing = 0;
283+
shellPath = /bin/sh;
284+
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
285+
};
286+
/* End PBXShellScriptBuildPhase section */
287+
266288
/* Begin PBXSourcesBuildPhase section */
267289
6B2DF869210E2C12004D2D40 /* Sources */ = {
268290
isa = PBXSourcesBuildPhase;

Examples/Example-macOS/Sources/ShuffleEmoticonViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import DifferenceKit
44
final class ShuffleEmoticonViewController: NSViewController {
55
@IBOutlet private weak var collectionView: NSCollectionView!
66
@IBOutlet private weak var tableView: NSTableView!
7-
7+
88
private var data = (0x1F600...0x1F647).compactMap { UnicodeScalar($0).map(String.init) }
99
private var dataInput: [String] {
1010
get { return data }
@@ -22,7 +22,7 @@ final class ShuffleEmoticonViewController: NSViewController {
2222
@IBAction func shufflePress(_ button: NSButton) {
2323
dataInput.shuffle()
2424
}
25-
25+
2626
override func awakeFromNib() {
2727
super.awakeFromNib()
2828

@@ -34,11 +34,11 @@ extension ShuffleEmoticonViewController: NSCollectionViewDataSource {
3434
func numberOfSections(in collectionView: NSCollectionView) -> Int {
3535
return 1
3636
}
37-
37+
3838
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
3939
return data.count
4040
}
41-
41+
4242
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
4343
let item = collectionView.makeItem(withIdentifier: EmoticonCollectionViewItem.itemIdentifier, for: indexPath) as! EmoticonCollectionViewItem
4444
item.emoticon = data[indexPath.item]
@@ -50,7 +50,7 @@ extension ShuffleEmoticonViewController: NSTableViewDataSource, NSTableViewDeleg
5050
func numberOfRows(in tableView: NSTableView) -> Int {
5151
return data.count
5252
}
53-
53+
5454
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
5555
let view = tableView.makeView(withIdentifier: NSTableCellView.itemIdentifier, owner: tableView) as! NSTableCellView
5656
view.textField?.stringValue = data[row]

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ let package = Package(
1919
path: "Tests"
2020
)
2121
]
22-
)
22+
)

Sources/Algorithm.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// swiftlint:disable cyclomatic_complexity
2+
13
public extension StagedChangeset where Collection: RangeReplaceableCollection, Collection.Element: Differentiable {
24
/// Creates a new `StagedChangeset` from the two collections.
35
///

Sources/Extensions/UIKitExtension.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public extension UITableView {
115115
private func _performBatchUpdates(_ updates: () -> Void) {
116116
if #available(iOS 11.0, tvOS 11.0, *) {
117117
performBatchUpdates(updates)
118-
} else {
118+
}
119+
else {
119120
beginUpdates()
120121
updates()
121122
endUpdates()

Tests/AlgorithmTest.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ extension AlgorithmTestCase {
188188
M(2, false),
189189
M(4, false),
190190
M(0, true),
191-
M(3, false),
191+
M(3, false)
192192
]
193193

194194
XCTAssertExactDifferences(
@@ -320,7 +320,7 @@ extension AlgorithmTestCase {
320320
let source2 = [ArraySection<D, Int>]()
321321

322322
let target2 = [
323-
ArraySection(model: D.a, elements: [0]),
323+
ArraySection(model: D.a, elements: [0])
324324
]
325325

326326
XCTAssertExactDifferences(
@@ -674,12 +674,12 @@ extension AlgorithmTestCase {
674674
func testComplicated8() {
675675
let source = [
676676
ArraySection(model: M(0, false), elements: [M(0, false), M(1, false)]),
677-
ArraySection(model: M(1, false), elements: [M(2, false), M(3, false)]),
677+
ArraySection(model: M(1, false), elements: [M(2, false), M(3, false)])
678678
]
679679

680680
let target = [
681681
ArraySection(model: M(0, false), elements: []),
682-
ArraySection(model: M(1, false), elements: [M(1, true), M(3, false)]),
682+
ArraySection(model: M(1, false), elements: [M(1, true), M(3, false)])
683683
]
684684

685685
XCTAssertReproducible(source: source, target: target)

Tests/TestTools.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ func XCTAssertReproducible<C: RangeReplaceableCollection & Equatable>(
182182
let targetElementPath: ElementPath
183183
if let movedTargetElementPath = elementMoveMap[sourceElementPath] {
184184
targetElementPath = movedTargetElementPath
185-
} else {
185+
}
186+
else {
186187
let deleteOffset = elementDeletionMap[sourceElementPath.section].count(in: 0..<sourceElementPath.element)
187188
let insertOffset = elementInsertionMap[sourceElementPath.section].count(in: 0...sourceElementPath.element)
188189
targetElementPath = ElementPath(element: sourceElementPath.element - deleteOffset + insertOffset, section: sourceElementPath.section)

0 commit comments

Comments
 (0)