Class: Splam::Rules::LineLength
- Inherits:
-
Splam::Rule
- Object
- Splam::Rule
- Splam::Rules::LineLength
- Defined in:
- lib/splam/rules/line_length.rb
Instance Attribute Summary
Attributes inherited from Splam::Rule
#body, #reasons, #score, #suite, #weight
Instance Method Summary collapse
- #name ⇒ Object
-
#run ⇒ Object
Penalize long line lengths.
Methods inherited from Splam::Rule
#add_score, inherited, #initialize, #line_safe?, run
Constructor Details
This class inherits a constructor from Splam::Rule
Instance Method Details
#name ⇒ Object
3 4 5 |
# File 'lib/splam/rules/line_length.rb', line 3 def name "Line length" end |
#run ⇒ Object
Penalize long line lengths.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/splam/rules/line_length.rb', line 8 def run lines = @body.split("\n") lines.each do |line| next if line =~ /\A\s{4,}/ # ignore code blocks # multiplier = (lines.size == 1) ? 10 : 1 # one line? fail. multiplier = 1 # 1 point for each 40 chars in a line. hits = (line.size / 40) * multiplier add_score hits, "lines over 40 chars" # 2 more points if line is longer than 80 hits = (line.size / 80) * 2 * multiplier add_score hits, "lines over 80 chars" end end |