Class: CukeLinter::Linter

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

Overview

A generic linter that can be used to make arbitrary linting rules

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, message: nil, rule: nil) ⇒ Linter

Creates a new linter object



10
11
12
13
14
# File 'lib/cuke_linter/linters/linter.rb', line 10

def initialize(name: nil, message: nil, rule: nil)
  @name    = name || self.class.name.split('::').last
  @message = message || "#{self.name} problem detected"
  @rule    = rule
end

Instance Attribute Details

#nameObject (readonly)

Returns the name of the linter



7
8
9
# File 'lib/cuke_linter/linters/linter.rb', line 7

def name
  @name
end

Instance Method Details

#lint(model) ⇒ Object

Lints the given model and returns linting data about said model



17
18
19
20
21
22
23
24
25
# File 'lib/cuke_linter/linters/linter.rb', line 17

def lint(model)
  raise 'No linting rule provided!' unless @rule || respond_to?(:rule)

  problem_found = respond_to?(:rule) ? rule(model) : @rule.call(model)

  return nil unless problem_found

  build_problem(model)
end