【问题标题】:SwiftLint: Is it possible to disable rules for a specific parameter?SwiftLint:是否可以禁用特定参数的规则?
【发布时间】:2021-02-09 15:18:07
【问题描述】:

我有一个日志记录方法,不可避免地会使用违反 SwiftLint 的 hardcoded_string 规则的参数调用:

Logger.log("This will be a hardcoded string usually")

我知道我可以每次都使用 swiftlint:disable:next,但是是否可以在 Logger 类定义中指定 swiftlint 应该总是忽略这个特定参数?比如:

/// Implementation of Logger

/// Logs a message
/// - Parameter messsage: The message to log swiftlint:disable hardcoded_string
func log(_ message: String) { ... }

【问题讨论】:

  • 在您的 swiftlint.yml 中同时禁用 hardcoded_string
  • 不,我不想全局禁用它。我想在这种特定情况下禁用它。
  • 如何编写自定义规则来禁用除 Logger.log() 调用之外的硬编码字符串?

标签: swift swiftlint


【解决方案1】:

你可以写这行

// swiftlint:disable force_cast

【讨论】:

    猜你喜欢
    • 2020-07-04
    • 2017-02-01
    • 1970-01-01
    • 2023-03-12
    • 2017-07-22
    • 1970-01-01
    • 2016-07-22
    • 2017-07-30
    • 2020-09-06
    相关资源
    最近更新 更多