From ae7b61150de7c14eb901307daed403b67f29e962 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 12 Jun 2024 15:27:15 -0300 Subject: [PATCH] style(*) catch switch/case indentation See https://github.com/Kong/ngx_wasm_module/pull/530#discussion_r1635526128 --- src/wasm/ngx_wasm_ops.c | 26 +++++++++++++------------- util/morestyle.pl | 23 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/wasm/ngx_wasm_ops.c b/src/wasm/ngx_wasm_ops.c index 3f7c231c9..8c02e7b01 100644 --- a/src/wasm/ngx_wasm_ops.c +++ b/src/wasm/ngx_wasm_ops.c @@ -498,19 +498,19 @@ ngx_wasm_op_proxy_wasm_handler(ngx_wasm_op_ctx_t *opctx, rc = ngx_proxy_wasm_resume(pwctx, pwctx->phase, NGX_PROXY_WASM_STEP_REQ_BODY); switch (rc) { - case NGX_ERROR: - case NGX_HTTP_INTERNAL_SERVER_ERROR: - ngx_wasm_error(&rctx->env); - break; - case NGX_AGAIN: - ngx_wasm_yield(&rctx->env); - break; - case NGX_DONE: - rc = NGX_OK; - /* fallthrough */ - default: - ngx_wa_assert(rc == NGX_OK); - break; + case NGX_ERROR: + case NGX_HTTP_INTERNAL_SERVER_ERROR: + ngx_wasm_error(&rctx->env); + break; + case NGX_AGAIN: + ngx_wasm_yield(&rctx->env); + break; + case NGX_DONE: + rc = NGX_OK; + /* fallthrough */ + default: + ngx_wa_assert(rc == NGX_OK); + break; } } else { diff --git a/util/morestyle.pl b/util/morestyle.pl index 130acf54c..acbc4c447 100755 --- a/util/morestyle.pl +++ b/util/morestyle.pl @@ -63,6 +63,9 @@ # function declaration my ($func_decl_multiline, $in_func_decl); + # switch indentation levels + my @switch_level = (); + ################################################################## # end new rules - flags ################################################################## @@ -361,12 +364,30 @@ } } - # zero/null tests */ + # zero/null tests if ($line =~ /!= NULL/) { output "use 'if (ptr)' instead of if (ptr != NULL)"; } + # switch/case tests + + if ($line =~ /^(\s*)switch/) { + push(@switch_level, length($1)); + + } elsif ((scalar @switch_level) > 0) { + if ($line =~ /^(\s*)case/) { + if (length($1) != $switch_level[-1]) { + output "use 'case' at the same indent level as 'switch'"; + } + + } elsif ($line =~ /^(\s*)}/) { + if (length($1) == $switch_level[-1]) { + pop(@switch_level); + } + } + } + ################################################################## # end new rules - excluding comment lines ##################################################################