New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rogue Custom Rules #1586

Closed
tiagoalmeida opened this Issue May 30, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@tiagoalmeida

tiagoalmeida commented May 30, 2017

There are certain rules that kill all custom rules. I call them Rogue Rules.

Simple example

Let us start with a simple .swiftlint file, with only one customization:

vertical_whitespace: 
  max_empty_lines: 2

Imagine that you have a custom rule, like this one:

  force_https: # From https://github.com/Twigz/Game
    name: "Force HTTPS over HTTP"
    message: "HTTPS should be favored over HTTP"
    regex: "((?i)http(?!s))"
    match_kinds: string
    severity: warning

Then an awesome variable like this one:

_ = "http://thavariable.com"

This works. The variable produces a warning, everyone is happy.

THE ROGUE RULE

The moment you bring the Rogue Rule, the panic starts, people running and fire emerges in other rules.

Let me introduce you to my Rogue Rule:

  two_enters_before_marks: # ¯\_(ツ)_/¯
    name: "2 Enters before Marks"
    message: "You need two enters before Marks"
    regex: '( *} *\n *\n *// MARK)' # I have no idea what I am doing ¯\_(ツ)_/¯
    severity: "warning"

So by now, you must be imagining "YOU ARE THE ROGUE THAT IS KILLING REGEX". Probably you are right. Yeah, I know I have a lot to learn with regex, but it would be cool that people that use websites like Regex101 and create Rogue Rules wouldn't destroy all the work ever done by humankind.

Post Script Notes

PS: I am using the version 0.19.0.
PS2: I imagine that is some error with that regex that destroys everything, but since I have no feedback is kinda hard to spot the error. At least an error on running the script would be cool.

Ok, enough is enough, I am going after that Rogue Rule.

PS3: I started to mess around with SwiftLint code and found out that this rule is created with a niled regex
PS4: Ideally, for me, as a SwiftLinter user it would give an error (like it currently happens when the YAML parser fails) when a custom rule is badly defined. Not saying anything and obliterate the other custom rules is kinda weird.

@marcelofabri

This comment has been minimized.

Show comment
Hide comment
@marcelofabri

marcelofabri May 30, 2017

Collaborator

So, the actual issue here is that we should provide better feedback when a regex is invalid?

Collaborator

marcelofabri commented May 30, 2017

So, the actual issue here is that we should provide better feedback when a regex is invalid?

@tiagoalmeida

This comment has been minimized.

Show comment
Hide comment
@tiagoalmeida

tiagoalmeida May 30, 2017

When I started the issue I had no idea what was happening.

But after investigating in the code, yes, the issue is related with invalid regex.

This actually leads to two different issues:

  • When an invalid regex occurs SwiftLint starts to ignore all custom rules
  • There is no feedback that the problem is related to an invalid regex

tiagoalmeida commented May 30, 2017

When I started the issue I had no idea what was happening.

But after investigating in the code, yes, the issue is related with invalid regex.

This actually leads to two different issues:

  • When an invalid regex occurs SwiftLint starts to ignore all custom rules
  • There is no feedback that the problem is related to an invalid regex
@marcelofabri

This comment has been minimized.

Show comment
Hide comment
@marcelofabri

marcelofabri Jul 17, 2017

Collaborator

Closed in #1681 and #1683.

Collaborator

marcelofabri commented Jul 17, 2017

Closed in #1681 and #1683.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment