Skip to content

Commit 955e404

Browse files
committed
Enable Layout/RedundantLineBreak cop
Follow up rubocop/rubocop#9678 and #752 (comment).
1 parent e007571 commit 955e404

File tree

67 files changed

+228
-574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+228
-574
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ Layout/ClassStructure:
9090
- protected_methods
9191
- private_methods
9292

93+
Layout/RedundantLineBreak:
94+
Enabled: true
95+
9396
# Trailing white space is meaningful in code examples
9497
Layout/TrailingWhitespace:
9598
AllowInHeredoc: true

Rakefile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ end
3636
desc 'Run RuboCop over itself'
3737
RuboCop::RakeTask.new(:internal_investigation)
3838

39-
task default: %i[
40-
documentation_syntax_check
41-
spec
42-
internal_investigation
43-
]
39+
task default: %i[documentation_syntax_check spec internal_investigation]
4440

4541
desc 'Generate a new cop template'
4642
task :new_cop, [:cop] do |_task, args|
@@ -55,9 +51,7 @@ task :new_cop, [:cop] do |_task, args|
5551

5652
generator.write_source
5753
generator.write_spec
58-
generator.inject_require(
59-
root_file_path: 'lib/rubocop/cop/rails_cops.rb'
60-
)
54+
generator.inject_require(root_file_path: 'lib/rubocop/cop/rails_cops.rb')
6155
generator.inject_config(config_file_path: 'config/default.yml')
6256

6357
puts generator.todo

lib/rubocop/cop/mixin/active_record_helper.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ def table_name(class_node)
4848

4949
class_nodes = class_node.defined_module.each_node
5050
namespaces = class_node.each_ancestor(:class, :module).map(&:identifier)
51-
[*class_nodes, *namespaces]
52-
.reverse
53-
.map { |node| node.children[1] }.join('_')
54-
.tableize
51+
[*class_nodes, *namespaces].reverse.map { |node| node.children[1] }.join('_').tableize
5552
end
5653

5754
# Resolve relation into column name.

lib/rubocop/cop/mixin/active_record_migrations_helper.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ module ActiveRecordMigrationsHelper
1010
bigint binary boolean date datetime decimal float integer json string
1111
text time timestamp virtual
1212
].freeze
13-
RAILS_ABSTRACT_SCHEMA_DEFINITIONS_HELPERS = %i[
14-
column references belongs_to primary_key numeric
15-
].freeze
13+
RAILS_ABSTRACT_SCHEMA_DEFINITIONS_HELPERS = %i[column references belongs_to primary_key numeric].freeze
1614
POSTGRES_SCHEMA_DEFINITIONS = %i[
1715
bigserial bit bit_varying cidr citext daterange hstore inet interval
1816
int4range int8range jsonb ltree macaddr money numrange oid point line

lib/rubocop/cop/mixin/index_method.rb

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ def execute_correction(corrector, node, correction)
9898

9999
captures = extract_captures(correction.match)
100100
correction.set_new_arg_name(captures.transformed_argname, corrector)
101-
correction.set_new_body_expression(
102-
captures.transforming_body_expr,
103-
corrector
104-
)
101+
correction.set_new_body_expression(captures.transforming_body_expr, corrector)
105102
end
106103

107104
# Internal helper class to hold match data
@@ -110,8 +107,7 @@ def execute_correction(corrector, node, correction)
110107
:transforming_body_expr
111108
) do
112109
def noop_transformation?
113-
transforming_body_expr.lvar_type? &&
114-
transforming_body_expr.children == [transformed_argname]
110+
transforming_body_expr.lvar_type? && transforming_body_expr.children == [transformed_argname]
115111
end
116112
end
117113

@@ -157,17 +153,11 @@ def set_new_method_name(new_method_name, corrector)
157153
end
158154

159155
def set_new_arg_name(transformed_argname, corrector)
160-
corrector.replace(
161-
block_node.arguments.loc.expression,
162-
"|#{transformed_argname}|"
163-
)
156+
corrector.replace(block_node.arguments.loc.expression, "|#{transformed_argname}|")
164157
end
165158

166159
def set_new_body_expression(transforming_body_expr, corrector)
167-
corrector.replace(
168-
block_node.body.loc.expression,
169-
transforming_body_expr.loc.expression.source
170-
)
160+
corrector.replace(block_node.body.loc.expression, transforming_body_expr.loc.expression.source)
171161
end
172162
end
173163
end

