Class: Pronto::Stylelint::Linter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pronto/stylelint/linter.rb

Constant Summary collapse

STYLELINT_FAILURE =
'Stylelint failed to run'
STATUS_CODES =
{
  0 => :success,
  1 => :fatal_error,
  2 => :lint_problem,
  64 => :invalid_cli_usage,
  78 => :invalid_configuration_file
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patch, stylelint_config) ⇒ Linter

Returns a new instance of Linter.



32
33
34
35
36
# File 'lib/pronto/stylelint/linter.rb', line 32

def initialize(patch, stylelint_config)
  @patch = patch
  @stylelint_config = stylelint_config
  @stylint_major_version = nil
end

Instance Attribute Details

#stylelint_configObject (readonly)

Returns the value of attribute stylelint_config.



12
13
14
# File 'lib/pronto/stylelint/linter.rb', line 12

def stylelint_config
  @stylelint_config
end

Instance Method Details

#runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pronto/stylelint/linter.rb', line 38

def run
  Dir.chdir(git_repo_path) do
    Open3.popen3(cli_command) do |_stdin, stdout, stderr, thread|
      JSON.parse(
        case thread_status(thread)
        when :success, :lint_problem
          out = stdout.read
          out.empty? ? stderr.read : out
        else
          puts "#{STYLELINT_FAILURE} - #{thread_status(thread)}:\n#{stderr.read}"
          '[]'
        end
      )
    end
  end
end