rubocop-obsession 0.1.4 → 0.1.6
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 +3 -0
- data/config/default.yml +2 -4
- data/lib/rubocop/cop/obsession/graphql/mutation_name.rb +1 -1
- data/lib/rubocop/cop/obsession/method_order.rb +8 -30
- data/lib/rubocop/cop/obsession/no_break_or_next.rb +1 -1
- data/lib/rubocop/cop/obsession/no_paragraphs.rb +2 -2
- data/lib/rubocop/cop/obsession/no_todos.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/callback_one_method.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/fully_defined_json_field.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/migration_belongs_to.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/no_callback_conditions.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/private_callback.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/safety_assured_comment.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/short_after_commit.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/short_validate.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/validate_one_field.rb +1 -1
- data/lib/rubocop/cop/obsession/rails/validation_method_name.rb +1 -1
- data/lib/rubocop/cop/obsession/rspec/describe_public_method.rb +1 -1
- data/lib/rubocop/cop/obsession/too_many_paragraphs.rb +4 -4
- 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: 4b1e6edfacbf86e2ac264de49f2ac818af6ee693c6cabe9865894b556953e3ad
|
4
|
+
data.tar.gz: 9d523c4878734ef93c3b0052622ffe49e1a3913505963a91fe10327ddac17660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eed54a03536307d0bfdda7b43b8346306420d1037068921b238f67fbd938c276d84f5802f70ce42bc0a26f3d46f399a5db9e3864ac73adfc01e6e5911f8f5f83
|
7
|
+
data.tar.gz: bc7e712ec48bbe05f8419754a9b9d1f443973e154ca4525dc0712a3c0576be840b66c65e67c8a206a12a628af97d703c7b84d50a15951dc8446dc1bda5c5461e
|
data/README.md
CHANGED
@@ -9,6 +9,9 @@ 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 you think others might benefit
|
13
|
+
from? Then please open a PR!
|
14
|
+
|
12
15
|
## Installation
|
13
16
|
|
14
17
|
Install the gem:
|
data/config/default.yml
CHANGED
@@ -3,7 +3,7 @@ Obsession/MethodOrder:
|
|
3
3
|
Obsession/NoBreakOrNext:
|
4
4
|
Enabled: false
|
5
5
|
Exclude:
|
6
|
-
- 'script
|
6
|
+
- 'script/**/*'
|
7
7
|
Obsession/NoParagraphs:
|
8
8
|
Enabled: false
|
9
9
|
Exclude:
|
@@ -15,7 +15,7 @@ Obsession/TooManyParagraphs:
|
|
15
15
|
Enabled: false
|
16
16
|
Exclude:
|
17
17
|
- 'db/migrate/*'
|
18
|
-
- 'script
|
18
|
+
- 'script/**/*'
|
19
19
|
- 'spec/**/*'
|
20
20
|
|
21
21
|
Obsession/Graphql/MutationName:
|
@@ -66,8 +66,6 @@ Obsession/Rails/ServiceName:
|
|
66
66
|
- 'app/jobs/**/*'
|
67
67
|
Exclude:
|
68
68
|
- 'app/jobs/application_job.rb'
|
69
|
-
- 'app/jobs/scheduled/scheduled_job.rb'
|
70
|
-
- '**/*events/**'
|
71
69
|
Obsession/Rails/ServicePerformMethod:
|
72
70
|
Enabled: true
|
73
71
|
Include:
|
@@ -56,7 +56,7 @@ module RuboCop
|
|
56
56
|
# def method_c; ...; end
|
57
57
|
class MethodOrder < Base
|
58
58
|
include Helpers
|
59
|
-
include
|
59
|
+
include CommentsHelp
|
60
60
|
include VisibilityHelp
|
61
61
|
extend AutoCorrector
|
62
62
|
|
@@ -209,40 +209,18 @@ module RuboCop
|
|
209
209
|
|
210
210
|
def autocorrect(corrector, method, previous_method)
|
211
211
|
previous_method_range = source_range_with_comment(previous_method)
|
212
|
+
if buffer.source[previous_method_range.end_pos + 1] == "\n"
|
213
|
+
previous_method_range = previous_method_range.adjust(end_pos: 1)
|
214
|
+
end
|
215
|
+
|
212
216
|
method_range = source_range_with_comment(method)
|
217
|
+
if buffer.source[method_range.begin_pos - 1] == "\n"
|
218
|
+
method_range = method_range.adjust(end_pos: 1)
|
219
|
+
end
|
213
220
|
|
214
221
|
corrector.insert_after(previous_method_range, method_range.source)
|
215
222
|
corrector.remove(method_range)
|
216
223
|
end
|
217
|
-
|
218
|
-
def source_range_with_comment(node)
|
219
|
-
range_between(start_position_with_comment(node), end_position(node) + 1)
|
220
|
-
end
|
221
|
-
|
222
|
-
def start_position_with_comment(node)
|
223
|
-
first_comment = nil
|
224
|
-
|
225
|
-
(node.first_line - 1).downto(1) do |annotation_line|
|
226
|
-
comment = processed_source.comment_at_line(annotation_line)
|
227
|
-
break if !comment
|
228
|
-
first_comment = comment if whole_line_comment_at_line?(annotation_line)
|
229
|
-
end
|
230
|
-
|
231
|
-
start_line_position(first_comment || node)
|
232
|
-
end
|
233
|
-
|
234
|
-
def whole_line_comment_at_line?(line)
|
235
|
-
/\A\s*#/.match?(processed_source.lines[line - 1])
|
236
|
-
end
|
237
|
-
|
238
|
-
def start_line_position(node)
|
239
|
-
processed_source.buffer.line_range(node.loc.line).begin_pos - 1
|
240
|
-
end
|
241
|
-
|
242
|
-
def end_position(node)
|
243
|
-
end_line = processed_source.buffer.line_for_position(node.loc.expression.end_pos)
|
244
|
-
processed_source.buffer.line_range(end_line).end_pos
|
245
|
-
end
|
246
224
|
end
|
247
225
|
end
|
248
226
|
end
|
@@ -59,7 +59,7 @@ module RuboCop
|
|
59
59
|
# end
|
60
60
|
# end
|
61
61
|
# end
|
62
|
-
class NoBreakOrNext <
|
62
|
+
class NoBreakOrNext < Base
|
63
63
|
BIG_LOOP_MSG =
|
64
64
|
'Avoid `break`/`next` in big loop, decompose into private method or rethink loop.'
|
65
65
|
NO_NEXT_MSG = 'Avoid `next` in loop, use conditions or rethink loop.'
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
# If your method code has many instructions that are not organized into
|
9
9
|
# paragraphs, you should break it up into multiple paragraphs to make the
|
10
10
|
# code more breathable and readable. The 3 possible paragraphs themes
|
11
|
-
#
|
11
|
+
# could be: initialization, action, and result.
|
12
12
|
#
|
13
13
|
# @example
|
14
14
|
#
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
#
|
34
34
|
# Rails.logger.info('Content has been set')
|
35
35
|
# end
|
36
|
-
class NoParagraphs <
|
36
|
+
class NoParagraphs < Base
|
37
37
|
MSG = 'Method has many instructions and should be broken up into paragraphs.'
|
38
38
|
MAX_CONSECUTIVE_INSTRUCTIONS_ALLOWED = 5
|
39
39
|
|
@@ -11,7 +11,7 @@ module RuboCop
|
|
11
11
|
# stale TODOs. Sometimes developers really mean to work on their TODOs
|
12
12
|
# soon, but then Product re-prioritizes their work, or the developer
|
13
13
|
# leaves the company, and never gets a chance to tackle them.
|
14
|
-
class NoTodos <
|
14
|
+
class NoTodos < Base
|
15
15
|
MSG = 'Avoid TODO comment, create a task in your project management tool instead.'
|
16
16
|
KEYWORD_REGEX = /(^|[^\w])(TODO|FIXME|OPTIMIZE|HACK)($|[^\w])/i
|
17
17
|
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
26
26
|
# :jsonb,
|
27
27
|
# default: [],
|
28
28
|
# comment: "Example: [{ 'name': 'ruby' }, { 'name': 'python' }]"
|
29
|
-
class FullyDefinedJsonField <
|
29
|
+
class FullyDefinedJsonField < Base
|
30
30
|
def_node_matcher :json_field?, <<~PATTERN
|
31
31
|
(send nil? :add_column _ _ (sym {:json :jsonb}) ...)
|
32
32
|
PATTERN
|
@@ -13,7 +13,7 @@ module RuboCop
|
|
13
13
|
# of the DB migration. The reason should be detailed and reviewed by a
|
14
14
|
# knowledgeable PR reviewer. Failure to follow instructions may bring your
|
15
15
|
# app down.
|
16
|
-
class SafetyAssuredComment <
|
16
|
+
class SafetyAssuredComment < Base
|
17
17
|
MSG =
|
18
18
|
'Add `# Safe because <reason>` comment above safety_assured. ' \
|
19
19
|
'An invalid reason may bring the site down.'
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
# # good
|
17
17
|
# validates :name, presence: true
|
18
18
|
# validates :status, presence: true
|
19
|
-
class ValidateOneField <
|
19
|
+
class ValidateOneField < Base
|
20
20
|
MSG = 'Validate only one field per line.'
|
21
21
|
|
22
22
|
def_node_matcher :validates_with_more_than_one_field?, <<~PATTERN
|
@@ -13,7 +13,7 @@ module RuboCop
|
|
13
13
|
#
|
14
14
|
# # good
|
15
15
|
# validate :validate_at_least_one_admin
|
16
|
-
class ValidationMethodName <
|
16
|
+
class ValidationMethodName < Base
|
17
17
|
MSG = 'Prefix custom validation method with validate_'
|
18
18
|
|
19
19
|
def_node_matcher :on_validate_callback, <<~PATTERN
|
@@ -6,13 +6,13 @@ module RuboCop
|
|
6
6
|
# This cop checks for methods with too many paragraphs.
|
7
7
|
#
|
8
8
|
# You should organize your method code into 2 to 3 paragraphs maximum.
|
9
|
-
# The 3 possible paragraphs themes
|
9
|
+
# The 3 possible paragraphs themes could be: initialization, action,
|
10
10
|
# and result. Shape your paragraph according to those themes. Spec code
|
11
11
|
# should also be organized into 2 to 3 paragraphs
|
12
12
|
# (initialization/action/result or given/when/then paragraphs).
|
13
13
|
#
|
14
|
-
# After organizing your paragraphs, if they are too long or dense, it
|
15
|
-
# a sign that
|
14
|
+
# After organizing your paragraphs, if they are too long or dense, it
|
15
|
+
# could be a sign that they should be broken into smaller methods.
|
16
16
|
#
|
17
17
|
# @example
|
18
18
|
#
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
#
|
40
40
|
# Rails.logger.info('Content has been set')
|
41
41
|
# end
|
42
|
-
class TooManyParagraphs <
|
42
|
+
class TooManyParagraphs < Base
|
43
43
|
MSG = 'Organize method into 2 to 3 paragraphs (init, action, result).'
|
44
44
|
MAX_PARAGRAPHS = 3
|
45
45
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerome Dalbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|