mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: when
indent
* parse.y (k_when): warn less-indented `when` than `case`. [ruby-core:86492] [Bug #14674] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2625c6a761
commit
a3a5f38d09
2 changed files with 12 additions and 11 deletions
17
parse.y
17
parse.y
|
@ -738,7 +738,7 @@ PRINTF_ARGS(static void parser_compile_error(struct parser_params*, const char *
|
|||
|
||||
static void token_info_push(struct parser_params*, const char *token, const rb_code_location_t *loc);
|
||||
static void token_info_pop(struct parser_params*, const char *token, const rb_code_location_t *loc);
|
||||
static void token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, const rb_code_location_t *loc);
|
||||
static void token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, int same, const rb_code_location_t *loc);
|
||||
%}
|
||||
|
||||
%pure-parser
|
||||
|
@ -2731,31 +2731,31 @@ k_do_block : keyword_do_block
|
|||
|
||||
k_rescue : keyword_rescue
|
||||
{
|
||||
token_info_warn(p, "rescue", p->token_info, &@$);
|
||||
token_info_warn(p, "rescue", p->token_info, 1, &@$);
|
||||
}
|
||||
;
|
||||
|
||||
k_ensure : keyword_ensure
|
||||
{
|
||||
token_info_warn(p, "ensure", p->token_info, &@$);
|
||||
token_info_warn(p, "ensure", p->token_info, 1, &@$);
|
||||
}
|
||||
;
|
||||
|
||||
k_when : keyword_when
|
||||
{
|
||||
token_info_warn(p, "when", p->token_info, &@$);
|
||||
token_info_warn(p, "when", p->token_info, 0, &@$);
|
||||
}
|
||||
;
|
||||
|
||||
k_else : keyword_else
|
||||
{
|
||||
token_info_warn(p, "else", p->token_info, &@$);
|
||||
token_info_warn(p, "else", p->token_info, 1, &@$);
|
||||
}
|
||||
;
|
||||
|
||||
k_elsif : keyword_elsif
|
||||
{
|
||||
token_info_warn(p, "elsif", p->token_info, &@$);
|
||||
token_info_warn(p, "elsif", p->token_info, 1, &@$);
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -4533,12 +4533,12 @@ token_info_pop(struct parser_params *p, const char *token, const rb_code_locatio
|
|||
p->token_info = ptinfo_beg->next;
|
||||
|
||||
/* indentation check of matched keywords (begin..end, if..end, etc.) */
|
||||
token_info_warn(p, token, ptinfo_beg, loc);
|
||||
token_info_warn(p, token, ptinfo_beg, 1, loc);
|
||||
xfree(ptinfo_beg);
|
||||
}
|
||||
|
||||
static void
|
||||
token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, const rb_code_location_t *loc)
|
||||
token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, int same, const rb_code_location_t *loc)
|
||||
{
|
||||
token_info ptinfo_end_body, *ptinfo_end = &ptinfo_end_body;
|
||||
if (!p->token_info_enabled) return;
|
||||
|
@ -4547,6 +4547,7 @@ token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_b
|
|||
if (ptinfo_beg->linenum == ptinfo_end->linenum) return; /* ignore one-line block */
|
||||
if (ptinfo_beg->nonspc || ptinfo_end->nonspc) return; /* ignore keyword in the middle of a line */
|
||||
if (ptinfo_beg->column == ptinfo_end->column) return; /* the indents are matched */
|
||||
if (!same && ptinfo_beg->column < ptinfo_end->column) return;
|
||||
rb_warn3L(ptinfo_end->linenum,
|
||||
"mismatched indentations at '%s' with '%s' at %d",
|
||||
WARN_S(token), WARN_S(ptinfo_beg->token), WARN_I(ptinfo_beg->linenum));
|
||||
|
|
|
@ -450,13 +450,13 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
["begin", "rescue ; end"],
|
||||
["begin rescue", "else ; end"],
|
||||
["begin", "ensure ; end"],
|
||||
["case nil", "when true; end"],
|
||||
[" case nil", "when true; end"],
|
||||
["case nil; when true", "end"],
|
||||
].each do
|
||||
|b, e = 'end'|
|
||||
src = ["#{b}\n", " #{e}\n"]
|
||||
k = b[/\A\S+/]
|
||||
e = e[/\A\S+/]
|
||||
k = b[/\A\s*(\S+)/, 1]
|
||||
e = e[/\A\s*(\S+)/, 1]
|
||||
|
||||
a.for("no directives with #{b}") do
|
||||
err = ["#{t.path}:2: warning: mismatched indentations at '#{e}' with '#{k}' at 1"]
|
||||
|
|
Loading…
Add table
Reference in a new issue