rubocop-rails 2.14.1 → 2.14.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: babf21479a37aa37cba8b6b8401b23ddb6532e14afd679095d456f749aca3ca0
|
4
|
+
data.tar.gz: 11a94f8219a5b9d241d68af1c3ecd69afb0a47ccf988db59d00f48caaf73dfbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02b2646080a54c50c8708cd6feeed501b5aafd7ae77d04e42ed0bf5b8779f43fa778bc3f46daec2c06474ac76f40ae144bf0afed35e5acf996c4b2213df53f89
|
7
|
+
data.tar.gz: 4b29b44608474ead97651327e5c896bfb403eadcc1deffd10730853f303e75682e3ebebed80f8b3b05c1f9f0862441845bea89135d694ecf70ee3d6c776f2a97
|
@@ -22,30 +22,30 @@ module RuboCop
|
|
22
22
|
extend AutoCorrector
|
23
23
|
include MigrationsHelper
|
24
24
|
|
25
|
-
MSG = 'Replace with `%<
|
25
|
+
MSG = 'Replace with `%<camelized_basename>s` that matches the file name.'
|
26
26
|
|
27
27
|
def on_class(node)
|
28
|
-
return
|
28
|
+
return unless migration_class?(node)
|
29
29
|
|
30
|
-
|
30
|
+
basename = basename_without_timestamp_and_suffix(processed_source.file_path)
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
class_identifier = node.identifier
|
33
|
+
camelized_basename = camelize(basename)
|
34
|
+
return if class_identifier.source.casecmp(camelized_basename).zero?
|
34
35
|
|
35
|
-
|
36
|
-
message = format(MSG, corrected_class_name: corrected_class_name)
|
36
|
+
message = format(MSG, camelized_basename: camelized_basename)
|
37
37
|
|
38
|
-
add_offense(
|
39
|
-
corrector.replace(
|
38
|
+
add_offense(class_identifier, message: message) do |corrector|
|
39
|
+
corrector.replace(class_identifier, camelized_basename)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
-
def basename_without_timestamp_and_suffix
|
46
|
-
filepath = processed_source.file_path
|
45
|
+
def basename_without_timestamp_and_suffix(filepath)
|
47
46
|
basename = File.basename(filepath, '.rb')
|
48
47
|
basename = remove_gem_suffix(basename)
|
48
|
+
|
49
49
|
basename.sub(/\A\d+_/, '')
|
50
50
|
end
|
51
51
|
|
@@ -54,17 +54,9 @@ module RuboCop
|
|
54
54
|
file_name.sub(/\..+\z/, '')
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def camelize(word)
|
58
58
|
word.split('_').map(&:capitalize).join
|
59
59
|
end
|
60
|
-
|
61
|
-
def to_snakecase(word)
|
62
|
-
word
|
63
|
-
.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
64
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
65
|
-
.tr('-', '_')
|
66
|
-
.downcase
|
67
|
-
end
|
68
60
|
end
|
69
61
|
end
|
70
62
|
end
|
@@ -54,23 +54,40 @@ module RuboCop
|
|
54
54
|
PATTERN
|
55
55
|
|
56
56
|
def on_send(node)
|
57
|
-
parent = node.parent
|
58
|
-
|
59
|
-
return unless parent&.block_type?
|
57
|
+
return unless (parent = node.parent)
|
58
|
+
return unless parent.block_type? && parent.body
|
60
59
|
|
61
60
|
exit_statements(parent.body).each do |statement_node|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
'break'
|
66
|
-
else
|
67
|
-
statement_node.method_name
|
68
|
-
end
|
61
|
+
next if in_rescue?(statement_node) || nested_block?(statement_node)
|
62
|
+
|
63
|
+
statement = statement(statement_node)
|
69
64
|
message = format(MSG, statement: statement)
|
70
65
|
|
71
66
|
add_offense(statement_node, message: message)
|
72
67
|
end
|
73
68
|
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def statement(statement_node)
|
73
|
+
if statement_node.return_type?
|
74
|
+
'return'
|
75
|
+
elsif statement_node.break_type?
|
76
|
+
'break'
|
77
|
+
else
|
78
|
+
statement_node.method_name
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def in_rescue?(statement_node)
|
83
|
+
statement_node.ancestors.find(&:rescue_type?)
|
84
|
+
end
|
85
|
+
|
86
|
+
def nested_block?(statement_node)
|
87
|
+
return false unless statement_node.break_type?
|
88
|
+
|
89
|
+
!statement_node.ancestors.find(&:block_type?).method?(:transaction)
|
90
|
+
end
|
74
91
|
end
|
75
92
|
end
|
76
93
|
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.14.
|
4
|
+
version: 2.14.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: 2022-03-
|
13
|
+
date: 2022-03-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|