rubocop-rails 2.26.1 → 2.26.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +5 -5
- data/lib/rubocop/cop/rails/compact_blank.rb +8 -4
- data/lib/rubocop/cop/rails/enum_syntax.rb +2 -0
- data/lib/rubocop/cop/rails/file_path.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_foreign_key.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -1
- data/lib/rubocop/cop/rails/reflection_class_name.rb +1 -1
- data/lib/rubocop/cop/rails/request_referer.rb +1 -1
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6d480f2ef30bba709b183d1a3b71dee6c0838ea2815975b5fd25ab5933277ad
|
4
|
+
data.tar.gz: 1d36f2779e44e1fa03437154f388bf2e865c3af810e0238f5ddc6580f024fd04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cc2521c185293872667eb2a23aaaadc4ddee8289b1f16c9fff1e6c87b9498708226a0147697acb9bcc3be69642c3f3ecc063b749056c0df1cdb065a224e4a3d
|
7
|
+
data.tar.gz: ea268a009b987a6f61008602d67a8e89659611b7469fe6c1b9c81825b5f9227391035866b2ec593e6109e91a470d607f6f4bb48fd11155b9177d59daf2301111
|
data/README.md
CHANGED
@@ -65,7 +65,7 @@ end
|
|
65
65
|
|
66
66
|
## Rails configuration tip
|
67
67
|
|
68
|
-
|
68
|
+
In Rails 6.1+, add the following `config.generators.after_generate` setting to
|
69
69
|
your `config/environments/development.rb` to apply RuboCop autocorrection to code generated by `bin/rails g`.
|
70
70
|
|
71
71
|
```ruby
|
@@ -84,6 +84,20 @@ It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsaf
|
|
84
84
|
`rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to
|
85
85
|
be incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.
|
86
86
|
|
87
|
+
In Rails 7.2+, it is recommended to use `config.generators.apply_rubocop_autocorrect_after_generate!` instead of the above setting:
|
88
|
+
|
89
|
+
```diff
|
90
|
+
# config/environments/development.rb
|
91
|
+
Rails.application.configure do
|
92
|
+
(snip)
|
93
|
+
# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
|
94
|
+
- # config.generators.apply_rubocop_autocorrect_after_generate!
|
95
|
+
+ config.generators.apply_rubocop_autocorrect_after_generate!
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
You only need to uncomment.
|
100
|
+
|
87
101
|
## The Cops
|
88
102
|
|
89
103
|
All cops are located under
|
@@ -72,13 +72,13 @@ module RuboCop
|
|
72
72
|
if (node = context.each_ancestor(:if, :rescue).first)
|
73
73
|
return false if use_redirect_to?(context)
|
74
74
|
|
75
|
-
context = node
|
75
|
+
context = node
|
76
|
+
elsif context.right_siblings.empty?
|
77
|
+
return true
|
76
78
|
end
|
79
|
+
context = context.right_siblings
|
77
80
|
|
78
|
-
|
79
|
-
return true if siblings.empty?
|
80
|
-
|
81
|
-
siblings.compact.any? do |render_candidate|
|
81
|
+
context.compact.any? do |render_candidate|
|
82
82
|
render?(render_candidate)
|
83
83
|
end
|
84
84
|
end
|
@@ -25,6 +25,8 @@ module RuboCop
|
|
25
25
|
# collection.reject { |_k, v| v.blank? }
|
26
26
|
# collection.select(&:present?)
|
27
27
|
# collection.select { |_k, v| v.present? }
|
28
|
+
# collection.filter(&:present?)
|
29
|
+
# collection.filter { |_k, v| v.present? }
|
28
30
|
#
|
29
31
|
# # good
|
30
32
|
# collection.compact_blank
|
@@ -44,7 +46,8 @@ module RuboCop
|
|
44
46
|
extend TargetRailsVersion
|
45
47
|
|
46
48
|
MSG = 'Use `%<preferred_method>s` instead.'
|
47
|
-
RESTRICT_ON_SEND = %i[reject delete_if select keep_if].freeze
|
49
|
+
RESTRICT_ON_SEND = %i[reject delete_if select filter keep_if].freeze
|
50
|
+
DESTRUCTIVE_METHODS = %i[delete_if keep_if].freeze
|
48
51
|
|
49
52
|
minimum_target_rails_version 6.1
|
50
53
|
|
@@ -64,19 +67,20 @@ module RuboCop
|
|
64
67
|
|
65
68
|
def_node_matcher :select_with_block?, <<~PATTERN
|
66
69
|
(block
|
67
|
-
(send _ {:select :keep_if})
|
70
|
+
(send _ {:select :filter :keep_if})
|
68
71
|
$(args ...)
|
69
72
|
(send
|
70
73
|
$(lvar _) :present?))
|
71
74
|
PATTERN
|
72
75
|
|
73
76
|
def_node_matcher :select_with_block_pass?, <<~PATTERN
|
74
|
-
(send _ {:select :keep_if}
|
77
|
+
(send _ {:select :filter :keep_if}
|
75
78
|
(block-pass
|
76
79
|
(sym :present?)))
|
77
80
|
PATTERN
|
78
81
|
|
79
82
|
def on_send(node)
|
83
|
+
return if target_ruby_version < 2.6 && node.method?(:filter)
|
80
84
|
return unless bad_method?(node)
|
81
85
|
|
82
86
|
range = offense_range(node)
|
@@ -120,7 +124,7 @@ module RuboCop
|
|
120
124
|
end
|
121
125
|
|
122
126
|
def preferred_method(node)
|
123
|
-
|
127
|
+
DESTRUCTIVE_METHODS.include?(node.method_name) ? 'compact_blank!' : 'compact_blank'
|
124
128
|
end
|
125
129
|
end
|
126
130
|
end
|
@@ -17,8 +17,10 @@ module RuboCop
|
|
17
17
|
#
|
18
18
|
class EnumSyntax < Base
|
19
19
|
extend AutoCorrector
|
20
|
+
extend TargetRubyVersion
|
20
21
|
extend TargetRailsVersion
|
21
22
|
|
23
|
+
minimum_target_ruby_version 3.0
|
22
24
|
minimum_target_rails_version 7.0
|
23
25
|
|
24
26
|
MSG = 'Enum defined with keyword arguments in `%<enum>s` enum declaration. Use positional arguments instead.'
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
97
97
|
return unless node.arguments.any? { |e| rails_root_nodes?(e) }
|
98
98
|
|
99
99
|
register_offense(node, require_to_s: true) do |corrector|
|
100
|
-
autocorrect_file_join(corrector, node)
|
100
|
+
autocorrect_file_join(corrector, node) unless node.first_argument.array_type?
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
40
40
|
def on_send(node)
|
41
41
|
association_with_foreign_key(node) do |type, name, options, foreign_key_pair, foreign_key|
|
42
42
|
if redundant?(node, type, name, options, foreign_key)
|
43
|
-
add_offense(foreign_key_pair
|
43
|
+
add_offense(foreign_key_pair) do |corrector|
|
44
44
|
range = range_with_surrounding_space(foreign_key_pair.source_range, side: :left)
|
45
45
|
range = range_with_surrounding_comma(range, :left)
|
46
46
|
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
return if reflection_class_name.value.send_type? && reflection_class_name.value.receiver.nil?
|
44
44
|
return if reflection_class_name.value.lvar_type? && str_assigned?(reflection_class_name)
|
45
45
|
|
46
|
-
add_offense(reflection_class_name
|
46
|
+
add_offense(reflection_class_name) do |corrector|
|
47
47
|
autocorrect(corrector, reflection_class_name)
|
48
48
|
end
|
49
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.26.
|
4
|
+
version: 2.26.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-09-
|
13
|
+
date: 2024-09-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -265,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
265
265
|
- !ruby/object:Gem::Version
|
266
266
|
version: '0'
|
267
267
|
requirements: []
|
268
|
-
rubygems_version: 3.5.
|
268
|
+
rubygems_version: 3.5.16
|
269
269
|
signing_key:
|
270
270
|
specification_version: 4
|
271
271
|
summary: Automatic Rails code style checking tool.
|