lib/rubocop/cop/rails/active_record_aliases.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ class ActiveRecordAliases < Base
2121

2222
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
2323

24-
ALIASES = {
25-
update_attributes: :update,
26-
update_attributes!: :update!
27-
}.freeze
24+
ALIASES = { update_attributes: :update, update_attributes!: :update! }.freeze
2825

2926
RESTRICT_ON_SEND = ALIASES.keys.freeze
3027

lib/rubocop/cop/rails/active_record_override.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@ module Rails
2525
# end
2626
#
2727
class ActiveRecordOverride < Base
28-
MSG =
29-
'Use %<prefer>s callbacks instead of overriding the Active Record ' \
30-
'method `%<bad>s`.'
28+
MSG = 'Use %<prefer>s callbacks instead of overriding the Active Record method `%<bad>s`.'
3129
BAD_METHODS = %i[create destroy save update].freeze
32-
ACTIVE_RECORD_CLASSES = %w[ApplicationRecord ActiveModel::Base
33-
ActiveRecord::Base].freeze
30+
ACTIVE_RECORD_CLASSES = %w[ApplicationRecord ActiveModel::Base ActiveRecord::Base].freeze
3431

3532
def on_def(node)
3633
return unless BAD_METHODS.include?(node.method_name)

lib/rubocop/cop/rails/add_column_index.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ def on_send(node)
5353
private
5454

5555
def index_range(pair_node)
56-
range_with_surrounding_comma(
57-
range_with_surrounding_space(pair_node.loc.expression, side: :left),
58-
:left
59-
)
56+
range_with_surrounding_comma(range_with_surrounding_space(pair_node.loc.expression, side: :left), :left)
6057
end
6158
end
6259
end

lib/rubocop/cop/rails/blank.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ class Blank < Base
6363

6464
MSG_NIL_OR_EMPTY = 'Use `%<prefer>s` instead of `%<current>s`.'
6565
MSG_NOT_PRESENT = 'Use `%<prefer>s` instead of `%<current>s`.'
66-
MSG_UNLESS_PRESENT = 'Use `if %<prefer>s` instead of ' \
67-
'`%<current>s`.'
66+
MSG_UNLESS_PRESENT = 'Use `if %<prefer>s` instead of `%<current>s`.'
6867
RESTRICT_ON_SEND = %i[!].freeze
6968

7069
# `(send nil $_)` is not actually a valid match for an offense. Nodes

lib/rubocop/cop/rails/bulk_change_table.rb

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,13 @@ class BulkChangeTable < Base
111111
remove_timestamps
112112
].freeze
113113

114-
MYSQL_COMBINABLE_TRANSFORMATIONS = %i[
115-
rename
116-
index
117-
remove_index
118-
].freeze
114+
MYSQL_COMBINABLE_TRANSFORMATIONS = %i[rename index remove_index].freeze
119115

120-
MYSQL_COMBINABLE_ALTER_METHODS = %i[
121-
rename_column
122-
add_index
123-
remove_index
124-
].freeze
116+
MYSQL_COMBINABLE_ALTER_METHODS = %i[rename_column add_index remove_index].freeze
125117

126-
POSTGRESQL_COMBINABLE_TRANSFORMATIONS = %i[
127-
change_default
128-
].freeze
118+
POSTGRESQL_COMBINABLE_TRANSFORMATIONS = %i[change_default].freeze
129119

130-
POSTGRESQL_COMBINABLE_ALTER_METHODS = %i[
131-
change_column_default
132-
].freeze
120+
POSTGRESQL_COMBINABLE_ALTER_METHODS = %i[change_column_default].freeze
133121

134122
def on_def(node)
135123
return unless support_bulk_alter?
@@ -186,8 +174,7 @@ def include_bulk_options?(node)
186174
options = node.arguments[1]
187175
return false unless options
188176

189-
options.hash_type? &&
190-
options.keys.any? { |key| key.sym_type? && key.value == :bulk }
177+
options.hash_type? && options.keys.any? { |key| key.sym_type? && key.value == :bulk }
191178
end
192179

193180
def database
@@ -237,8 +224,7 @@ def support_bulk_alter?
237224
end
238225

239226
def call_to_combinable_alter_method?(child_node)
240-
child_node.send_type? &&
241-
combinable_alter_methods.include?(child_node.method_name)
227+
child_node.send_type? && combinable_alter_methods.include?(child_node.method_name)
242228
end
243229

244230
def combinable_alter_methods

0 commit comments

Comments
 (0)