rubocop-obsession 0.1.0
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/config/default.yml +163 -0
- data/lib/rubocop/cop/mixin/files/verbs.txt +8507 -0
- data/lib/rubocop/cop/mixin/helpers.rb +27 -0
- data/lib/rubocop/cop/obsession/graphql/mutation_name.rb +40 -0
- data/lib/rubocop/cop/obsession/method_order.rb +244 -0
- data/lib/rubocop/cop/obsession/no_break_or_next.rb +94 -0
- data/lib/rubocop/cop/obsession/no_paragraphs.rb +62 -0
- data/lib/rubocop/cop/obsession/no_todos.rb +26 -0
- data/lib/rubocop/cop/obsession/rails/callback_one_method.rb +35 -0
- data/lib/rubocop/cop/obsession/rails/fully_defined_json_field.rb +71 -0
- data/lib/rubocop/cop/obsession/rails/migration_belongs_to.rb +44 -0
- data/lib/rubocop/cop/obsession/rails/no_callback_conditions.rb +60 -0
- data/lib/rubocop/cop/obsession/rails/private_callback.rb +59 -0
- data/lib/rubocop/cop/obsession/rails/safety_assured_comment.rb +37 -0
- data/lib/rubocop/cop/obsession/rails/service_name.rb +82 -0
- data/lib/rubocop/cop/obsession/rails/service_perform_method.rb +57 -0
- data/lib/rubocop/cop/obsession/rails/short_after_commit.rb +90 -0
- data/lib/rubocop/cop/obsession/rails/short_validate.rb +36 -0
- data/lib/rubocop/cop/obsession/rails/validate_one_field.rb +33 -0
- data/lib/rubocop/cop/obsession/rails/validation_method_name.rb +32 -0
- data/lib/rubocop/cop/obsession/rspec/describe_public_method.rb +125 -0
- data/lib/rubocop/cop/obsession/rspec/empty_line_after_final_let.rb +36 -0
- data/lib/rubocop/cop/obsession/too_many_paragraphs.rb +56 -0
- data/lib/rubocop/obsession/version.rb +5 -0
- data/lib/rubocop/obsession.rb +9 -0
- metadata +100 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Obsession
|
6
|
+
# This cop checks for methods with too many paragraphs.
|
7
|
+
#
|
8
|
+
# You should organize your method code into 2 to 3 paragraphs maximum.
|
9
|
+
# The 3 possible paragraphs themes always are: initialization, action,
|
10
|
+
# and result. Shape your paragraph according to those themes. Spec code
|
11
|
+
# should also be organized into 2 to 3 paragraphs
|
12
|
+
# (initialization/action/result or given/when/then paragraphs).
|
13
|
+
#
|
14
|
+
# After organizing your paragraphs, if they are too long or dense, it is
|
15
|
+
# a sign that you should break your code into smaller methods.
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
#
|
19
|
+
# # bad
|
20
|
+
# def set_seo_content
|
21
|
+
# return if seo_content.present?
|
22
|
+
#
|
23
|
+
# template = SeoTemplate.find_by(template_type: 'BlogPost')
|
24
|
+
#
|
25
|
+
# return if template.blank?
|
26
|
+
#
|
27
|
+
# self.seo_content = build_seo_content(seo_template: template, slug: slug)
|
28
|
+
#
|
29
|
+
# Rails.logger.info('Content has been set')
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# def set_seo_content
|
34
|
+
# return if seo_content.present?
|
35
|
+
# template = SeoTemplate.find_by(template_type: 'BlogPost')
|
36
|
+
# return if template.blank?
|
37
|
+
#
|
38
|
+
# self.seo_content = build_seo_content(seo_template: template, slug: slug)
|
39
|
+
#
|
40
|
+
# Rails.logger.info('Content has been set')
|
41
|
+
# end
|
42
|
+
class TooManyParagraphs < Cop
|
43
|
+
MSG = 'Organize method into 2 to 3 paragraphs (init, action, result).'
|
44
|
+
MAX_PARAGRAPHS = 3
|
45
|
+
|
46
|
+
def on_def(node)
|
47
|
+
lines = processed_source.lines[node.first_line..(node.last_line - 2)]
|
48
|
+
blank_lines_count = lines.count(&:blank?)
|
49
|
+
|
50
|
+
add_offense(node) if blank_lines_count >= MAX_PARAGRAPHS
|
51
|
+
end
|
52
|
+
alias_method :on_defs, :on_def
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/object/blank'
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
require_relative 'cop/mixin/helpers'
|
6
|
+
Dir["#{__dir__}/cop/obsession/**/*.rb"].sort.each { |file| require file }
|
7
|
+
require_relative 'obsession/version'
|
8
|
+
|
9
|
+
RuboCop::ConfigLoader.inject_defaults!("#{__dir__}/../..")
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-obsession
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jerome Dalbert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.41'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.41'
|
41
|
+
description: A collection of RuboCop cops I have been obsessed with.
|
42
|
+
email:
|
43
|
+
- jerome.dalbert@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE.txt
|
49
|
+
- README.md
|
50
|
+
- config/default.yml
|
51
|
+
- lib/rubocop/cop/mixin/files/verbs.txt
|
52
|
+
- lib/rubocop/cop/mixin/helpers.rb
|
53
|
+
- lib/rubocop/cop/obsession/graphql/mutation_name.rb
|
54
|
+
- lib/rubocop/cop/obsession/method_order.rb
|
55
|
+
- lib/rubocop/cop/obsession/no_break_or_next.rb
|
56
|
+
- lib/rubocop/cop/obsession/no_paragraphs.rb
|
57
|
+
- lib/rubocop/cop/obsession/no_todos.rb
|
58
|
+
- lib/rubocop/cop/obsession/rails/callback_one_method.rb
|
59
|
+
- lib/rubocop/cop/obsession/rails/fully_defined_json_field.rb
|
60
|
+
- lib/rubocop/cop/obsession/rails/migration_belongs_to.rb
|
61
|
+
- lib/rubocop/cop/obsession/rails/no_callback_conditions.rb
|
62
|
+
- lib/rubocop/cop/obsession/rails/private_callback.rb
|
63
|
+
- lib/rubocop/cop/obsession/rails/safety_assured_comment.rb
|
64
|
+
- lib/rubocop/cop/obsession/rails/service_name.rb
|
65
|
+
- lib/rubocop/cop/obsession/rails/service_perform_method.rb
|
66
|
+
- lib/rubocop/cop/obsession/rails/short_after_commit.rb
|
67
|
+
- lib/rubocop/cop/obsession/rails/short_validate.rb
|
68
|
+
- lib/rubocop/cop/obsession/rails/validate_one_field.rb
|
69
|
+
- lib/rubocop/cop/obsession/rails/validation_method_name.rb
|
70
|
+
- lib/rubocop/cop/obsession/rspec/describe_public_method.rb
|
71
|
+
- lib/rubocop/cop/obsession/rspec/empty_line_after_final_let.rb
|
72
|
+
- lib/rubocop/cop/obsession/too_many_paragraphs.rb
|
73
|
+
- lib/rubocop/obsession.rb
|
74
|
+
- lib/rubocop/obsession/version.rb
|
75
|
+
homepage: https://github.com/jeromedalbert/rubocop-obsession
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata:
|
79
|
+
homepage_uri: https://github.com/jeromedalbert/rubocop-obsession
|
80
|
+
source_code_uri: https://github.com/jeromedalbert/rubocop-obsession
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.5.16
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Code style checking for Ruby files.
|
100
|
+
test_files: []
|