Skip to content

Commit

Permalink
[ruby/prism] Warn on frozen_string_literal after tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Mar 18, 2024
1 parent 8514785 commit 548203e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions prism/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ warnings:
- DUPLICATED_HASH_KEY
- DUPLICATED_WHEN_CLAUSE
- FLOAT_OUT_OF_RANGE
- IGNORED_FROZEN_STRING_LITERAL
- INTEGER_IN_FLIP_FLOP
- INVALID_CHARACTER
- INVALID_NUMBERED_REFERENCE
Expand Down
6 changes: 4 additions & 2 deletions prism/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -7391,8 +7391,10 @@ parser_lex_magic_comment(pm_parser_t *parser, bool semantic_token_seen) {

// We only want to handle frozen string literal comments if it's before
// any semantic tokens have been seen.
if (!semantic_token_seen) {
if (key_length == 21 && pm_strncasecmp(key_source, (const uint8_t *) "frozen_string_literal", 21) == 0) {
if (key_length == 21 && pm_strncasecmp(key_source, (const uint8_t *) "frozen_string_literal", 21) == 0) {
if (semantic_token_seen) {
pm_parser_warn_token(parser, &parser->current, PM_WARN_IGNORED_FROZEN_STRING_LITERAL);
} else {
parser_lex_magic_comment_frozen_string_literal_value(parser, value_start, value_end);
}
}
Expand Down
1 change: 1 addition & 0 deletions prism/templates/src/diagnostic.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
[PM_WARN_EQUAL_IN_CONDITIONAL] = { "found '= literal' in conditional, should be ==", PM_WARNING_LEVEL_DEFAULT },
[PM_WARN_END_IN_METHOD] = { "END in method; use at_exit", PM_WARNING_LEVEL_DEFAULT },
[PM_WARN_FLOAT_OUT_OF_RANGE] = { "Float %.*s%s out of range", PM_WARNING_LEVEL_VERBOSE },
[PM_WARN_IGNORED_FROZEN_STRING_LITERAL] = { "'frozen_string_literal' is ignored after any tokens", PM_WARNING_LEVEL_VERBOSE },
[PM_WARN_INTEGER_IN_FLIP_FLOP] = { "integer literal in flip-flop", PM_WARNING_LEVEL_DEFAULT },
[PM_WARN_INVALID_CHARACTER] = { "invalid character syntax; use %s%s%s", PM_WARNING_LEVEL_DEFAULT },
[PM_WARN_INVALID_SHAREABLE_CONSTANT_VALUE] = { "invalid value for shareable_constant_value: %.*s", PM_WARNING_LEVEL_VERBOSE },
Expand Down

0 comments on commit 548203e

Please sign in to comment.