Skip to content

Commit

Permalink
fix: clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmasani committed Oct 21, 2023
1 parent 221cd6a commit b23aa3e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/quick-lint-js/diag/diagnostic-types-2.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ struct Diag_Duplicated_Cases_In_Switch_Statement {
struct Diag_Explicit_Fallthrough_Comment_In_Switch {
[[qljs::diag("E0423", Diagnostic_Severity::warning)]] //
[[qljs::message("missing fallthrough comment",
ARG(end_of_case))]] //
ARG(end_of_case))]] //
Source_Code_Span end_of_case;
};

Expand Down
58 changes: 31 additions & 27 deletions src/quick-lint-js/fe/parse-statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2770,30 +2770,30 @@ void Parser::parse_and_visit_switch(Parse_Visitor_Base &v) {
Hash_Set<String8_View> cases;
while (keep_going) {
auto is_comment_line = [&]() -> bool {
const Char8* th = this->lexer().end_of_previous_token();
const Char8 *th = this->lexer().end_of_previous_token();
bool f = false;
int i = 0;
for(;;) {
switch(th[i]) {
case '/':
if (th[i+1] == '/') {
f = true;
}
goto exit_loop;
// skip empty lines to reach comment
case ' ':
case '\n':
case '\r':
case '\t':
case '\f':
case '\v':
break;
default:
goto exit_loop;
for (;;) {
switch (th[i]) {
case '/':
if (th[i + 1] == '/') {
f = true;
}
goto exit_loop;
// skip empty lines to reach comment
case ' ':
case '\n':
case '\r':
case '\t':
case '\f':
case '\v':
break;
default:
goto exit_loop;
}
i++;
i++;
}
exit_loop:;
exit_loop:;
return f;
};
switch (this->peek().type) {
Expand All @@ -2803,10 +2803,12 @@ void Parser::parse_and_visit_switch(Parse_Visitor_Base &v) {
break;

case Token_Type::kw_case: {
if (!is_before_first_switch_case && prev_token.type != Token_Type::kw_break && prev_token.type != Token_Type::kw_case && !is_comment_line()) {
if (!is_before_first_switch_case &&
prev_token.type != Token_Type::kw_break &&
prev_token.type != Token_Type::kw_case && !is_comment_line()) {
this->diag_reporter_->report(
Diag_Explicit_Fallthrough_Comment_In_Switch{
.end_of_case = prev_token.span() });
Diag_Explicit_Fallthrough_Comment_In_Switch{.end_of_case =
prev_token.span()});
}
prev_token = this->peek();
is_before_first_switch_case = false;
Expand Down Expand Up @@ -2840,17 +2842,19 @@ void Parser::parse_and_visit_switch(Parse_Visitor_Base &v) {
}

case Token_Type::kw_default:
if (!is_before_first_switch_case && prev_token.type != Token_Type::kw_break && prev_token.type != Token_Type::kw_case && !is_comment_line()) {
if (!is_before_first_switch_case &&
prev_token.type != Token_Type::kw_break &&
prev_token.type != Token_Type::kw_case && !is_comment_line()) {
this->diag_reporter_->report(
Diag_Explicit_Fallthrough_Comment_In_Switch{
.end_of_case = prev_token.span() });
Diag_Explicit_Fallthrough_Comment_In_Switch{.end_of_case =
prev_token.span()});
}
is_before_first_switch_case = false;
this->skip();
QLJS_PARSER_UNIMPLEMENTED_IF_NOT_TOKEN(Token_Type::colon);
this->skip();
break;

default: {
if (is_before_first_switch_case) {
this->diag_reporter_->report(Diag_Statement_Before_First_Switch_Case{
Expand Down
8 changes: 5 additions & 3 deletions test/test-parse-warning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,16 @@ TEST_F(Test_Parse_Warning, Diag_Explicit_Fallthrough_Comment_In_Switch) {
u8" ^^^ Diag_Explicit_Fallthrough_Comment_In_Switch"_diag);
test_parse_and_visit_statement(
u8"switch(cond1){case 1:\nfoo()\ncase 2:\nlongBarFn()\ndefault:}"_sv, //
u8" ^^^^^^^^^ Diag_Explicit_Fallthrough_Comment_In_Switch"_diag, //
u8" ^^^^^^^^^ Diag_Explicit_Fallthrough_Comment_In_Switch"_diag, //
u8" ^^^ Diag_Explicit_Fallthrough_Comment_In_Switch"_diag);
// check for false positive
test_parse_and_visit_statement(
u8R"(switch(cond1){
case 1:
case 2:
default:
})"_sv, no_diags);
})"_sv,
no_diags);
test_parse_and_visit_statement(
u8R"(switch(cond1){
case 1:
Expand All @@ -459,7 +460,8 @@ TEST_F(Test_Parse_Warning, Diag_Explicit_Fallthrough_Comment_In_Switch) {
//fallthrough
case 2:
bar()//fallthrough
default:})"_sv, no_diags);
default:})"_sv,
no_diags);
}
}
}
Expand Down

0 comments on commit b23aa3e

Please sign in to comment.