Skip to content

Commit 2a44746

Browse files
authored
Merge pull request #1479 from Earlopain/schema-comment-local-var
[Fix #1477] Fix an error for `Rails/SchemaComment` when the comment is passed as a local variable
2 parents 9196e3e + 43427f6 commit 2a44746

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1477](https://github.com/rubocop/rubocop-rails/issues/1477): Fix an error for `Rails/SchemaComment` when the comment is passed as a local variable. ([@earlopain][])

lib/rubocop/cop/rails/schema_comment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SchemaComment < Base
3939

4040
# @!method comment_present?(node)
4141
def_node_matcher :comment_present?, <<~PATTERN
42-
(hash <(pair {(sym :comment) (str "comment")} (_ !blank?)) ...>)
42+
(hash <(pair {(sym :comment) (str "comment")} !{nil (str blank?)}) ...>)
4343
PATTERN
4444

4545
# @!method add_column?(node)

spec/rubocop/cop/rails/schema_comment_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,14 @@
142142
end
143143
RUBY
144144
end
145+
146+
it 'does not register an offense when the comment is a local variable' do
147+
expect_no_offenses(<<~RUBY)
148+
create_table :users, comment: 'Table' do |t|
149+
i_am_a_comment = 'I am a column'
150+
t.integer :column, comment: i_am_a_comment
151+
end
152+
RUBY
153+
end
145154
end
146155
end

0 commit comments

Comments
 (0)