LoginSignup
3
0

More than 1 year has passed since last update.

【Swiftlint】一部だけルールを適用したくない、あるいはしたいとき

Last updated at Posted at 2021-12-04

どういうことか

たとえばこういうのを書いたとき

    private var viewModel: ViewModel!

implicitly_unwrapped_optional という警告がでてしまう。
「いやここはOKでしょ」というとき。

ルールを適用外にする

コメントアウトの形式で swiftlint:disable ルール名 を書くと、そのファイルのこれを書いた以降にそのルールが適用されなくなる。

    // swiftlint:disable implicitly_unwrapped_optional
    private var viewModel: ViewModel! // implicitly_unwrapped_optionalの警告が出ない

    @IBOutlet weak var titleLabel: UILabel! // private_outletの警告が出る
    @IBOutlet weak var userImageView: UIImageView! // private_outletの警告が出る
    // swiftlint:disable private_outlet
    @IBOutlet weak var dateLabel: UILabel! // private_outletの警告が出ない

ルールを適用する

逆に swiftlint:enable ルール名 を書くと、そのファイルのこれを書いた以降にそのルールが適用される。

    // swiftlint:disable private_outlet
    @IBOutlet weak var titleLabel: UILabel! // 警告が出ない
    @IBOutlet weak var userImageView: UIImageView! // 警告が出ない
    // swiftlint:enable private_outlet
    @IBOutlet weak var dateLabel: UILabel! // 警告が出る

おわり(´・ω・`)

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0