class Git::Cop::Styles::Abstract

An abstract class which provides basic functionality from which all style cops inherit from. Not meant for direct use.

Constants

ISSUE_LINE_OFFSET
LEVELS

Attributes

commit[R]
graylist[R]
settings[R]

Public Class Methods

build_issue_line(index, line) click to toggle source
# File lib/git/cop/styles/abstract.rb, line 37
def self.build_issue_line index, line
  {number: index + ISSUE_LINE_OFFSET, content: line}
end
defaults() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 29
def self.defaults
  fail NotImplementedError, "The `.defaults` method has not been implemented."
end
descendants() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 33
def self.descendants
  @descendants || []
end
id() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 21
def self.id
  to_s.sub("Git::Cop::Styles", "").snakecase.to_sym
end
inherited(klass) click to toggle source
# File lib/git/cop/styles/abstract.rb, line 16
def self.inherited klass
  @descendants ||= []
  @descendants << klass
end
label() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 25
def self.label
  to_s.sub("Git::Cop::Styles", "").titleize
end
new(commit:, settings: self.class.defaults) click to toggle source
# File lib/git/cop/styles/abstract.rb, line 43
def initialize commit:, settings: self.class.defaults
  @commit = commit
  @settings = settings
  @graylist = load_graylist
end

Public Instance Methods

enabled?() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 49
def enabled?
  settings.fetch :enabled
end
error?() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 71
def error?
  invalid? && severity == :error
end
invalid?() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 63
def invalid?
  !valid?
end
issue() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 75
def issue
  fail NotImplementedError, "The `#issue` method has not been implemented."
end
severity() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 53
def severity
  level = settings.fetch :severity
  fail(Errors::Severity, level: level) unless LEVELS.include?(level)
  level
end
valid?() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 59
def valid?
  fail NotImplementedError, "The `#valid?` method has not been implemented."
end
warning?() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 67
def warning?
  invalid? && severity == :warn
end

Protected Instance Methods

load_graylist() click to toggle source
# File lib/git/cop/styles/abstract.rb, line 83
def load_graylist
  Kit::Graylist.new settings[:graylist]
end