swiftlint version : 0.9.2
swiftlint rules => this only give standard rules not custom rules define in swiftlint.yml
=> even with example to catch all s character, it still did not use custom rule
custom_rules:
no_scott: # rule identifier
name: "No Scott Rule" # rule name
regex: "([s,S])" # matching pattern
match_kinds: # SyntaxKinds to match
- comment
- string
message: "There should be no Scotts here"
severity: error
All match kinds must match, so your custom rule is trying to match a single character to two different sequential tokens (comment followed by a string literal).
To match any token, just omit match_kinds
even with these two below it is not working. What is the best way to debug it?
custom_rules:
no_scott: # rule identifier
name: "No Scott Rule" # rule name
regex: "([s,S])" # matching pattern
message: "There should be no Scotts here"
severity: error
no_hiding_in_strings:
regex: "([n,N]inja)"
match_kinds: string
`
What is the best way to debug it?
I recommend to using Atom.
The linter-swiftlint plugin for Atom supports live linting with SwiftLint. Live linting will be updated by changing contents without saving.

Atom recognize (maybe)same regular expression syntax on find.

If you want to specify match_kinds, I recommend to using linter-sourcekitten-syntax that displays syntax kinds recognized by SourceKitService.

great info to debug problem in swiftlint. thanks
in the same topic. if your configuration already has custom rules. what it will display if print "swiftlint rules"
on my case
+-----------------------------+--------+-------------+------------------------+--------------------------------------------------+ | identifier | opt-in | correctable | enabled in your config | configuration | +-----------------------------+--------+-------------+------------------------+--------------------------------------------------+ | closing_brace | no | yes | yes | warning | | colon | no | yes | yes | warning | | comma | no | yes | no | warning | | conditional_binding_cascade | no | no | yes | warning | | control_statement | no | no | no | warning | | custom_rules | no | no | no | user-defined | | cyclomatic_complexity | no | no | yes | warning: 10, error: 20 | | empty_count | yes | no | no | error | | file_length | no | no | no | warning: 400, error: 1000 | | force_cast | no | no | yes | error | | force_try | no | no | yes | warning | | force_unwrapping | yes | no | no | warning | | function_body_length | no | no | no | warning: 40, error: 100 | | function_parameter_count | no | no | yes | warning: 5, error: 8 | | leading_whitespace | no | no | yes | warning | | legacy_constant | no | yes | yes | warning | | legacy_constructor | no | yes | yes | warning | | line_length | no | no | no | warning: 100, error: 200 | | missing_docs | yes | no | no | warning: public | | nesting | no | no | yes | warning | | opening_brace | no | yes | no | warning | | operator_whitespace | no | no | yes | warning | | return_arrow_whitespace | no | no | no | warning | | statement_position | no | yes | no | warning | | todo | no | no | no | warning | | trailing_newline | no | yes | no | warning | | trailing_semicolon | no | yes | no | warning | | trailing_whitespace | no | yes | no | warning | | type_body_length | no | no | no | warning: 200, error: 350 | | type_name | no | no | yes | (min_length) w/e: 3/0, (max_length) w/e: 40/1000 | | valid_docs | no | no | no | warning | | variable_name | no | no | yes | (min_length) w/e: 3/2, (max_length) w/e: 40/60 | +-----------------------------+--------+-------------+------------------------+--------------------------------------------------+
CustomRules does not yet support displaying configuration on swiftlint rules.
https://github.com/realm/SwiftLint/blob/master/Source%2FSwiftLintFramework%2FRules%2FCustomRules.swift#L15
public struct CustomRulesConfiguration: RuleConfiguration, Equatable {
public var consoleDescription: String { return "user-defined" }
Contribution is welcome! 馃槑
i'm using version 0.12.0 and when i'm adding a custom rule it does not work. I've checked the regex with the linter-swiftlint plugin and it checks out, but on Xcode it seems that it is not working.
Any advices?
thanks
Custom rule uses NSRegularExpression that recognizes ICU regular expression.
The ICU regular expressions are described at http://userguide.icu-project.org/strings/regexp .
Hi! Seems that custom rules don't work when using whitelist_rules. Any ideas?
Oh, it turned out that I should add custom_rules to whitelist instead of custom rule name.
@DeeSee That's exactly the information I needed to address my problem. I have submitted a PR for the README.md to clarify this: https://github.com/realm/SwiftLint/pull/1982
Most helpful comment
I recommend to using Atom.

The linter-swiftlint plugin for Atom supports live linting with SwiftLint. Live linting will be updated by changing contents without saving.
Atom recognize (maybe)same regular expression syntax on find.

If you want to specify

match_kinds, I recommend to using linter-sourcekitten-syntax that displays syntax kinds recognized by SourceKitService.