-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add exemption for in
-Wparens
for if ((x))
.
This is used to silence warnings about constant if statements like: ``` if ((true)) { return 2; } return 3; ```
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Tokstyle.Linter.ParensSpec where | ||
|
||
import Test.Hspec (Spec, it, shouldBe) | ||
|
||
import Tokstyle.Linter (allWarnings, analyse) | ||
import Tokstyle.LinterSpec (mustParse) | ||
|
||
|
||
spec :: Spec | ||
spec = do | ||
it "warns about parentheses around return expressions" $ do | ||
ast <- mustParse | ||
[ "int a(int b) {" | ||
, " return (1 + 2);" | ||
, "}" | ||
] | ||
analyse allWarnings ("test.c", ast) | ||
`shouldBe` | ||
[ "test.c:2: return expression does not need parentheses [-Wparens]" | ||
] | ||
|
||
it "does not warn about parens in if conditions" $ do | ||
ast <- mustParse | ||
[ "int a(int b) {" | ||
, " if ((true)) { return 3; }" | ||
, "}" | ||
] | ||
analyse allWarnings ("test.c", ast) `shouldBe` [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters