Agent skills for iOS, iPadOS, Swift, SwiftUI, and modern Apple framework development.
71
89%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Advisory
Suggest reviewing before use
Guidance on SwiftLint rule categories, inline suppression syntax, baseline workflows, and false-positive handling.
SwiftLint rules fall into three categories:
Enabled automatically. These cover widely agreed-upon conventions (e.g., line_length, force_cast, trailing_semicolon). Disable specific ones via disabled_rules in .swiftlint.yml.
Disabled by default because they are more opinionated or may not suit every project. Enable selectively via opt_in_rules:
opt_in_rules:
- empty_count
- closure_spacing
- force_unwrapping
- sorted_imports
- contains_over_filter_count
- first_where
- last_where
- modifier_order
- vertical_whitespace_opening_braces
- explicit_init
- joined_default_parameter
- redundant_nil_coalescing
- private_swiftui_state
- unhandled_throwing_task
- accessibility_label_for_image
- accessibility_trait_for_buttonRequire the Swift compiler's AST information. Must be run via swiftlint analyze with compiler logs. See the custom rules and analyze reference linked from SKILL.md.
analyzer_rules:
- unused_import
- unused_declarationList all rules and their status:
swiftlint rules # all rules with enabled/disabled/correctable status
swiftlint rules --enabled # only currently enabled rules
swiftlint rules --disabled # only currently disabled rules
swiftlint rules <rule_identifier> # detailed info for one ruleThe official rule directory provides descriptions, configuration options, and examples for every rule.
Do not memorize or transcribe the rule directory. Look up specific rules when needed.
An agent writing or reviewing Swift code should understand what these frequently triggered rules enforce. Each rule can be configured in .swiftlint.yml using the rule identifier as a key.
| Rule | What it enforces | Key config options |
|---|---|---|
line_length | Max characters per line | warning, error, ignores_urls, ignores_comments, ignores_interpolated_strings |
file_length | Max lines per file | warning, error, ignore_comment_only_lines |
type_body_length | Max lines in a type body | warning, error |
function_body_length | Max lines in a function body | warning, error |
function_parameter_count | Max parameters per function | warning, error, ignores_default_parameters |
cyclomatic_complexity | Max branching complexity | warning, error, ignores_case_statements |
nesting | Max nesting depth | type_level, function_level |
blanket_disable_command | Prevents swiftlint:disable from disabling rules for the rest of the file | allowed_rules, always_blanket_disable |
identifier_name | Naming length and conventions | min_length, max_length, excluded (list of allowed short names like id, x, i) |
type_name | Type naming length and conventions | min_length, max_length, excluded |
large_tuple | Max tuple size | warning, error |
force_cast | Flags as! | severity only |
force_try | Flags try! | severity only |
todo | Flags // TODO: and // FIXME: | severity only |
trailing_whitespace | Trailing spaces on lines | ignores_empty_lines, ignores_comments |
trailing_comma | Trailing commas in collections | mandatory_comma (when true, requires trailing commas) |
vertical_whitespace | Max consecutive blank lines | max_empty_lines |
opening_brace | Brace placement ({ on same line) | allow_multiline_func |
colon | Spacing around colons | flexible_right_spacing, apply_to_dictionaries |
deployment_target | Flags @available / #available checks that use versions already satisfied by the deployment target | iOS_deployment_target, macOS_deployment_target, etc. |
| Rule | What it enforces | Why enable it |
|---|---|---|
force_unwrapping | Flags ! unwraps | Catches crashes; relax in tests via child config |
private_swiftui_state | @State, @StateObject, @FocusState must be private | Prevents accidental external mutation of view state |
unhandled_throwing_task | Task { try ... } without do/catch | Silently swallowed errors in async contexts |
sorted_imports | Import statements in alphabetical order | Reduces merge conflicts; auto-correctable |
modifier_order | Consistent declaration modifier ordering | Readability; auto-correctable |
accessibility_label_for_image | Images must have accessibility labels | Accessibility compliance |
accessibility_trait_for_button | Buttons must have accessibility traits | Accessibility compliance |
empty_count | Use .isEmpty instead of .count == 0 | Performance and clarity |
closure_spacing | Spaces inside closure braces | Formatting consistency |
contains_over_filter_count | .contains instead of .filter { }.count | Performance |
first_where / last_where | .first(where:) instead of .filter { }.first | Performance |
redundant_nil_coalescing | Flags x ?? nil | Dead code |
implicit_return | Single-expression returns don't need return | Modern Swift style |
self_binding | Consistent guard let self naming | Configurable: bind_identifier |
shorthand_optional_binding | if let x instead of if let x = x | Swift 5.7+ style |
expiring_todo | TODOs/FIXMEs with dates become warnings or errors after expiry | Project hygiene with configurable thresholds and severities |
| Rule | What it enforces |
|---|---|
unused_import | Flags unnecessary import statements; auto-correctable |
unused_declaration | Flags private declarations never referenced |
capture_variable | Flags mutable variables captured by closures |
explicit_self | Requires self. for instance members |
typesafe_array_init | Flags Array(x.map { ... }) → use x.map { ... } directly |
Every rule that accepts configuration uses its identifier as the YAML key:
# Threshold-based rules use warning/error:
line_length:
warning: 140
error: 200
# Boolean option rules:
trailing_comma:
mandatory_comma: true
# Rules with excluded identifiers:
identifier_name:
excluded:
- id
- x
- y
# Rules with a single severity override:
force_cast: error # shorthand for severity: error
# Deployment target rule:
deployment_target:
iOS_deployment_target: "16.0"Run swiftlint rules <rule_identifier> to see all available configuration keys for any rule.
// swiftlint:disable:next force_cast
let view = object as! UIView
let value = dict["key"]! // swiftlint:disable:this force_unwrapping
// swiftlint:disable:previous large_tuple:next — suppresses on the next line:this — suppresses on the same line:previous — suppresses on the previous line// swiftlint:disable cyclomatic_complexity function_body_length
func complexLegacyFunction() {
// ... long function ...
}
// swiftlint:enable cyclomatic_complexity function_body_lengthMultiple rules can be listed in one directive, separated by spaces.
// swiftlint:disable all
// ... entire block is unlinted ...
// swiftlint:enable allIf you forget // swiftlint:enable all, the rest of the file is unlinted. This is a common mistake.
// swiftlint:disable all unless the block is generated code that cannot be excluded via config.// swiftlint:disable:next force_cast — guaranteed by Interface Builder outlet type
let cell = tableView.dequeueReusableCell(...) as! CustomCelldisable with enable.Baselines record all existing violations so only new violations are reported.
swiftlint --write-baseline .swiftlint.baselineThis creates a JSON file listing every current violation by file, line, and rule. Commit this file to the repository.
swiftlint --baseline .swiftlint.baselineViolations matching the baseline are suppressed. New violations (new files, new lines, new rules) are reported normally.
After fixing violations, regenerate:
swiftlint --write-baseline .swiftlint.baselineThe new baseline will be smaller. Commit the update.
swiftlint --strict --baseline .swiftlint.baseline --reporter github-actions-loggingThis fails the build only on new violations not present in the baseline.
| Approach | When to use |
|---|---|
| Baseline | Adopting SwiftLint in a large existing codebase |
| Inline suppression | Specific intentional deviation from a rule |
disabled_rules | Team disagrees with a rule project-wide |
excluded paths | Generated or vendored code |
| Child config | Different rules for test vs production code |
When SwiftLint flags code incorrectly:
line_length for a file with long URLs).Exclude generated code directories in .swiftlint.yml:
excluded:
- "**/Generated"
- "**/Derived"
- "**/*.generated.swift"This is preferable to inline // swiftlint:disable all markers because it keeps generated files completely out of the lint pass.
Tests legitimately use patterns that production code should avoid (force unwraps, long functions, etc.). Use a child .swiftlint.yml in the test directory:
# Tests/.swiftlint.yml
disabled_rules:
- force_unwrapping
- force_try
- force_cast
- function_body_length
- type_body_length
- file_lengthThis is better than excluding tests entirely, because tests still benefit from formatting rules, naming conventions, and other applicable checks.
skills
accessorysetupkit
references
activitykit
references
adattributionkit
references
alarmkit
references
app-clips
app-intents
references
app-store-optimization
app-store-review
apple-on-device-ai
appmigrationkit
references
audioaccessorykit
references
authentication
references
avkit
references
background-processing
references
browserenginekit
references
callkit
references
carplay
references
cloudkit
references
contacts-framework
references
core-bluetooth
references
core-data
core-motion
references
core-nfc
references
coreml
references
cryptokit
references
cryptotokenkit
references
debugging-instruments
device-integrity
references
dockkit
references
energykit
references
eventkit
references
financekit
references
focus-engine
gamekit
references
healthkit
references
homekit
references
ios-accessibility
ios-localization
ios-networking
ios-simulator
references
mapkit
metrickit
references
musickit
references
natural-language
references
paperkit
references
passkit
references
pdfkit
references
pencilkit
references
permissionkit
references
photokit
push-notifications
realitykit
references
relevancekit
references
scenekit
references
sensorkit
references
speech-recognition
spritekit
references
storekit
swift-api-design-guidelines
swift-architecture
swift-charts
references
swift-codable
swift-concurrency
swift-formatstyle
swift-language
swift-security
references
swift-testing
swiftdata
swiftlint
swiftui-animation
swiftui-gestures
references
swiftui-layout-components
swiftui-liquid-glass
references
swiftui-patterns
swiftui-performance
swiftui-uikit-interop
swiftui-webkit
tabletopkit
references
tipkit
references
vision-framework
weatherkit
references
widgetkit
references