-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add ControlStatementRule #39
Conversation
return StyleViolation(type: .ControlStatement, | ||
location: Location(file: file, offset: range.location), | ||
severity: .Low, | ||
reason: "if,for,while,do statements shouldn't wrap their conditionals in parentheses.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably use the regex match for the specific keyword instead of listing them all
This is really great, @andreamazz! Thanks for the PR ✨ You'll have to resolve the merge conflict before we can merge this. Also, |
withSyntaxKinds: [.Keyword]).map{ return ($0, "for") } | ||
let whileStatement = file.matchPattern("\\s{0,}(while)\\s{0,}\\(", | ||
withSyntaxKinds: [.Keyword]).map{ return ($0, "while") } | ||
return (ifStatement + forStatement + whileStatement).map { violation in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we separate while
from do-while
statements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this seems fine to me.
Fixed the conflict 👍 |
Looks great, @andreamazz! Could you add an entry to CHANGELOG.md under "Enhancements"? |
Sure! Updated. |
Fantastic, thanks for the hard work @andreamazz! |
FYI, there were a few false positives with this rule, especially when using tuples in control statements, and I've attempted to address those in #48. |
Right, tuples did not cross my mind 😅 |
Hi @jpsim
I've added the lint rule for
if
,for
,while
anddo
while statements as mentioned in one of the Todos in the test suite.