rubocop-obsession 0.1.14 → 0.1.15
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 +2 -2
- data/config/default.yml +4 -0
- data/lib/rubocop/cop/obsession/graphql/mutation_name.rb +0 -1
- data/lib/rubocop/cop/obsession/method_order.rb +111 -27
- data/lib/rubocop/cop/obsession/no_break_or_next.rb +0 -1
- data/lib/rubocop/cop/obsession/no_paragraphs.rb +0 -1
- data/lib/rubocop/cop/obsession/no_todos.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/callback_one_method.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/fully_defined_json_field.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/migration_belongs_to.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/no_callback_conditions.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/private_callback.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/safety_assured_comment.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/service_name.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/service_perform_method.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/short_after_commit.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/short_validate.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/validate_one_field.rb +0 -1
- data/lib/rubocop/cop/obsession/rails/validation_method_name.rb +0 -1
- data/lib/rubocop/cop/obsession/rspec/describe_public_method.rb +0 -1
- data/lib/rubocop/cop/obsession/rspec/empty_line_after_final_let.rb +0 -1
- data/lib/rubocop/cop/obsession/too_many_paragraphs.rb +0 -1
- data/lib/rubocop/obsession/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be68e2beb303a311848858498767c76c03cc98031d8716bc27a702c3e2d0bb01
|
4
|
+
data.tar.gz: 0e867c196f843e6c206794e9938e0e88a779b8b231f51b43f4aeed02d6331efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa035279001455509c1a4ee73d1aeae9e418733471691270c0c9627371f3ebd24415db377985ca6ff1f583e9843a65712be9ff9d640cc60643b2197b12f3e51
|
7
|
+
data.tar.gz: 90a7ed2c98377e3367ac0a177629c8e83a19b56cc294ddbadd260a3d67ce941a95b26f626401904078753822a00ae17babbb95f1c88bd6c128646917423c5908
|
data/README.md
CHANGED
@@ -9,8 +9,8 @@ There are some lower-level cops as well.
|
|
9
9
|
Use the provided cops as is, or as inspiration to build custom cops aligned
|
10
10
|
with your project's best practices.
|
11
11
|
|
12
|
-
Does your project have any cool custom cops that
|
13
|
-
|
12
|
+
Does your project have any cool custom cops that others might benefit from?
|
13
|
+
Then please open a PR!
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
data/config/default.yml
CHANGED
@@ -6,9 +6,8 @@ module RuboCop
|
|
6
6
|
# This cop checks for private/protected methods that are not ordered
|
7
7
|
# correctly. It supports autocorrect.
|
8
8
|
#
|
9
|
-
# Code should read from top to bottom
|
10
|
-
#
|
11
|
-
# Private/protected methods should follow that rule.
|
9
|
+
# Code should read from top to bottom. Private/protected methods should
|
10
|
+
# follow that rule.
|
12
11
|
#
|
13
12
|
# Note 1: public methods do not have to follow that rule, and can be
|
14
13
|
# defined in any order the developer wants, like by order of importance.
|
@@ -20,44 +19,121 @@ module RuboCop
|
|
20
19
|
# Note 2: method order cannot be computed for methods called by `send`,
|
21
20
|
# metaprogramming, private methods called by superclasses or modules,
|
22
21
|
# etc. This cop's suggestions and autocorrections may be slightly off for
|
23
|
-
# these
|
22
|
+
# these cases.
|
24
23
|
#
|
25
24
|
# Note 3: for simplicity, protected methods do not have to follow that
|
26
25
|
# rule if there are both a protected section and a private section.
|
27
26
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
27
|
+
# @example EnforcedStyle: drill_down (default)
|
28
|
+
# In this style, methods should be defined in the same order as the
|
29
|
+
# order when they are first mentioned. This means that a called method
|
30
|
+
# is defined below the caller method as immediately as possible. In
|
31
|
+
# other words, you go to the bottom of the method call tree before
|
32
|
+
# going back up. See the second example.
|
32
33
|
#
|
33
|
-
#
|
34
|
+
# This style is similar to the code example provided in the "Reading
|
35
|
+
# Code from Top to Bottom: The Stepdown Rule" chapter from Robert C.
|
36
|
+
# Martin's "Clean Code" book, but diverges from it in that it drills
|
37
|
+
# down to the bottom of the call tree as much as possible.
|
34
38
|
#
|
35
39
|
# # bad
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
+
# class Foo
|
41
|
+
# def perform
|
42
|
+
# return if method_a?
|
43
|
+
# method_b
|
44
|
+
# method_c
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# private
|
48
|
+
#
|
49
|
+
# def method_c; ...; end
|
50
|
+
# def method_b; ...; end
|
51
|
+
# def method_a?; ...; end
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# # good
|
55
|
+
# class Foo
|
56
|
+
# def perform
|
57
|
+
# return if method_a?
|
58
|
+
# method_b
|
59
|
+
# method_c
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# private
|
63
|
+
#
|
64
|
+
# def method_a?; ...; end
|
65
|
+
# def method_b; ...; end
|
66
|
+
# def method_c; ...; end
|
40
67
|
# end
|
41
68
|
#
|
42
|
-
#
|
69
|
+
# # bad
|
70
|
+
# class Foo
|
71
|
+
# def perform
|
72
|
+
# method_a
|
73
|
+
# method_b
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# private
|
43
77
|
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
78
|
+
# def method_a; method_c; end
|
79
|
+
# def method_b; method_c; end
|
80
|
+
# def method_c; ...; end
|
81
|
+
# end
|
47
82
|
#
|
48
83
|
# # good
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
84
|
+
# class Foo
|
85
|
+
# def perform
|
86
|
+
# method_a
|
87
|
+
# method_b
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# private
|
91
|
+
#
|
92
|
+
# def method_a; method_c; end
|
93
|
+
# def method_c; ...; end
|
94
|
+
# def method_b; method_c; end
|
53
95
|
# end
|
54
96
|
#
|
55
|
-
#
|
97
|
+
# @example EnforcedStyle: step_down
|
98
|
+
# In this style, common called methods (which tend to have a lower
|
99
|
+
# level of abstraction) are defined after the group of methods that
|
100
|
+
# calls them (these caller methods tend to have a higher level of
|
101
|
+
# abstraction). The idea is to gradually descend one level of
|
102
|
+
# abstraction at a time.
|
103
|
+
#
|
104
|
+
# This style adheres more strictly to the code example provided in the
|
105
|
+
# "Reading Code from Top to Bottom: The Stepdown Rule" chapter from
|
106
|
+
# Robert C. Martin's "Clean Code" book.
|
56
107
|
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
108
|
+
# # bad
|
109
|
+
# class Foo
|
110
|
+
# def perform
|
111
|
+
# method_a
|
112
|
+
# method_b
|
113
|
+
# end
|
114
|
+
#
|
115
|
+
# private
|
116
|
+
#
|
117
|
+
# def method_a; method_c; end
|
118
|
+
# def method_c; ...; end
|
119
|
+
# def method_b; method_c; end
|
120
|
+
# end
|
121
|
+
#
|
122
|
+
# # good
|
123
|
+
# class Foo
|
124
|
+
# def perform
|
125
|
+
# method_a
|
126
|
+
# method_b
|
127
|
+
# end
|
128
|
+
#
|
129
|
+
# private
|
130
|
+
#
|
131
|
+
# def method_a; method_c; end
|
132
|
+
# def method_b; method_c; end
|
133
|
+
# def method_c; ...; end
|
134
|
+
# end
|
60
135
|
class MethodOrder < Base
|
136
|
+
include ConfigurableEnforcedStyle
|
61
137
|
include Helpers
|
62
138
|
include CommentsHelp
|
63
139
|
include VisibilityHelp
|
@@ -183,10 +259,14 @@ module RuboCop
|
|
183
259
|
def ordered_private_methods(node)
|
184
260
|
ast_node = node.value
|
185
261
|
method_name = should_ignore?(ast_node) ? nil : ast_node.method_name
|
186
|
-
|
187
262
|
next_names = node.children.flat_map { |child| ordered_private_methods(child) }
|
188
263
|
|
189
|
-
|
264
|
+
common_methods =
|
265
|
+
drill_down_style? ? [] : next_names.tally.select { |_, size| size > 1 }.keys
|
266
|
+
|
267
|
+
unique_methods = next_names - common_methods
|
268
|
+
|
269
|
+
([method_name] + unique_methods + common_methods).compact.uniq
|
190
270
|
end
|
191
271
|
|
192
272
|
def should_ignore?(ast_node)
|
@@ -194,6 +274,10 @@ module RuboCop
|
|
194
274
|
!@called_methods.include?(ast_node)
|
195
275
|
end
|
196
276
|
|
277
|
+
def drill_down_style?
|
278
|
+
style == :drill_down
|
279
|
+
end
|
280
|
+
|
197
281
|
def build_private_methods
|
198
282
|
@private_methods = @methods.keys.intersection(@ordered_private_methods)
|
199
283
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-obsession
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerome Dalbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|