Class: Commitlint::Linter

Inherits:
Object
  • Object
show all
Defined in:
lib/commitlint/linter.rb

Overview

Linter class is responsible for linting commit messages.

Instance Method Summary collapse

Constructor Details

#initialize(commit_message, output: true) ⇒ Linter

Returns a new instance of Linter.



6
7
8
9
# File 'lib/commitlint/linter.rb', line 6

def initialize(commit_message, output: true)
  @commit_message = clean_commit_message(commit_message)
  @output = output
end

Instance Method Details

#lint!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/commitlint/linter.rb', line 11

def lint!
  validator = Validator.new(@commit_message)

  return 0 if validator.valid?

  errors = validator.errors

  puts <<~MESSAGE if @output
    \nYour commit message is invalid:

    #{errors.map { |e| "=> #{e}" }.join("\n")}

    Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint\n
  MESSAGE
  1
end