class CukeLinter::Linter
A generic linter that can be used to make arbitrary linting rules
Attributes
name[R]
Returns the name of the linter
Public Class Methods
new(name: nil, message: nil, rule: nil)
click to toggle source
Creates a new linter object
# File lib/cuke_linter/linters/linter.rb, line 11 def initialize(name: nil, message: nil, rule: nil) @name = name || self.class.name.split('::').last @message = message || "#{self.name} problem detected" @rule = rule end
Public Instance Methods
lint(model)
click to toggle source
Lints the given model and returns linting data about said model
# File lib/cuke_linter/linters/linter.rb, line 18 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
Private Instance Methods
build_problem(model)
click to toggle source
# File lib/cuke_linter/linters/linter.rb, line 32 def build_problem(model) problem_message = respond_to?(:message) ? message : @message if model.is_a?(CukeModeler::FeatureFile) { problem: problem_message, location: model.path } else { problem: problem_message, location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" } end end