Class: FitCommit::Validators::LineLength
- Inherits:
-
Base
- Object
- Base
- FitCommit::Validators::LineLength
show all
- Defined in:
- lib/fit_commit/validators/line_length.rb
Instance Attribute Summary
Attributes inherited from Base
#branch_name, #config
Instance Method Summary
collapse
Methods inherited from Base
#enabled?, inherited, #initialize, #matches_branch?, #validate
Methods included from HasErrors
#add_error, #add_warning, #clear_errors, #clear_warnings, #errors, #merge_errors, #merge_warnings, #warnings
Instance Method Details
#allow_long_urls? ⇒ Boolean
36
37
38
|
# File 'lib/fit_commit/validators/line_length.rb', line 36
def allow_long_urls?
config.fetch("AllowLongUrls")
end
|
#contains_url?(text) ⇒ Boolean
24
25
26
|
# File 'lib/fit_commit/validators/line_length.rb', line 24
def contains_url?(text)
text =~ %r{[a-z]+://}
end
|
#line_too_long?(text) ⇒ Boolean
20
21
22
|
# File 'lib/fit_commit/validators/line_length.rb', line 20
def line_too_long?(text)
text.length > max_line_length && !(allow_long_urls? && contains_url?(text))
end
|
#max_line_length ⇒ Object
28
29
30
|
# File 'lib/fit_commit/validators/line_length.rb', line 28
def max_line_length
config.fetch("MaxLineLength")
end
|
#subject_warn_length ⇒ Object
32
33
34
|
# File 'lib/fit_commit/validators/line_length.rb', line 32
def subject_warn_length
config.fetch("SubjectWarnLength")
end
|
#validate_line(lineno, text) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/fit_commit/validators/line_length.rb', line 6
def validate_line(lineno, text)
if lineno == 1 && text.empty?
add_error(lineno, "Subject line cannot be blank.")
elsif lineno == 2 && !text.empty?
add_error(lineno, "Second line must be blank.")
elsif line_too_long?(text)
add_error(lineno, format("Lines should be <= %i chars. (%i)",
max_line_length, text.length))
elsif lineno == 1 && text.length > subject_warn_length
add_warning(lineno, format("Subject line should be <= %i chars. (%i)",
subject_warn_length, text.length))
end
end
|