class Gitlab::Dangerfiles::BaseLinter
Constants
- MAX_LINE_LENGTH
- MIN_SUBJECT_WORDS_COUNT
Attributes
commit[R]
problems[R]
Public Class Methods
new(commit)
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 26 def initialize(commit) @commit = commit @problems = {} end
problems_mapping()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 13 def self.problems_mapping { subject_too_short: "The %s must contain at least #{MIN_SUBJECT_WORDS_COUNT} words", subject_too_long: "The %s may not be longer than #{MAX_LINE_LENGTH} characters", subject_starts_with_lowercase: "The %s must start with a capital letter", subject_ends_with_a_period: "The %s must not end with a period", } end
subject_description()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 22 def self.subject_description "commit subject" end
Public Instance Methods
add_problem(problem_key, *args)
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 35 def add_problem(problem_key, *args) @problems[problem_key] = sprintf(self.class.problems_mapping[problem_key], *args) end
failed?()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 31 def failed? problems.any? end
lint_subject()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 39 def lint_subject if subject_too_short? add_problem(:subject_too_short, self.class.subject_description) end if subject_too_long? add_problem(:subject_too_long, self.class.subject_description) end if subject_starts_with_lowercase? add_problem(:subject_starts_with_lowercase, self.class.subject_description) end if subject_ends_with_a_period? add_problem(:subject_ends_with_a_period, self.class.subject_description) end self end
Private Instance Methods
line_too_long?(line)
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 73 def line_too_long?(line) line.length > MAX_LINE_LENGTH end
message_parts()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 92 def message_parts @message_parts ||= commit.message.split("\n", 3) end
subject()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 61 def subject @subject ||= TitleLinting.remove_draft_flag(message_parts[0]) end
subject_ends_with_a_period?()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 88 def subject_ends_with_a_period? subject.end_with?(".") end
subject_starts_with_lowercase?()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 77 def subject_starts_with_lowercase? return false if subject.empty? return false if ("A".."Z").cover?(subject[0]) first_char = subject.sub(/\A(\[.+\]|\w+:)\s/, "")[0] first_char_downcased = first_char.downcase return true unless ("a".."z").cover?(first_char_downcased) first_char.downcase == first_char end
subject_too_long?()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 69 def subject_too_long? line_too_long?(subject) end
subject_too_short?()
click to toggle source
# File lib/gitlab/dangerfiles/base_linter.rb, line 65 def subject_too_short? subject.split(" ").length < MIN_SUBJECT_WORDS_COUNT end