Swiftlint: Custom Rules

Created on 30 Aug 2016  路  6Comments  路  Source: realm/SwiftLint

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

question

All 6 comments

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.

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!

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

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

Thanks for the help @norio-nomura

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

muzamilhassan1987 picture muzamilhassan1987  路  3Comments

BalestraPatrick picture BalestraPatrick  路  3Comments

Den-Ree picture Den-Ree  路  3Comments

ziryanov picture ziryanov  路  3Comments

Tableau-David-Potter picture Tableau-David-Potter  路  3Comments