Class: RuboCop::Cop::Obsession::TooManyParagraphs
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Obsession::TooManyParagraphs
- Defined in:
- lib/rubocop/cop/obsession/too_many_paragraphs.rb
Overview
This cop checks for methods with too many paragraphs.
You should organize your method code into 2 to 3 paragraphs maximum. The 3 possible paragraphs themes could be: initialization, action, and result. Shape your paragraph according to those themes. Spec code should also be organized into 2 to 3 paragraphs (initialization/action/result or given/when/then paragraphs).
After organizing your paragraphs, if they are too long or dense, it could be a sign that they should be broken into smaller methods.
Constant Summary collapse
- MSG =
'Organize method into 2 to 3 paragraphs (init, action, result).'
- MAX_PARAGRAPHS =
3
Instance Method Summary collapse
- #on_def(node) ⇒ Object (also: #on_defs)
Instance Method Details
#on_def(node) ⇒ Object Also known as: on_defs
46 47 48 49 50 51 |
# File 'lib/rubocop/cop/obsession/too_many_paragraphs.rb', line 46 def on_def(node) lines = processed_source.lines[node.first_line..(node.last_line - 2)] blank_lines_count = lines.count(&:blank?) add_offense(node) if blank_lines_count >= MAX_PARAGRAPHS end |