This article is the 18th day article of Swift/Kotlin Lovers Association Advent Calendar 2020. Since SwiftLint 0.42.0, the configuration file can be obtained remotely, so I will show you how to do it.
--Overview of SwiftLint and how to set it up Please refer to the article I wrote earlier. How to set up Swift's static analysis tool "SwiftLint" --Qiita
I will show you how to create a configuration file, place it on the server, and get it locally.
Create a SwiftLint configuration file with any name. The writing method is the same as the normal configuration file. Extract only the settings you want to share.
I have extracted the following:
uhooi-base-swiftlint-config.yml
disabled_rules:
#- block_based_kvo
# ...
opt_in_rules:
- anyobject_protocol
# ...
analyzer_rules:
- unused_declaration
# ...
line_length:
warning: 300
error: 500
identifier_name:
min_length:
warning: 1
The following is different for each project, so I didn't extract it.
Place the created configuration file on the server.
I created a GitHub repository just to put the SwiftLint config file and put it there. https://github.com/uhooi/SwiftLint-Config/blob/main/uhooi-base-swiftlint-config.yml
If you attach a tag for each supported version of SwiftLint, you can specify the tag and acquire the configuration file and reuse it even in projects with different versions of SwiftLint. I'm using the release feature on GitHub. https://github.com/uhooi/SwiftLint-Config/releases
It is easy to understand if you put the correspondence table of the version of SwiftLint and the release of the configuration file in the README. (I referred to the Swift and SwiftLint version correspondence table in the SwiftLint README)
Read the configuration file placed on the server from other configuration files.
Just add parent_config
.
yaml:.swiftLint.yml
parent_config: {URL of the shared configuration file}
If you are in the GitHub repository, you can get the config file with https://raw.githubusercontent.com/ {username}/{repository name}/{tag or branch name}/{config file name}
..
yaml:.swiftLint.yml
parent_config: https://raw.githubusercontent.com/uhooi/SwiftLint-Config/v1.0.0/uhooi-base-swiftlint-config.yml
As the name of parent
, the configuration file placed on the server becomes the parent setting.
The child settings have priority and can be overwritten.
Since I created my own config file, I didn't overwrite any rules, only included
and excluded
.
yaml:.swiftlint.yml
parent_config: https://raw.githubusercontent.com/uhooi/SwiftLint-Config/v1.0.0/uhooi-base-swiftlint-config.yml
included:
- Shared
- UhooiPicBook
- UhooiPicBookStickers
- UhooiPicBookWidgets
- UhooiPicBookWidgetsConfigurableIntent
#- UhooiPicBookTests
#- UhooiPicBookUITests
excluded:
- UhooiPicBook/Generated
The configuration file is much cleaner!
Running SwiftLint with the URL of the config file in parent_config
will download the remote config file to the .swiftlint/RemoteConfigCache
folder.
As the name suggests, the above folder acts as a cache, so if the configuration file already exists, it will be used as it is.
The cache folder is automatically written to .gitignore
at the time of download, so please commit as it is.
.gitignore
+
+
+ # SwiftLint Remote Config Cache
+ .swiftlint/RemoteConfigCache
The remote timeout defaults to 2 seconds and 1 second if the cache exists.
To change it, specify remote_timeout
or remote_timeout_if_cached
.
Now you can easily share your SwiftLint settings with multiple projects! You can use my config file as a parent: relaxed:
This is the article on the 18th day of Swift/Kotlin Lovers Association Advent Calendar 2020. Tomorrow isn't filled yet. Let's participate from here!
Recommended Posts