0

我正在为 SwiftLint 创建一些自定义规则,我只希望我的规则适用于某些函数中的字符串,例如只适用于 logEvent 中的字符串

analytics.logEvent('goal_completion', { name: 'lever_puzzle'});

SwiftLint Github 似乎没有提到如何仅在某些函数中将 lint 应用于字符串。

swiftLint 自定义规则:

    namingConvention:
        name: "event naming"
        regex: "[^a-z]"
        message: "any event should only be in letters"
        severity: warning
4

2 回答 2

0

您需要match_kinds为您的规则确定 。

match_kinds:
  - identifier
  - string
于 2019-10-15T07:43:25.687 回答
0

Yup, you're right, currently function by function rules are not available.

However, you can make multiple SwiftLint yml files! Here's what the docs say:

Nested Configurations

SwiftLint supports nesting configuration files for more granular control over the linting process.

Include additional .swiftlint.yml files where necessary in your directory structure.
Each file will be linted using the configuration file that is in its directory or at the deepest level of its parent directories. Otherwise the root configuration will be used.
included is ignored for nested configurations.

So basically if you can group those functions together, they can all have their separate SwiftLint yml file. Not the best solution, but maybe the best solution for the current offering.

于 2020-08-22T23:35:23.927 回答