Skip to content

Commit db365f3

Browse files
committed
Fix linter
1 parent 0c6c13a commit db365f3

File tree

5 files changed

+181
-4
lines changed

5 files changed

+181
-4
lines changed

.swiftlint.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
line_length:
2+
warning: 150
3+
error: 150
4+
ignores_comments: true
5+
file_length:
6+
warning: 500
7+
error: 1000
8+
type_body_length:
9+
warning: 300
10+
error: 350
11+
nesting:
12+
type_level: 6
13+
generic_type_name:
14+
max_length: 30
15+
identifier_name:
16+
min_length:
17+
error: 3
18+
max_length:
19+
warning: 100
20+
error: 100
21+
excluded:
22+
- id
23+
- fn
24+
- v1
25+
- v2
26+
- io
27+
type_name:
28+
min_length:
29+
warning: 2
30+
error: 1
31+
excluded:
32+
- Id
33+
- V1
34+
- V2
35+
cyclomatic_complexity:
36+
warning: 12
37+
error: 14
38+
disabled_rules:
39+
- function_parameter_count
40+
- large_tuple
41+
- multiple_closures_with_trailing_closure
42+
excluded:
43+
- .build
44+
- DerivedData
45+
opt_in_rules: # some rules are only opt-in
46+
- array_init
47+
- closure_end_indentation
48+
- closure_spacing
49+
- collection_alignment
50+
- contains_over_first_not_nil
51+
- convenience_type
52+
- discouraged_optional_boolean
53+
- discouraged_optional_collection
54+
- empty_count
55+
- empty_string
56+
- empty_xctest_method
57+
- explicit_init
58+
- fallthrough
59+
- fatal_error_message
60+
# - file_types_order
61+
- first_where
62+
- identical_operands
63+
- implicit_return
64+
- joined_default_parameter
65+
- last_where
66+
- legacy_random
67+
- literal_expression_end_indentation
68+
- lower_acl_than_parent
69+
# - missing_docs
70+
- modifier_order
71+
- multiline_arguments
72+
- multiline_literal_brackets
73+
- multiline_parameters
74+
- no_extension_access_modifier
75+
- nslocalizedstring_key
76+
- number_separator
77+
- object_literal
78+
- operator_usage_whitespace
79+
- overridden_super_call
80+
- override_in_extension
81+
- pattern_matching_keywords
82+
- private_action
83+
- private_outlet
84+
- prohibited_interface_builder
85+
# - reduce_into
86+
- redundant_nil_coalescing
87+
- redundant_type_annotation
88+
- sorted_first_last
89+
- sorted_imports
90+
- strong_iboutlet
91+
- toggle_bool
92+
# - type_contents_order
93+
- unavailable_function
94+
- unneeded_parentheses_in_closure_argument
95+
- unused_import
96+
- vertical_parameter_alignment_on_call
97+
- vertical_whitespace_closing_braces
98+
- vertical_whitespace_opening_braces
99+
- xct_specific_matcher
100+
- yoda_condition
101+
custom_rules:
102+
double_space: # from https://github.com/IBM-Swift/Package-Builder
103+
include: "*.swift"
104+
name: "Double space"
105+
regex: '([a-z,A-Z] \s+)'
106+
message: "Double space between keywords"
107+
match_kinds: keyword
108+
severity: warning
109+
comments_space: # from https://github.com/brandenr/swiftlintconfig
110+
name: "Space After Comment"
111+
regex: '(^ *//\w+)'
112+
message: "There should be a space after //"
113+
severity: warning
114+
unnecessary_type: # from https://github.com/brandenr/swiftlintconfig
115+
name: "Unnecessary Type"
116+
regex: '[ a-zA-Z0-9]*(?:let|var) [ a-zA-Z0-9]*: ([a-zA-Z0-9]*)[ ]*= \1'
117+
message: "Type Definition Not Needed"
118+
severity: error

.swiftpm/xcode/xcshareddata/xcschemes/Reducer.xcscheme

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@
3434
ReferencedContainer = "container:">
3535
</BuildableReference>
3636
</BuildActionEntry>
37+
<BuildActionEntry
38+
buildForTesting = "YES"
39+
buildForRunning = "YES"
40+
buildForProfiling = "YES"
41+
buildForArchiving = "YES"
42+
buildForAnalyzing = "YES">
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "Linter"
46+
BuildableName = "Linter"
47+
BlueprintName = "Linter"
48+
ReferencedContainer = "container:">
49+
</BuildableReference>
50+
</BuildActionEntry>
51+
<BuildActionEntry
52+
buildForTesting = "YES"
53+
buildForRunning = "YES"
54+
buildForProfiling = "YES"
55+
buildForArchiving = "YES"
56+
buildForAnalyzing = "YES">
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "SwiftLintPlugin"
60+
BuildableName = "SwiftLintPlugin"
61+
BlueprintName = "SwiftLintPlugin"
62+
ReferencedContainer = "container:">
63+
</BuildableReference>
64+
</BuildActionEntry>
3765
</BuildActionEntries>
3866
</BuildAction>
3967
<TestAction

Package.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@ let package = Package(
55
name: "Reducer",
66
platforms: [.macOS(.v10_13), .iOS(.v11), .tvOS(.v11), .watchOS(.v4)],
77
products: [
8-
.library(name: "Reducer", targets: ["Reducer"])
8+
.library(name: "Reducer", targets: ["Reducer"]),
9+
// .plugin(name: "Linter", targets: ["SwiftLintPlugin"])
910
],
1011
targets: [
11-
.target(name: "Reducer"),
12-
.testTarget(name: "ReducerTests", dependencies: ["Reducer"])
12+
.target(name: "Reducer"), // dependencies: ["SwiftLintPlugin"]),
13+
.testTarget(name: "ReducerTests", dependencies: ["Reducer"]),
14+
// Please keep it commented out. This should be uncommented only for when developing the library in Xcode
15+
// .binaryTarget(
16+
// name: "SwiftLintBinary",
17+
// url: "https://github.com/realm/SwiftLint/releases/download/0.50.0/SwiftLintBinary-macos.artifactbundle.zip",
18+
// checksum: "fb93e474e5827940985093c9cd437f1a70e511b16d790fe0e4150ab25edefa3b"
19+
// ),
20+
// .plugin(
21+
// name: "SwiftLintPlugin",
22+
// capability: .buildTool(),
23+
// dependencies: ["SwiftLintBinary"]
24+
// )
1325
],
1426
swiftLanguageVersions: [.v5]
1527
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import PackagePlugin
2+
3+
@main
4+
struct SwiftLintPlugins: BuildToolPlugin {
5+
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
6+
[
7+
.buildCommand(
8+
displayName: "Linting \(target.name)...",
9+
executable: try context.tool(named: "swiftlint").path,
10+
arguments: [
11+
"lint",
12+
"--config",
13+
"\(context.package.directory.string)/.swiftlint.yml"
14+
],
15+
environment: [:]
16+
)
17+
]
18+
}
19+
}

Tests/ReducerTests/ReducerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
@testable import Reducer
33
import XCTest
44

5-
// swiftlint:disable:next
5+
// swiftlint:disable:next type_body_length
66
class ReducerTests: XCTestCase {
77
func testAnyReducer() {
88
// Given

0 commit comments

Comments
 (0)