@@ -580,11 +580,11 @@ can be used to update to the current version.
580580SwiftLint can be configured using `entry` to apply fixes and fail on errors :
581581
582582` ` ` yaml
583- - repo: https://github.com/realm/SwiftLint
584- rev: 0.57.1
585- hooks:
586- - id: swiftlint
587- entry: swiftlint --fix --strict
583+ - repo: https://github.com/realm/SwiftLint
584+ rev: 0.57.1
585+ hooks:
586+ - id: swiftlint
587+ entry: swiftlint --fix --strict
588588` ` `
589589
590590# # Rules
@@ -629,9 +629,9 @@ For example:
629629
630630` ` ` swift
631631// swiftlint:disable colon
632- let noWarning :String = "" // No warning about colons immediately after variable names!
632+ let noWarning :String = "" // No warning about colons immediately after variable names.
633633// swiftlint:enable colon
634- let hasWarning :String = "" // Warning generated about colons immediately after variable names
634+ let hasWarning :String = "" // Warning generated about colons immediately after variable names.
635635` ` `
636636
637637Including the `all` keyword will disable all rules until the linter sees a
@@ -644,11 +644,11 @@ For example:
644644
645645` ` ` swift
646646// swiftlint:disable all
647- let noWarning :String = "" // No warning about colons immediately after variable names!
648- let i = "" // Also no warning about short identifier names
647+ let noWarning :String = "" // No warning about colons immediately after variable names.
648+ let i = "" // Also no warning about short identifier names.
649649// swiftlint:enable all
650- let hasWarning :String = "" // Warning generated about colons immediately after variable names
651- let y = "" // Warning generated about short identifier names
650+ let hasWarning :String = "" // Warning generated about colons immediately after variable names.
651+ let y = "" // Warning generated about short identifier names.
652652` ` `
653653
654654It's also possible to modify a `disable` or `enable` command by appending
@@ -689,32 +689,41 @@ Rule inclusion:
689689 all analyzer rules, except the ones listed in `disabled_rules`.
690690
691691` ` ` yaml
692- # By default, SwiftLint uses a set of sensible default rules you can adjust:
693- disabled_rules: # rule identifiers turned on by default to exclude from running
692+ # By default, SwiftLint uses a set of sensible default rules you can adjust. Find all the available rules
693+ # by running ` swiftlint rules` or visiting https://realm.github.io/SwiftLint/rule-directory.html.
694+
695+ # Rules turned on by default can be disabled.
696+ disabled_rules :
694697 - colon
695698 - comma
696699 - control_statement
697- opt_in_rules: # some rules are turned off by default, so you need to opt-in
698- - empty_count # find all the available rules by running: ` swiftlint rules`
700+
701+ # Rules turned off by default can be enabled.
702+ opt_in_rules :
703+ - empty_count
699704
700- # Alternatively, specify all rules explicitly by uncommenting this option:
701- # only_rules: # delete `disabled_rules` & `opt_in_rules` if using this
705+ # Alternatively, specify all rules explicitly by uncommenting this option and removing the above two.
706+ # only_rules:
702707# - empty_parameters
703708# - vertical_whitespace
704709
705- analyzer_rules : # rules run by `swiftlint analyze`
710+ # Rules only run by `swiftlint analyze`. These are all opt-in.
711+ analyzer_rules :
706712 - explicit_self
707713
708714# Case-sensitive paths to include during linting. Directory paths supplied on the
709- # command line will be ignored.
715+ # command line will be ignored. Wildcards are supported.
710716included :
711717 - Sources
712- excluded : # case-sensitive paths to ignore during linting. Takes precedence over `included`
718+
719+ # Case-sensitive paths to ignore during linting. Takes precedence over `included`. Wildcards
720+ # are supported.
721+ excluded :
713722 - Carthage
714723 - Pods
715724 - Sources/ExcludedFolder
716725 - Sources/ExcludedFile.swift
717- - Sources/*/ExcludedFile.swift # exclude files with a wildcard
726+ - Sources/*/ExcludedFile.swift
718727
719728# If true, SwiftLint will not fail if no lintable files are found.
720729allow_zero_lintable_files : false
@@ -734,39 +743,45 @@ write_baseline: Baseline.json
734743# If true, SwiftLint will check for updates after linting or analyzing.
735744check_for_updates : true
736745
737- # configurable rules can be customized from this configuration file
738- # binary rules can set their severity level
746+ # Configurable rules can be customized. All rules support setting their severity level.
739747force_cast : warning # implicitly
740748force_try :
741749 severity : warning # explicitly
742- # rules that have both warning and error levels, can set just the warning level
743- # implicitly
750+
751+ # Rules that have both warning and error levels can set just the warning level implicitly.
744752line_length : 110
745- # they can set both implicitly with an array
753+
754+ # To set both levels implicitly, use an array.
746755type_body_length :
747756 - 300 # warning
748757 - 400 # error
749- # or they can set both explicitly
758+
759+ # To set both levels explicitly, use a dictionary.
750760file_length :
751761 warning : 500
752762 error : 1200
753- # naming rules can set warnings/errors for min_length and max_length
754- # additionally they can set excluded names
763+
764+ # Naming rules can set warnings/errors for `min_length` and `max_length`. Additionally, they can
765+ # set excluded names and allowed symbols.
755766type_name :
756- min_length : 4 # only warning
767+ min_length : 4 # warning
757768 max_length : # warning and error
758769 warning : 40
759770 error : 50
760- excluded : iPhone # excluded via string
761- allowed_symbols : ["_"] # these are allowed in type names
771+ excluded : i(Phone|Pad|Pod) # regex pattern
772+ allowed_symbols : ["_"]
762773identifier_name :
763- min_length : # only min_length
774+ min_length :
764775 error : 4 # only error
765776 excluded : # excluded via string array
766777 - id
767778 - URL
768779 - GlobalAPIKey
769- reporter : " xcode" # reporter type (xcode, json, csv, checkstyle, codeclimate, junit, html, emoji, sonarqube, markdown, github-actions-logging, summary)
780+
781+ # The default reporter (SwiftLint's output format) can be configured as `checkstyle`, `codeclimate`, `csv`,
782+ # `emoji`, `github-actions-logging`, `gitlab`, `html`, `json`, `junit`, `markdown`, `relative-path`, `sarif`,
783+ # `sonarqube`, `summary`, or `xcode` (default).
784+ reporter : " xcode"
770785` ` `
771786
772787You can also use environment variables in your configuration file,
@@ -795,21 +810,31 @@ following syntax:
795810
796811` ` ` yaml
797812custom_rules:
798- pirates_beat_ninjas: # rule identifier
813+ # Rule identifier.
814+ pirates_beat_ninjas:
815+ # Optional regex that defines paths to include during linting.
799816 included:
800- - ".*\\ .swift" # regex that defines paths to include during linting. optional.
817+ - ".*\\ .swift"
818+ # Optional regex that defines paths to exclude during linting.
801819 excluded:
802- - ".*Test\\ .swift" # regex that defines paths to exclude during linting. optional
803- name: "Pirates Beat Ninjas" # rule name. optional.
804- regex: "([nN]inja)" # matching pattern
805- capture_group: 0 # number of regex capture group to highlight the rule violation at. optional.
806- match_kinds: # SyntaxKinds to match. optional.
820+ - ".*Test\\ .swift"
821+ # Optional rule name.
822+ name: "Pirates Beat Ninjas"
823+ # Matching pattern.
824+ regex: "([nN]inja)"
825+ # Number of regex capture group to highlight the rule violation at. Optional, defaults to 0 (the whole match).
826+ capture_group: 0
827+ # SyntaxKinds to match. optional.
828+ match_kinds:
807829 - comment
808830 - identifier
809- message: "Pirates are better than ninjas." # violation message. optional.
810- severity: error # violation severity. optional.
831+ # Optional violation message.
832+ message: "Pirates are better than ninjas."
833+ # Optional violation severity.
834+ severity: error
811835 no_hiding_in_strings:
812836 regex: "([nN]inja)"
837+ # Syntax kinds to match. optional.
813838 match_kinds: string
814839` ` `
815840
@@ -918,14 +943,14 @@ Team-Wide Configuration:
918943
919944` ` ` yaml
920945disabled_rules:
921- - force_cast
946+ - force_cast
922947` ` `
923948
924949Project-Specific Configuration :
925950
926951` ` ` yaml
927952opt_in_rules:
928- - force_cast
953+ - force_cast
929954` ` `
930955
931956# ## Child/Parent Configs (Locally)
0 commit comments