rubocop-rails 2.23.0 → 2.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -9
- data/config/default.yml +2 -1
- data/lib/rubocop/cop/mixin/active_record_helper.rb +6 -1
- data/lib/rubocop/cop/rails/content_tag.rb +1 -1
- data/lib/rubocop/cop/rails/dangerous_column_names.rb +1 -2
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration.rb +1 -1
- data/lib/rubocop/cop/rails/where_exists.rb +3 -3
- data/lib/rubocop/cop/rails/where_not.rb +2 -1
- data/lib/rubocop/rails/schema_loader.rb +5 -15
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24df033ffce85b621be414aaec3b62b7b5ac8613e5fc55ce54d58a4be9c22c8b
|
4
|
+
data.tar.gz: 328d994492ff8e6b1f3634e62a1fefaa4e7f3e894492d9f65bc141c7f49e8dac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2be5897e47aa2e661a93ece9254578962af30ea0bad2f0303a92f63d846cc37bf7f85d9338e385b29a489202ce762ee5f077dd355443e24695f7b4869f4fd902
|
7
|
+
data.tar.gz: 56db6c7a79ce813778ec0d6fcdbf57de7bdf7ea5b7463c78a58f1919c46b84c3edbbc8f8f02de123439a33df8bdf427b8e29a0d82d51ae624ace0890c8e8158f
|
data/README.md
CHANGED
@@ -66,17 +66,15 @@ end
|
|
66
66
|
## Rails configuration tip
|
67
67
|
|
68
68
|
If you are using Rails 6.1 or newer, add the following `config.generators.after_generate` setting to
|
69
|
-
your config/
|
69
|
+
your `config/environments/development.rb` to apply RuboCop autocorrection to code generated by `bin/rails g`.
|
70
70
|
|
71
71
|
```ruby
|
72
|
-
# config/
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
|
79
|
-
end
|
72
|
+
# config/environments/development.rb
|
73
|
+
Rails.application.configure do
|
74
|
+
config.generators.after_generate do |files|
|
75
|
+
parsable_files = files.filter { |file| file.end_with?('.rb') }
|
76
|
+
unless parsable_files.empty?
|
77
|
+
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
|
80
78
|
end
|
81
79
|
end
|
82
80
|
end
|
data/config/default.yml
CHANGED
@@ -445,9 +445,10 @@ Rails/EnvironmentVariableAccess:
|
|
445
445
|
# TODO: Set to `pending` status in RuboCop Rails 2 series when migration doc will be written.
|
446
446
|
Enabled: false
|
447
447
|
VersionAdded: '2.10'
|
448
|
-
VersionChanged: '2.
|
448
|
+
VersionChanged: '2.24'
|
449
449
|
Include:
|
450
450
|
- app/**/*.rb
|
451
|
+
- config/initializers/**/*.rb
|
451
452
|
- lib/**/*.rb
|
452
453
|
Exclude:
|
453
454
|
- lib/**/*.rake
|
@@ -39,7 +39,12 @@ module RuboCop
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def schema
|
42
|
-
RuboCop
|
42
|
+
# For compatibility with RuboCop 1.61.0 or lower.
|
43
|
+
if respond_to?(:parser_engine)
|
44
|
+
RuboCop::Rails::SchemaLoader.load(target_ruby_version, parser_engine)
|
45
|
+
else
|
46
|
+
RuboCop::Rails::SchemaLoader.load(target_ruby_version, :parser_whitequark)
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
50
|
def table_name(class_node)
|
@@ -7,7 +7,7 @@ module RuboCop
|
|
7
7
|
#
|
8
8
|
# NOTE: Allow `tag` when the first argument is a variable because
|
9
9
|
# `tag(name)` is simpler rather than `tag.public_send(name)`.
|
10
|
-
# And this cop will be renamed to something like `LegacyTag` in the future. (e.g. RuboCop Rails
|
10
|
+
# And this cop will be renamed to something like `LegacyTag` in the future. (e.g. RuboCop Rails 3.0)
|
11
11
|
#
|
12
12
|
# @example
|
13
13
|
# # bad
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
time
|
32
32
|
].to_set.freeze
|
33
33
|
|
34
|
-
# Generated from `ActiveRecord::AttributeMethods.dangerous_attribute_methods` on activerecord 7.1.
|
34
|
+
# Generated from `ActiveRecord::AttributeMethods.dangerous_attribute_methods` on activerecord 7.1.3.
|
35
35
|
# rubocop:disable Metrics/CollectionLiteralLength
|
36
36
|
DANGEROUS_COLUMN_NAMES = %w[
|
37
37
|
__callbacks
|
@@ -290,7 +290,6 @@ module RuboCop
|
|
290
290
|
new_record
|
291
291
|
no_touching
|
292
292
|
normalize_reflection_attribute
|
293
|
-
object_id
|
294
293
|
partial_inserts
|
295
294
|
partial_updates
|
296
295
|
perform_validations
|
@@ -59,7 +59,7 @@ module RuboCop
|
|
59
59
|
return if node.method?(:first)
|
60
60
|
|
61
61
|
where_loc = node.receiver.loc.selector
|
62
|
-
first_loc = range_between(node.
|
62
|
+
first_loc = range_between(node.receiver.source_range.end_pos, node.loc.selector.end_pos)
|
63
63
|
|
64
64
|
corrector.replace(where_loc, 'find_by')
|
65
65
|
corrector.replace(first_loc, '')
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
67
67
|
return unless convertable_args?(args)
|
68
68
|
|
69
69
|
range = correction_range(node)
|
70
|
-
good_method = build_good_method(args,
|
70
|
+
good_method = build_good_method(args, dot: node.loc.dot)
|
71
71
|
message = format(MSG, good_method: good_method, bad_method: range.source)
|
72
72
|
|
73
73
|
add_offense(range, message: message) do |corrector|
|
@@ -109,11 +109,11 @@ module RuboCop
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
def build_good_method(args,
|
112
|
+
def build_good_method(args, dot:)
|
113
113
|
if exists_style?
|
114
114
|
build_good_method_exists(args)
|
115
115
|
elsif where_style?
|
116
|
-
build_good_method_where(args,
|
116
|
+
build_good_method_where(args, dot&.source || '.')
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -46,7 +46,7 @@ module RuboCop
|
|
46
46
|
column_and_value = extract_column_and_value(template_node, value_node)
|
47
47
|
return unless column_and_value
|
48
48
|
|
49
|
-
good_method = build_good_method(node.loc.dot
|
49
|
+
good_method = build_good_method(node.loc.dot&.source, *column_and_value)
|
50
50
|
message = format(MSG, good_method: good_method)
|
51
51
|
|
52
52
|
add_offense(range, message: message) do |corrector|
|
@@ -88,6 +88,7 @@ module RuboCop
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def build_good_method(dot, column, value)
|
91
|
+
dot ||= '.'
|
91
92
|
if column.include?('.')
|
92
93
|
table, column = column.split('.')
|
93
94
|
|
@@ -12,10 +12,10 @@ module RuboCop
|
|
12
12
|
# So a cop that uses the loader should handle `nil` properly.
|
13
13
|
#
|
14
14
|
# @return [Schema, nil]
|
15
|
-
def load(target_ruby_version)
|
15
|
+
def load(target_ruby_version, parser_engine)
|
16
16
|
return @load if defined?(@load)
|
17
17
|
|
18
|
-
@load = load!(target_ruby_version)
|
18
|
+
@load = load!(target_ruby_version, parser_engine)
|
19
19
|
end
|
20
20
|
|
21
21
|
def reset!
|
@@ -38,23 +38,13 @@ module RuboCop
|
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
-
def load!(target_ruby_version)
|
41
|
+
def load!(target_ruby_version, parser_engine)
|
42
42
|
path = db_schema_path
|
43
43
|
return unless path
|
44
44
|
|
45
|
-
ast =
|
46
|
-
Schema.new(ast) if ast
|
47
|
-
end
|
48
|
-
|
49
|
-
def parse(path, target_ruby_version)
|
50
|
-
klass_name = :"Ruby#{target_ruby_version.to_s.sub('.', '')}"
|
51
|
-
klass = ::Parser.const_get(klass_name)
|
52
|
-
parser = klass.new(RuboCop::AST::Builder.new)
|
45
|
+
ast = RuboCop::ProcessedSource.new(File.read(path), target_ruby_version, path, parser_engine: parser_engine).ast
|
53
46
|
|
54
|
-
|
55
|
-
buffer.source = path.read
|
56
|
-
|
57
|
-
parser.parse(buffer)
|
47
|
+
Schema.new(ast) if ast
|
58
48
|
end
|
59
49
|
end
|
60
50
|
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.
|
4
|
+
version: 2.24.0
|
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:
|
13
|
+
date: 2024-03-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.
|
69
|
+
version: 1.31.1
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '2.0'
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
requirements:
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 1.
|
79
|
+
version: 1.31.1
|
80
80
|
- - "<"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.0'
|
@@ -245,7 +245,7 @@ metadata:
|
|
245
245
|
homepage_uri: https://docs.rubocop.org/rubocop-rails/
|
246
246
|
changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
|
247
247
|
source_code_uri: https://github.com/rubocop/rubocop-rails/
|
248
|
-
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.
|
248
|
+
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.24/
|
249
249
|
bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
|
250
250
|
rubygems_mfa_required: 'true'
|
251
251
|
post_install_message:
|
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: '0'
|
265
265
|
requirements: []
|
266
|
-
rubygems_version: 3.
|
266
|
+
rubygems_version: 3.3.26
|
267
267
|
signing_key:
|
268
268
|
specification_version: 4
|
269
269
|
summary: Automatic Rails code style checking tool.
|