class ROM::Lint::Linter

Base class for building linters that check source code

Linters are used by authors of ROM adapters to verify that their integration complies with the ROM api.

Most of the time, authors won't need to construct linters directly because the provided test helpers will automatically run when required in tests and specs.

@example

require 'rom/lint/spec'

@api public

Constants

Failure

A failure raised by complain

Public Class Methods

each_lint() { |lint, self| ... } click to toggle source

Iterate over all lint methods

@yield [String, ROM::Lint]

@api public

# File lib/rom/lint/linter.rb, line 28
def self.each_lint
  return to_enum unless block_given?

  lints.each { |lint| yield lint, self }
end

Private Class Methods

lints() click to toggle source

Return a list a lint methods

@return [String]

@api private

# File lib/rom/lint/linter.rb, line 55
def self.lints
  public_instance_methods(true).grep(/^lint_/).map(&:to_s)
end

Public Instance Methods

lint(name) click to toggle source

Run a lint method

@param [String] name

@raise [ROM::Lint::Linter::Failure] if linting fails

@api public

# File lib/rom/lint/linter.rb, line 41
def lint(name)
  before_lint
  public_send name
  after_lint
  true # for assertions
end

Private Instance Methods

after_lint() click to toggle source

Hook method executed after each lint method run

@api private

# File lib/rom/lint/linter.rb, line 76
def after_lint; end
before_lint() click to toggle source

Hook method executed before each lint method run

@api private

# File lib/rom/lint/linter.rb, line 71
def before_lint; end
complain(*args) click to toggle source

Raise a failure if a lint verification fails

@raise [ROM::Lint::Linter::Failure]

@api private

# File lib/rom/lint/linter.rb, line 64
def complain(*args)
  raise Failure, *args
end