aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-07-07 15:45:10 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-07-07 15:47:40 +0900
commitd548073f68ae719933c328686df224f74a60d366 (patch)
tree6a831188d76894d6a0efcd90ec0def0235fa1c20 /parse.y
parent789e49dc7e36f2c19a3df6dfa348e95b7105061c (diff)
downloadruby-d548073f68ae719933c328686df224f74a60d366.tar.gz
Enable indentation warning against `if` just after `else`
```ruby if false puts 'false' else if true puts 'true' end # -:5: warning: mismatched indentations at 'end' with 'if' at 3 end ``` [Feature #15990]
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y9
1 files changed, 9 insertions, 0 deletions
diff --git a/parse.y b/parse.y
index 88c02082ad..7823b4215d 100644
--- a/parse.y
+++ b/parse.y
@@ -3003,6 +3003,15 @@ k_begin : keyword_begin
k_if : keyword_if
{
token_info_push(p, "if", &@$);
+ if (p->token_info && p->token_info->nonspc &&
+ p->token_info->next && !strcmp(p->token_info->next->token, "if")) {
+ const char *tok = p->lex.ptok, *beg = p->lex.pbeg;
+ while (tok > beg && ISSPACE(*--tok));
+ while (beg < tok && ISSPACE(*beg)) beg++;
+ if (tok - beg == 3 && !memcmp(beg, "else", 4)) {
+ p->token_info->nonspc = 0;
+ }
+ }
}
;