-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Feature/warn missing fallthrough #1094
Closed
yashmasani
wants to merge
15
commits into
quick-lint:master
from
yashmasani:feature/warn-missing-fallthrough
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
90b6ce8
feat: add diag missing fallthrough comment to diagnostic types
yashmasani 9a31c29
feat: add functionality to find comments and report to diag if not found
yashmasani a95534f
fix: remove unintended diag warning from other tests cases due to new…
yashmasani 221cd6a
test: add new test cases for E0423 diag warn
yashmasani b23aa3e
fix: clang-format
yashmasani 731cce5
feat: add error docs for E0423
yashmasani f8ed5fa
feat: use more explicit message for E0423 diag
yashmasani a190be5
fix: change diagnostic name and match message with docs
yashmasani d73c09a
fix: change diag name in test
yashmasani 2516ebc
feat: check if token is valid end for switch case
yashmasani f07f052
fix: diag should display before case/default
yashmasani f121cb6
Merge branch 'master' into feature/warn-missing-fallthrough
yashmasani 1be8e48
fix: clang-format and use more correct variable name
yashmasani 6cc3562
fix: remove false positive diag
yashmasani 9f96079
fix: use console in docs instead of undeclared functions
yashmasani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# E0427: missing 'break;' or '// fallthrough' comment between statement and 'case' | ||
|
||
Switch Cases in javascript fallthrough to the next case if the `break` statement is not added at the end of the case. | ||
Since there is no explicit way of communication whether the fallthrough is intentional or not, it is recommended to use a comment indicating fallthrough. | ||
|
||
```javascript | ||
function test (c) { | ||
switch (c) { | ||
case 1: | ||
console.log('case 1'); | ||
default: | ||
console.log('default'); | ||
} | ||
} | ||
``` | ||
|
||
To fix this error, place a comment at the end of `case 1` indicating fallthrough | ||
|
||
```javascript | ||
function test (c) { | ||
switch (c) { | ||
case 1: | ||
console.log('case 1'); | ||
//fallthrough | ||
default: | ||
console.log('default'); | ||
} | ||
} | ||
``` |
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
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
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
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
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
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 |
---|---|---|
|
@@ -436,6 +436,33 @@ TEST_F(Test_Parse_Warning, warn_on_xor_operation_used_as_exponentiation) { | |
test_parse_and_visit_expression(u8"4 ^ 3"_sv, no_diags); | ||
test_parse_and_visit_expression(u8"(x+2)^a"_sv, no_diags); | ||
} | ||
TEST_F(Test_Parse_Warning, Diag_Fallthrough_Without_Comment_In_Switch) { | ||
test_parse_and_visit_statement( | ||
u8"switch(cond1){case 1:\nfoo()\ncase 2:\nbar() //fallthrough\ndefault:}"_sv, // | ||
u8" ` Diag_Fallthrough_Without_Comment_In_Switch"_diag); | ||
test_parse_and_visit_statement( | ||
u8"switch(cond1){case 1:\nfoo()\ncase 2:\nlongBarFn()\ndefault:}"_sv, // | ||
u8" ` Diag_Fallthrough_Without_Comment_In_Switch"_diag, // | ||
u8" ` Diag_Fallthrough_Without_Comment_In_Switch"_diag); | ||
// check for false positive | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
test_parse_and_visit_statement( | ||
u8R"(switch(cond1){ | ||
case 1: | ||
case 2: | ||
default: | ||
})"_sv, | ||
no_diags); | ||
test_parse_and_visit_statement( | ||
u8R"(switch(cond1){ | ||
case 1: | ||
foo() | ||
|
||
//fallthrough | ||
case 2: | ||
bar()//fallthrough | ||
default:})"_sv, | ||
no_diags); | ||
} | ||
TEST_F(Test_Parse_Warning, warn_on_unintuitive_precedence_when_using_bitshift) { | ||
test_parse_and_visit_expression( | ||
u8"var1 & 0x01 >> 0x02"_sv, | ||
|
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 |
---|---|---|
|
@@ -263,6 +263,7 @@ TEST_F(Test_Parse, asi_between_expression_statement_and_switch_label) { | |
switch (x) { | ||
case a: | ||
f() | ||
//fallthrough | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
case b: | ||
g() | ||
} | ||
|
@@ -278,6 +279,7 @@ TEST_F(Test_Parse, asi_between_expression_statement_and_switch_label) { | |
switch (x) { | ||
case a: | ||
f() | ||
//fallthrough | ||
default: | ||
g() | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍 Nice helper function.