Skip to main content

SwiftLint

Supported VersionLanguageWebsite
0.43.1Swifthttps://realm.github.io/SwiftLint

SwiftLint is a static analysis tool for Swift. It checks style and conventions, reports code metrics, and so on.

Getting Started#

To start using SwiftLint, enable it in your repository settings.

If you want to customize SwiftLint, put a .swiftlint.yml file in your repository.

Configuration#

Here is an example configuration via sider.yml:

linter:  swiftlint:    target: Source/    config: lint_yml/.swiftlint.yml    ignore_warnings: true    lenient: true    enable-all-rules: true

You can use several options to fine-tune SwiftLint to your project.

NameTypeDefault
root_dirstring-
targetstring, string[]-
configstring-
ignore_warningsbooleanfalse
lenientbooleanfalse
enable-all-rulesbooleanfalse

target#

This option allows you to specify files or directories to be analyzed.

This also allows you to specify a special format "@path/to/file" (prefixed with @). You can create a file which contains a list of file names to be analyzed and pass it to the analyzer with this option.

For example, when you have the file config/swiftlint_target.txt with the following content,

test1.swifttest2.swiftfoo/test3.swift

then sider.yml should be below:

linter:  swiftlint:    path: "@config/swiftlint_target.txt"

Note that the file path should be relative to the root directory where the sider.yml is located or the root_dir directory if it is specified.

alias: path

config#

This option allows you to specify a SwiftLint configuration file you want. If omitted, the SwiftLint's default one is used.

ignore_warnings#

This option allows you to ignore warning issues.

lenient#

This option allows you to downgrade serious violations to warnings.

enable-all-rules#

This option allows you to enable all the rules, even opt-in and disabled ones.