Class: Linter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, command:, ignore: false) ⇒ Linter

Returns a new instance of Linter.



4
5
6
7
8
# File 'lib/B4U/linter.rb', line 4

def initialize(name:, command:, ignore: false)
  @name = name
  @command = command
  @ignore = ignore
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



2
3
4
# File 'lib/B4U/linter.rb', line 2

def command
  @command
end

#ignoreObject (readonly)

Returns the value of attribute ignore.



2
3
4
# File 'lib/B4U/linter.rb', line 2

def ignore
  @ignore
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/B4U/linter.rb', line 2

def name
  @name
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/B4U/linter.rb', line 10

def run
  console_output, status = Open3.capture2e(command)
  if status.success?
    puts "✅ - #{name}".green
  elsif ignore
    puts "❌ - #{name} (ignored)".magenta
  else
    puts "❌ - #{name}".red
    raise LinterError.new(linter: name, console_output:)
  end
end