From b23aa3ebf7b379ee9d75b2df5e4a84f3c084960d Mon Sep 17 00:00:00 2001 From: Yash Masani Date: Sat, 21 Oct 2023 14:23:57 -0400 Subject: [PATCH] fix: clang-format --- src/quick-lint-js/diag/diagnostic-types-2.h | 2 +- src/quick-lint-js/fe/parse-statement.cpp | 58 +++++++++++---------- test/test-parse-warning.cpp | 8 +-- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/quick-lint-js/diag/diagnostic-types-2.h b/src/quick-lint-js/diag/diagnostic-types-2.h index a94fd971c5..9acff27e5d 100644 --- a/src/quick-lint-js/diag/diagnostic-types-2.h +++ b/src/quick-lint-js/diag/diagnostic-types-2.h @@ -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; }; diff --git a/src/quick-lint-js/fe/parse-statement.cpp b/src/quick-lint-js/fe/parse-statement.cpp index 82a37bc9ad..5e35e2fe3a 100644 --- a/src/quick-lint-js/fe/parse-statement.cpp +++ b/src/quick-lint-js/fe/parse-statement.cpp @@ -2770,30 +2770,30 @@ void Parser::parse_and_visit_switch(Parse_Visitor_Base &v) { Hash_Set 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) { @@ -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; @@ -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{ diff --git a/test/test-parse-warning.cpp b/test/test-parse-warning.cpp index bd41038db0..79f0ea4165 100644 --- a/test/test-parse-warning.cpp +++ b/test/test-parse-warning.cpp @@ -442,7 +442,7 @@ 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( @@ -450,7 +450,8 @@ TEST_F(Test_Parse_Warning, Diag_Explicit_Fallthrough_Comment_In_Switch) { case 1: case 2: default: - })"_sv, no_diags); + })"_sv, + no_diags); test_parse_and_visit_statement( u8R"(switch(cond1){ case 1: @@ -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); } } }