- SwiftLint is a linting tool for Swift that runs static analysis and identifies style and potential logic issues.
- It can be installed with Homebrew and configured using a .swiflint.yml file to set which rules to enable/disable and rule parameters.
- Rules check things like force casts, line lengths, naming conventions, and more. Many rules support auto-correction to fix issues automatically.
- The tool continues to be actively developed with new rules and improvements over time. Contributions are welcome to add new rules, improve performance, or fix bugs.
18. .swi%lint.yml
disabled_rules: # rule identifiers to exclude from running
- colon
- comma
- control_statement
enabled_rules: # some rules are only opt-in
- empty_count
- missing_docs
# Find all the available rules by running:
# swiftlint rules
included: # paths to include during linting. `--path` is ignored if present.
- Source
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods
- Source/ExcludedFolder
- Source/ExcludedFile.swift
19. .swi%lint.yml
# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 110
# they can set both implicitly with an array
type_body_length:
- 300 # warning
- 400 # error
# or they can set both explicitly
file_length:
warning: 500
error: 1200
20. .swi%lint.yml
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
min_length: 4 # only warning
max_length: # warning and error
warning: 40
error: 50
excluded: iPhone # excluded via string
variable_name:
min_length: # only min_length
error: 4 # only error
excluded: # excluded via string array
- id
- URL
- GlobalAPIKey
reporter: "csv" # reporter type (xcode, json, csv, checkstyle)