Skip to content

Commit

Permalink
style(*) catch switch/case indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm authored and thibaultcha committed Jun 14, 2024
1 parent 6622c43 commit ae7b611
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
26 changes: 13 additions & 13 deletions src/wasm/ngx_wasm_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 22 additions & 1 deletion util/morestyle.pl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
# function declaration
my ($func_decl_multiline, $in_func_decl);

# switch indentation levels
my @switch_level = ();

##################################################################
# end new rules - flags
##################################################################
Expand Down Expand Up @@ -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
##################################################################
Expand Down

0 comments on commit ae7b611

Please sign in to comment.