Skip to content
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

Certain custom rule regular expressions aren't parsed properly #717

Closed
kutschenator opened this issue Jul 7, 2016 · 5 comments · Fixed by #743
Closed

Certain custom rule regular expressions aren't parsed properly #717

kutschenator opened this issue Jul 7, 2016 · 5 comments · Fixed by #743
Labels
bug Unexpected and reproducible misbehavior.

Comments

@kutschenator
Copy link

kutschenator commented Jul 7, 2016

Hi,
i am trying to add custom warnings in my yaml to match Void -> and -> ()
The first rule to match Void -> and Void-> works perfectly

custom_rules:
  void_as_parameter:
    included: "*.swift"
    name: "Void as Parameter"
    regex: "(Void ->)"
    message: "Use Void only as return type."
    severity: warning

but i cannot match -> () and ->()
i have tried (->[ ]?\(\)) and (\-\>[ ]?\(\)) but nothing works
Am I doing something wrong?

@jpsim
Copy link
Collaborator

jpsim commented Jul 8, 2016

Works for me. What version of SwiftLint do you have installed (swiftlint version)?

$ cat .swiftlint.yml 
custom_rules:
  void_as_parameter:
    included: "*.swift"
    name: "Void as Parameter"
    regex: "(Void ->)"
    message: "Use Void only as return type."
    severity: warning
$ cat main.swift 
let abc: Void -> () = {}
$ swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'main.swift' (1/1)
/working_dir/main.swift:1:10: warning: Void as Parameter Violation: Use Void only as return type. (void_as_parameter)
Done linting! Found 1 violation, 0 serious in 1 file.

@jpsim jpsim added the question Question or doubts that needs discussion and clarification. Can become a bug or proposal. label Jul 8, 2016
@kutschenator
Copy link
Author

kutschenator commented Jul 8, 2016

Sorry i was not clear enough, the posted rule works but the one to match -> () does not.

➜  tmp cat .swiftlint.yml 
custom_rules:
  void_as_return:
    included: "*.swift"
    name: "Void as Parameter"
    regex: "(->[ ]?\(\))"
    message: "Use Void as return type instead of ()."
    severity: warning

➜  tmp cat test.swift 
let abc: () -> () = {}

➜  tmp swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'test.swift' (1/1)
Done linting! Found 0 violations, 0 serious in 1 file.

@jpsim
Copy link
Collaborator

jpsim commented Jul 8, 2016

Oops, no you were clear in your issue I just misread it. I can reproduce this, I suspect it's the way we're creating NSRegularExpressions for custom rules. I'll mark this as a bug and hopefully will have time to take a closer look later.

@jpsim jpsim added bug Unexpected and reproducible misbehavior. and removed question Question or doubts that needs discussion and clarification. Can become a bug or proposal. labels Jul 8, 2016
@jpsim jpsim changed the title Custom rule in yml does not match Certain custom rule regular expressions aren't parsed properly Jul 8, 2016
@kutschenator
Copy link
Author

should I submit a rule for this once the issue is resolved?

@jpsim
Copy link
Collaborator

jpsim commented Jul 8, 2016

Yes please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants