Skip to content

Commit 627e319

Browse files
committed
Adds additional swiftlint rules
1 parent 80dda2d commit 627e319

File tree

8 files changed

+178
-16
lines changed

8 files changed

+178
-16
lines changed

SwiftAlgorithmClub/.swiftlint.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
opt_in_rules:
2+
- array_init
3+
- closure_spacing
4+
- contains_over_filter_count
5+
- contains_over_filter_is_empty
6+
- contains_over_first_not_nil
7+
- discouraged_object_literal
8+
- empty_collection_literal
9+
- empty_count
10+
- empty_string
11+
- explicit_init
12+
- file_header
13+
- first_where
14+
- identical_operands
15+
- implicit_return
16+
- implicitly_unwrapped_optional
17+
- joined_default_parameter
18+
- last_where
19+
- legacy_multiple
20+
- legacy_random
21+
- lower_acl_than_parent
22+
- modifier_order
23+
- multiline_parameters
24+
- nimble_operator
25+
- nslocalizedstring_key
26+
- operator_usage_whitespace
27+
- overridden_super_call
28+
- override_in_extension
29+
- pattern_matching_keywords
30+
- private_action
31+
- private_over_fileprivate
32+
- prohibited_interface_builder
33+
- prohibited_super_call
34+
- quick_discouraged_call
35+
- quick_discouraged_focused_test
36+
- quick_discouraged_pending_test
37+
- redundant_nil_coalescing
38+
- single_test_class
39+
- sorted_first_last
40+
- sorted_imports
41+
- toggle_bool
42+
- trailing_closure
43+
- unneeded_parentheses_in_closure_argument
44+
- unowned_variable_capture
45+
- untyped_error_in_catch
46+
- vertical_parameter_alignment_on_call
47+
- vertical_whitespace_opening_braces
48+
- vertical_whitespace_closing_braces
49+
- yoda_condition
50+
51+
disabled_rules:
52+
- identifier_name
53+
- type_name
54+
- line_length
55+
- force_try
56+
- force_cast
57+
58+
file_length: 450
59+
nesting:
60+
type_level: 3
61+
swiftlint_version: 0.36.0
62+
63+
cyclomatic_complexity:
64+
ignores_case_statements: true
65+
66+
explicit_type_interface:
67+
excluded:
68+
- local
69+
70+
identifier_name:
71+
excluded:
72+
- id
73+
74+
discouraged_object_literal:
75+
color_literal: false
76+
77+
trailing_closure:
78+
only_single_muted_parameter: true
79+
80+
modifier_order:
81+
preferred_modifier_order:
82+
- acl
83+
- setter ACL
84+
- override
85+
- dynamic
86+
- mutators
87+
- lazy
88+
- final
89+
- required
90+
- convenience
91+
- typeMethods
92+
- owned

