Skip to content

Commit

Permalink
style: add more linting rules and SwiftLint plugin setup
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime committed Jan 30, 2025
1 parent 47cf28b commit 1bb1e2c
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 26 deletions.
83 changes: 78 additions & 5 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,83 @@ included:
- Dangerfile.swift

# Rules
identifier_name:
excluded:
- or
- op
- id
disabled_rules:
- trailing_comma # Conflicts with swift-format's multiElementCollectionTrailingCommas
- force_cast # Handled by swift-format's NeverForceUnwrap
- force_try # Handled by swift-format's NeverUseForceTry
- force_unwrapping # Handled by swift-format's NeverForceUnwrap
- file_header

opt_in_rules:
- array_init
- closure_body_length
- closure_end_indentation
- closure_spacing
- collection_alignment
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- discouraged_object_literal
- empty_collection_literal # Matches swift-format's AlwaysUseLiteralForEmptyCollectionInit
- empty_count
- empty_string
- enum_case_associated_values_count
- explicit_init
- fallthrough # Matches swift-format's NoCasesWithOnlyFallthrough
- fatal_error_message
- first_where
- flatmap_over_map_reduce
- identical_operands
- implicit_return # Matches swift-format's OmitExplicitReturns
- implicitly_unwrapped_optional # Matches swift-format's NeverUseImplicitlyUnwrappedOptionals
- joined_default_parameter
- last_where
- legacy_multiple
- legacy_random
- literal_expression_end_indentation
- lower_acl_than_parent
- modifier_order
- multiline_arguments
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
- operator_usage_whitespace
- optional_enum_case_matching
- overridden_super_call
- pattern_matching_keywords
- prefer_self_type_over_type_of_self
- private_action
- private_outlet
- prohibited_super_call
- reduce_into
- redundant_nil_coalescing
- redundant_type_annotation
- sorted_first_last
- static_operator
- strong_iboutlet
- toggle_bool
- trailing_closure
- type_contents_order
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- xct_specific_matcher
- yoda_condition

analyzer_rules:
- capture_variable
- explicit_self
- unused_declaration
- unused_import

line_length: 150
nesting:
type_level:
warning: 3
error: 5
function_level:
warning: 3
error: 5
2 changes: 1 addition & 1 deletion Dangerfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let sourceChanges = allSourceFiles.contains { $0.hasPrefix("Source") }

// Ensure no copyright header
let swiftFilesWithCopyright = allSourceFiles.filter {
$0.contains("Copyright") && ($0.fileType == .swift || $0.fileType == .m)
$0.contains("Copyright") && ($0.fileType == .swift || $0.fileType == .m)
}
for file in swiftFilesWithCopyright {
danger.fail(message: "Please remove this copyright header", file: file, line: 0)
Expand Down
24 changes: 11 additions & 13 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"object": {
"pins": [
{
"package": "XMLCoder",
"repositoryURL": "https://github.com/MaxDesiatov/XMLCoder",
"state": {
"branch": null,
"revision": "b1e944cbd0ef33787b13f639a5418d55b3bed501",
"version": "0.17.1"
}
"pins" : [
{
"identity" : "xmlcoder",
"kind" : "remoteSourceControl",
"location" : "https://github.com/MaxDesiatov/XMLCoder",
"state" : {
"revision" : "b1e944cbd0ef33787b13f639a5418d55b3bed501",
"version" : "0.17.1"
}
]
},
"version": 1
}
],
"version" : 2
}
32 changes: 25 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,46 @@ import PackageDescription
let package = Package(
name: "Postie",
platforms: [
.macOS(.v10_15), .iOS(.v13)
//lint .macOS(.v12),
.macOS(.v10_15),
.iOS(.v13)
],
products: [
.library(name: "Postie", targets: ["Postie"]),
.library(name: "PostieMock", targets: ["PostieMock"])
],
dependencies: [
.package(url: "https://github.com/MaxDesiatov/XMLCoder", .upToNextMajor(from: "0.17.1"))
.package(url: "https://github.com/MaxDesiatov/XMLCoder", .upToNextMajor(from: "0.17.1")),
//lint .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", .upToNextMajor(from: "0.58.2"))
],
targets: [
.target(name: "Postie", dependencies: [
"URLEncodedFormCoding",
"PostieUtils",
"XMLCoder"
], plugins: [
//lint .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
]),
//dev .testTarget(name: "PostieTests", dependencies: ["Postie", "PostieMock"]),
//dev .testTarget(name: "PostieTests", dependencies: [
//dev "Postie",
//dev "PostieMock"
//dev ], plugins: [
//dev //lint .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
//dev ]),

.target(name: "PostieMock", dependencies: ["Postie"]),
.target(name: "PostieMock", dependencies: ["Postie"], plugins: [
//lint .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
]),

.target(name: "URLEncodedFormCoding", dependencies: ["PostieUtils"]),
.target(name: "URLEncodedFormCoding", dependencies: ["PostieUtils"], plugins: [
//lint .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
]),

.target(name: "PostieUtils"),
//dev .testTarget(name: "PostieUtilsTests", dependencies: ["PostieUtils"]),
.target(name: "PostieUtils", plugins: [
//lint .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
]),
//dev .testTarget(name: "PostieUtilsTests", dependencies: ["PostieUtils"], plugins: [
//dev //lint .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
//dev ]),
]
)

0 comments on commit 1bb1e2c

Please sign in to comment.