SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Custom Rules

Open yuvigr opened this issue 10 years ago • 6 comments

Hey,

I'm using the 0.12.0 version, and in the .swiftlint.yml i'm creating a custom rule like the guide say. My Regex string works (i've checked this in atom with the plugin and with a online tool), but for some reason non of the custom rules i have created (also added the rules from the examples) works. Maybe there is additional steps after adding the rules to the file?

Thanks

yuvigr avatar Aug 30 '16 07:08 yuvigr

Could you please share full steps detailing what you're doing, what you're expecting to happen and what's actually happening instead? That way we'll have enough info to help identify what you may be doing wrong, or what bug may be in SwiftLint.

jpsim avatar Aug 30 '16 17:08 jpsim

Yeah sure

I'm adding this custom rule to the configuration file

custom_rules:
  new_line_after_method_signature:
    include: "*.swift"
    name: "New line after method signature"
    regex: "({\n\s*\n\s*\w)"
    message: "No new line after curly braces and before code"
    severity: warning

this rule will check the following: after any kind of opening braces (function signature, enums, structs, classes) the next line should start with the code, if the next line is empty (line drop) then check to see if there is a comment on the next line.

Examples:

func okExample() {
    code start here
}

func anotherOKExample() {

    // comment
    code start here
}

func noOKExpample() {

    code start here
}

I have check the regex in several tools and it works (it marks the third case). Also like i said i have tried the

custom_rules:
  no_hiding_in_strings:
    regex: "([n,N]inja)"
    match_kinds: string

And it didn't showed any warnings

Thanks!

yuvigr avatar Aug 30 '16 17:08 yuvigr

{ needs escaping. Try "\{\n\s*\n"

norio-nomura avatar Aug 31 '16 07:08 norio-nomura

Of course..totally forgot about this. Thank you so much!

yuvigr avatar Aug 31 '16 07:08 yuvigr

Thanks for the help @norio-nomura

jpsim avatar Aug 31 '16 17:08 jpsim

is it possible to put this rule in the official rule set? I am currently searching for exactly this! @yuvigr @jpsim @norio-nomura @chriseidhof @koke ? - anybody?

Blackjacx avatar Apr 06 '17 15:04 Blackjacx