SwiftAlgorithmClub/AllPairsShortestPaths.playground/Sources/APSP.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Foundation
1313
returns an object conforming to `APSPResult`.
1414
*/
1515
public protocol APSPAlgorithm {
16-
1716
associatedtype Q: Hashable
1817
associatedtype P: APSPResult
1918

SwiftAlgorithmClub/AllPairsShortestPaths.playground/Sources/AdjacencyListGraph.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ open class AdjacencyListGraph<T>: AbstractGraph<T> where T: Hashable {
4343
if let match = vertices.first(where: { $0.data == data }) {
4444
return match
4545
}
46-
46+
4747
// if the vertex doesn't exist, create a new one
4848
let vertex = Vertex(data: data, index: adjacencyList.count)
4949
adjacencyList.append(EdgeList(vertex: vertex))
@@ -71,13 +71,7 @@ open class AdjacencyListGraph<T>: AbstractGraph<T> where T: Hashable {
7171
return nil
7272
}
7373

74-
for edge: Edge<T> in edges {
75-
if edge.to == destinationVertex {
76-
return edge.weight
77-
}
78-
}
79-
80-
return nil
74+
return edges.first { $0.to == destinationVertex }?.weight
8175
}
8276

8377
open override func edgesFrom(_ sourceVertex: Vertex<T>) -> [Edge<T>] {

SwiftAlgorithmClub/AllPairsShortestPaths.playground/Sources/FloydWarshall.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public struct FloydWarshall<T>: APSPAlgorithm where T: Hashable {
5959
shortest paths and the corresponding predecessor matrix
6060
*/
6161
static fileprivate func nextStep<T>(_ intermediateIdx: Int, previousDistances: Distances,
62-
previousPredecessors: Predecessors, graph: AbstractGraph<T>) -> StepResult {
62+
previousPredecessors: Predecessors, graph: AbstractGraph<T>) -> StepResult {
6363

6464
let vertexCount = graph.vertices.count
6565
var nextDistances = Array(repeating: Array(repeating: Double.infinity, count: vertexCount), count: vertexCount)
66-
var nextPredecessors = Array(repeating: Array<Int?>(repeating: nil, count: vertexCount), count: vertexCount)
66+
var nextPredecessors = Array(repeating: [Int?](repeating: nil, count: vertexCount), count: vertexCount)
6767

6868
for fromIdx in 0 ..< vertexCount {
6969
for toIndex in 0 ..< vertexCount {
@@ -127,7 +127,7 @@ public struct FloydWarshall<T>: APSPAlgorithm where T: Hashable {
127127
static fileprivate func constructInitialPredecessorMatrix(_ distances: Distances) -> Predecessors {
128128

129129
let vertexCount = distances.count
130-
var predecessors = Array(repeating: Array<Int?>(repeating: nil, count: vertexCount), count: vertexCount)
130+
var predecessors = Array(repeating: [Int?](repeating: nil, count: vertexCount), count: vertexCount)
131131

132132
for fromIdx in 0 ..< vertexCount {
133133
for toIdx in 0 ..< vertexCount {
@@ -190,7 +190,7 @@ public struct FloydWarshallResult<T>: APSPResult where T: Hashable {
190190
- returns: the list of predecessors discovered so far
191191
*/
192192
fileprivate func recursePathFrom(fromVertex from: Vertex<T>, toVertex to: Vertex<T>, path: [Vertex<T>],
193-
inGraph graph: AbstractGraph<T>) -> [Vertex<T>]? {
193+
inGraph graph: AbstractGraph<T>) -> [Vertex<T>]? {
194194

195195
if from.index == to.index {
196196
return [ from, to ]

SwiftAlgorithmClub/AllPairsShortestPaths.playground/Sources/Graph.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import Foundation
99

10-
open class AbstractGraph<T>: CustomStringConvertible where T: Hashable {
11-
10+
open class AbstractGraph<T: Hashable>: CustomStringConvertible {
1211
public required init() {}
1312

1413
public required init(fromGraph graph: AbstractGraph<T>) {

SwiftAlgorithmClub/Podfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
target 'SwiftAlgorithmClub' do
2+
use_frameworks!
3+
4+
pod 'SwiftLint'
5+
end

SwiftAlgorithmClub/SwiftAlgorithmClub.xcodeproj/project.pbxproj

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
/* Begin PBXBuildFile section */
1010
60908F9123691B81004E53B2 /* SwiftAlgorithmClub.h in Headers */ = {isa = PBXBuildFile; fileRef = 60908F8F23691B81004E53B2 /* SwiftAlgorithmClub.h */; settings = {ATTRIBUTES = (Public, ); }; };
11+
896EC48BF398EBA0498F3F37 /* Pods_SwiftAlgorithmClub.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E71A86B58EDBA0CFCF6ACDC /* Pods_SwiftAlgorithmClub.framework */; };
1112
/* End PBXBuildFile section */
1213

1314
/* Begin PBXFileReference section */
15+
19B6A76A8179150D7F857F86 /* Pods-SwiftAlgorithmClub.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftAlgorithmClub.release.xcconfig"; path = "Target Support Files/Pods-SwiftAlgorithmClub/Pods-SwiftAlgorithmClub.release.xcconfig"; sourceTree = "<group>"; };
16+
1AC49BC223347449D9B873B3 /* Pods-SwiftAlgorithmClub.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftAlgorithmClub.debug.xcconfig"; path = "Target Support Files/Pods-SwiftAlgorithmClub/Pods-SwiftAlgorithmClub.debug.xcconfig"; sourceTree = "<group>"; };
17+
4E71A86B58EDBA0CFCF6ACDC /* Pods_SwiftAlgorithmClub.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SwiftAlgorithmClub.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1418
60908F8C23691B81004E53B2 /* SwiftAlgorithmClub.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftAlgorithmClub.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1519
60908F8F23691B81004E53B2 /* SwiftAlgorithmClub.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftAlgorithmClub.h; sourceTree = "<group>"; };
1620
60908F9023691B81004E53B2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -21,6 +25,7 @@
2125
isa = PBXFrameworksBuildPhase;
2226
buildActionMask = 2147483647;
2327
files = (
28+
896EC48BF398EBA0498F3F37 /* Pods_SwiftAlgorithmClub.framework in Frameworks */,
2429
);
2530
runOnlyForDeploymentPostprocessing = 0;
2631
};
@@ -32,6 +37,8 @@
3237
children = (
3338
60908F8E23691B81004E53B2 /* SwiftAlgorithmClub */,
3439
60908F8D23691B81004E53B2 /* Products */,
40+
BA921E75CF90836A6FFD54BD /* Pods */,
41+
76C74A433C3D40B49A759205 /* Frameworks */,
3542
);
3643
sourceTree = "<group>";
3744
};
@@ -52,6 +59,23 @@
5259
path = SwiftAlgorithmClub;
5360
sourceTree = "<group>";
5461
};
62+
76C74A433C3D40B49A759205 /* Frameworks */ = {
63+
isa = PBXGroup;
64+
children = (
65+
4E71A86B58EDBA0CFCF6ACDC /* Pods_SwiftAlgorithmClub.framework */,
66+
);
67+
name = Frameworks;
68+
sourceTree = "<group>";
69+
};
70+
BA921E75CF90836A6FFD54BD /* Pods */ = {
71+
isa = PBXGroup;
72+
children = (
73+
1AC49BC223347449D9B873B3 /* Pods-SwiftAlgorithmClub.debug.xcconfig */,
74+
19B6A76A8179150D7F857F86 /* Pods-SwiftAlgorithmClub.release.xcconfig */,
75+
);
76+
path = Pods;
77+
sourceTree = "<group>";
78+
};
5579
/* End PBXGroup section */
5680

5781
/* Begin PBXHeadersBuildPhase section */
@@ -70,10 +94,12 @@
7094
isa = PBXNativeTarget;
7195
buildConfigurationList = 60908F9423691B81004E53B2 /* Build configuration list for PBXNativeTarget "SwiftAlgorithmClub" */;
7296
buildPhases = (
97+
5B0CDFC13A7E532D8AD759CD /* [CP] Check Pods Manifest.lock */,
7398
60908F8723691B81004E53B2 /* Headers */,
7499
60908F8823691B81004E53B2 /* Sources */,
75100
60908F8923691B81004E53B2 /* Frameworks */,
76101
60908F8A23691B81004E53B2 /* Resources */,
102+
60B8E3912369304400940496 /* ShellScript */,
77103
);
78104
buildRules = (
79105
);
@@ -126,6 +152,48 @@
126152
};
127153
/* End PBXResourcesBuildPhase section */
128154

155+
/* Begin PBXShellScriptBuildPhase section */
156+
5B0CDFC13A7E532D8AD759CD /* [CP] Check Pods Manifest.lock */ = {
157+
isa = PBXShellScriptBuildPhase;
158+
buildActionMask = 2147483647;
159+
files = (
160+
);
161+
inputFileListPaths = (
162+
);
163+
inputPaths = (
164+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
165+
"${PODS_ROOT}/Manifest.lock",
166+
);
167+
name = "[CP] Check Pods Manifest.lock";
168+
outputFileListPaths = (
169+
);
170+
outputPaths = (
171+
"$(DERIVED_FILE_DIR)/Pods-SwiftAlgorithmClub-checkManifestLockResult.txt",
172+
);
173+
runOnlyForDeploymentPostprocessing = 0;
174+
shellPath = /bin/sh;
175+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
176+
showEnvVarsInLog = 0;
177+
};
178+
60B8E3912369304400940496 /* ShellScript */ = {
179+
isa = PBXShellScriptBuildPhase;
180+
buildActionMask = 2147483647;
181+
files = (
182+
);
183+
inputFileListPaths = (
184+
);
185+
inputPaths = (
186+
);
187+
outputFileListPaths = (
188+
);
189+
outputPaths = (
190+
);
191+
runOnlyForDeploymentPostprocessing = 0;
192+
shellPath = /bin/sh;
193+
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\"${PODS_ROOT}/SwiftLint/swiftlint\"\n";
194+
};
195+
/* End PBXShellScriptBuildPhase section */
196+
129197
/* Begin PBXSourcesBuildPhase section */
130198
60908F8823691B81004E53B2 /* Sources */ = {
131199
isa = PBXSourcesBuildPhase;
@@ -258,6 +326,7 @@
258326
};
259327
60908F9523691B81004E53B2 /* Debug */ = {
260328
isa = XCBuildConfiguration;
329+
baseConfigurationReference = 1AC49BC223347449D9B873B3 /* Pods-SwiftAlgorithmClub.debug.xcconfig */;
261330
buildSettings = {
262331
CODE_SIGN_STYLE = Automatic;
263332
COMBINE_HIDPI_IMAGES = YES;
@@ -282,6 +351,7 @@
282351
};
283352
60908F9623691B81004E53B2 /* Release */ = {
284353
isa = XCBuildConfiguration;
354+
baseConfigurationReference = 19B6A76A8179150D7F857F86 /* Pods-SwiftAlgorithmClub.release.xcconfig */;
285355
buildSettings = {
286356
CODE_SIGN_STYLE = Automatic;
287357
COMBINE_HIDPI_IMAGES = YES;

SwiftAlgorithmClub/SwiftAlgorithmClub.xcworkspace/contents.xcworkspacedata

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)