How to place and share SwiftLint config files on the server

Introduction

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.

environment

Not explained in this article

--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

How to place and share configuration files on the server

I will show you how to create a configuration file, place it on the server, and get it locally.

Creating a shared configuration file

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 shared configuration file on the server

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 スクリーンショット 2020-12-17 22.12.32.png

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 スクリーンショット 2020-12-17 22.19.03.png

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) スクリーンショット 2020-12-17 22.21.20.png

Acquisition destination configuration file settings

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!

Get the configuration file placed on the server

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.

in conclusion

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!

Reference link

Recommended Posts

How to place and share SwiftLint config files on the server
How to run React and Rails on the same server
[Ruby] How to get the tens place and the ones place
How to share on the host side (windows) and guest side (CentOS 7) with VirtualBox
How to use Maven to place resource files outside the JAR
How to check the extension and size of uploaded files
How to install and configure the monitoring tool "Graphite" on Ubuntu
How to share files with Docker Toolbox
[Java] How to output and write files!
How to change the timezone on Ubuntu
How to find the tens and ones
How to place geckodriver (Selenium WebDriver) on the path using Maven command
[Android] How to turn the Notification panel on and off using StatusBarManager
[Java] How to retrieve the parameters passed from html on the server side
Ssh login to the app server on heroku
How to find the total score and average score
How to build parquet-tools and merge Parquet files
[Java] Memo on how to write the source
How to find the distance and angle between two points on a plane
[Ruby on Rails] How to change the column name
How to hover and click on Selenium DOM elements
How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
How to handle TSV files and CSV files in Ruby
Install MySQL 5.6 on CentOS6 [How to specify the version]
[Swift5] How to round off, round down, and round up to the second or third decimal place
(Ruby on Rails6) How to create models and tables
[Ruby On Rails] How to search and save the data of the parent table from the child table
How to use OpenCV 4 on Android and view camera live view
The key to running Docker on Raspberry Pi 4 (Ubuntu server 20.04)
How to create an application server on an EC2 instance on AWS
Difference between Java and JavaScript (how to find the average)
I want to bring Tomcat to the server and start the application
Apache Geode-Easy way to execute logic on the server side
How to Install Elixir and Phoenix Framework on Ubuntu 20.04 LTS
Sample to create one-time password on server side and client side
How to disable Set-Cookie from API on the front side
How to switch Java in the OpenJDK era on Mac
How to install PHP 7.4 and SQL Server drivers in CentOS 7.7
How to play MIDI files using the Java Sound API
Zip and upload multiple files to Firebase Storage on Android.
How to check the database of apps deployed on Heroku
How to deploy on heroku
How to terminate rails server
How to rollback migration files
[Docker] How to back up and restore the DB data of Rails application on docker-compose [MySQL]
How to pick up the input value by asynchronous communication and output the desired data from the server
[Swift] How to dynamically change the height of the toolbar on the keyboard
[Rails] How to get the URL of the transition source and redirect
[Swift5] How to get an array and the complement of arrays
How to set the IP address and host name of CentOS8
How to display 0 on the left side of the standard input value
[Rails] How to introduce kaminari with Slim and change the design
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku
How to display products by category on the same list screen
How to install the language used in Ubuntu and how to build the environment
[Rails] How to put a crown mark on the ranking function
How to make CsrfRequestDataValueProcessor and original RequestDataValueProcessor coexist on Spring Boot
Install Ubuntu20.04 on RaspberryPi 4 and build Kubernetes to run the container
How to create a web server on an EC2 instance on AWS
[Java] How to convert from String to Path type and get the path
Things to remember and concepts in the Ruby on Rails tutorial