diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-07 15:45:10 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-07 15:47:40 +0900 |
commit | d548073f68ae719933c328686df224f74a60d366 (patch) | |
tree | 6a831188d76894d6a0efcd90ec0def0235fa1c20 /parse.y | |
parent | 789e49dc7e36f2c19a3df6dfa348e95b7105061c (diff) | |
download | bundler-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.y | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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; + } + } } ; |