Class: FitCommit::Validators::Tense

Inherits:
Base
  • Object
show all
Defined in:
lib/fit-commit/validators/tense.rb

Constant Summary collapse

VERB_BLACKLIST =
%w(
  adds       adding       added
  allows     allowing     allowed
  amends     amending     amended
  bumps      bumping      bumped
  calculates calculating  calculated
  changes    changing     changed
  cleans     cleaning     cleaned
  commits    committing   committed
  corrects   correcting   corrected
  creates    creating     created
  darkens    darkening    darkened
  disables   disabling    disabled
  displays   displaying   displayed
  drys       drying       dryed
  ends       ending       ended
  enforces   enforcing    enforced
  enqueues   enqueuing    enqueued
  extracts   extracting   extracted
  finishes   finishing    finished
  fixes      fixing       fixed
  formats    formatting   formatted
  guards     guarding     guarded
  handles    handling     handled
  hides      hiding       hid
  increases  increasing   increased
  ignores    ignoring     ignored
  implements implementing implemented
  improves   improving    improved
  keeps      keeping      kept
  kills      killing      killed
  makes      making       made
  merges     merging      merged
  moves      moving       moved
  permits    permitting   permitted
  prevents   preventing   prevented
  pushes     pushing      pushed
  rebases    rebasing     rebased
  refactors  refactoring  refactored
  removes    removing     removed
  renames    renaming     renamed
  reorders   reordering   reordered
  requires   requiring    required
  restores   restoring    restored
  sends      sending      sent
  sets       setting
  separates  separating   separated
  shows      showing      showed
  skips      skipping     skipped
  sorts      sorting
  speeds     speeding     sped
  starts     starting     started
  supports   supporting   supported
  takes      taking       took
  tests      testing      tested
  truncates  truncating   truncated
  updates    updating     updated
  uses       using        used
)

Instance Attribute Summary

Attributes inherited from Base

#branch_name, #lines

Instance Method Summary collapse

Methods inherited from Base

inherited, #initialize, #validate

Methods included from HasErrors

#add_error, #add_warning, #errors, #merge_errors, #merge_warnings, #warnings

Constructor Details

This class inherits a constructor from FitCommit::Validators::Base

Instance Method Details

#validate_line(lineno, text, _branch_name) ⇒ Object



66
67
68
69
70
# File 'lib/fit-commit/validators/tense.rb', line 66

def validate_line(lineno, text, _branch_name)
  if lineno == 1 && wrong_tense?(text)
    add_error(lineno, "Message must use present imperative tense.")
  end
end

#wrong_tense?(text) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/fit-commit/validators/tense.rb', line 72

def wrong_tense?(text)
  first_word = text.split.first(2).detect { |w| w =~ /\A\w/ }
  first_word && VERB_BLACKLIST.include?(first_word.downcase)
end