我想在我的.swiftlint.yml文件中做这样的事情:
force_cast:
severity: warning # explicitly
excluded:
- Dog.swift
我有这个代码,我不喜欢我得到的force_try警告:
let cell = tableView.dequeueReusableCellWithIdentifier(Constants.dogViewCellReuseIdentifier,
forIndexPath: indexPath) as! DogViewCell
我想通过从规则中排除此文件来禁止此文件的警告 .
有没有办法做到这一点 ?
3 回答
好吧,如果您不希望某些特定规则应用于特定文件,您可以使用@Benno Kress提到的技术 . 为此,您需要在swift文件中添加注释,如下所示 .
规则将被禁用,直到文件结束或者linter看到匹配的启用注释:
也可以通过配置swiftlint来跳过某些文件 . 在您将运行SwiftLint的目录中添加“ .swiftlint.yml ”文件 .
添加以下内容以排除某些文件 . 让我们说file1,file2 ......等
要禁用某些规则,请将以下内容添加到同一个“ .swiftlint.yml ”文件中 .
有关更多信息,请参阅以下链接 .
https://swifting.io/blog/2016/03/29/11-swiftlint/
https://github.com/realm/SwiftLint#disable-rules-in-code
您可以在文件的开头写入
// swiftlint:disable force_cast
,在该文件中您要抑制此规则的警告 . 它会被禁用,直到文件结尾或添加行// swiftlint:enable force_cast
.资料来源:https://github.com/realm/SwiftLint#disable-rules-in-code
我摆脱 force_cast
Step 1:
Step 2:
Step 3: 打开.swiftlint.yml并添加
参考 - https://github.com/realm/SwiftLint#disable-rules-in-code