From f5f90281ba4c382524cab556eb15f25b1dc00582 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelgwad Date: Thu, 11 Apr 2024 07:18:55 +0200 Subject: [PATCH] fix(curly-rule): enforce braces for else clause --- .grit/patterns/js/curly.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.grit/patterns/js/curly.md b/.grit/patterns/js/curly.md index 929c1c03..5a1aaedb 100644 --- a/.grit/patterns/js/curly.md +++ b/.grit/patterns/js/curly.md @@ -10,10 +10,13 @@ engine marzano(1.0) language js or { - `if($_) $body`, + if_statement(consequence = $body), for_statement($body), while_statement($body), do_statement($body), + else_clause(else = $body) where { + $body <: ! if_statement() + } } where { $body <: not statement_block(), $body => `{$body}`, @@ -33,6 +36,23 @@ if (x > 0) { doStuff(); } ``` + +##else +```js +if (x > 0) + doStuff(); +else + console.log("e"); +``` +will become +```js +if (x > 0) { + doStuff(); +} else { + console.log("e"); +} +``` + ## for ```js for (var i = 0; i < 10; i++)