I want to use Swiftlint in my Swift project.
I followed the Realm instruction and installed Swiftlint by brew install swiftlint
. Further I face the problem to create .swiftlint.yml
file.
So please suggest me how I proceed?
swiftlint. yml) and runs the tool. It is now located at the root of your project, in the same folder of your project configuration file (. xcodeproj), although it can be anywhere that you like.
swiftlint. yml file to your project directory. Note that this file should be added alongside your Xcode project and your Xcode workspace. It should not be placed inside of your project files directory.
Configuration file You can find all rules by running $ swiftlint rules . You have the possibility to control which rule is disabled/enabled and set thresholds for warnings and errors for a given rule.
If you are using the terminal:
cd your_project_directory touch .swiftlint.yml
I found this video helpful: https://www.youtube.com/watch?v=3MAlqOVIAwI
You can create a .swiftlint.yml in XCode and save it in your project directory. Just select File -> New -> File -> Empty
Create this file in your project main directory and name should .swiftlint.yml
File example
disabled_rules: # rule identifiers to exclude from running
- colon
- comma
- control_statement
- identifier_name #rule for checking variable conditions (Upper case , lower case , underscore )
- force_cast
- shorthand_operator
cyclomatic_complexity:
warning: 25 # two nested ifs are acceptable
error: 50 # six nested ifs shows warning, 6 causes compile error
opt_in_rules: # some rules are only opt-in
# - empty_count
# 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
- AppFolder\ App/Class/*
# - AppFolder\ App/ViewController/* //Enabled for this
analyzer_rules: # Rules run by `swiftlint analyze` (experimental)
- explicit_self
# configurable rules can be customised 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: 200
# they can set both implicitly with an array
type_body_length:
- 300 # warning
- 600 # error
# or they can set both explicitly
file_length:
warning: 500
error: 2500
function_body_length:
- 200 #warning
- 300 #error
# 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
allowed_symbols: ["_"] # these are allowed in type names
identifier_name:
min_length: # only min_length
error: 4 # only error
excluded: # excluded via string array
- id
- URL
- GlobalAPIKey
identifier_name:
# allowed_symbols: "_"
max_length:
warning: 45
error: 60
min_length:
warning: 1
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With