Class: Pronto::Stylelint

Inherits:
Runner
  • Object
show all
Defined in:
lib/pronto/stylelint.rb

Constant Summary collapse

CONFIG_FILE =
'.pronto_stylelint.yml'.freeze
CONFIG_KEYS =
%w(stylelint_executable files_to_lint cli_options).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patches, commit = nil) ⇒ Stylelint

Returns a new instance of Stylelint.



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

def initialize(patches, commit = nil)
  super(patches, commit)
  read_config
end

Instance Attribute Details

#cli_optionsObject



21
22
23
# File 'lib/pronto/stylelint.rb', line 21

def cli_options
  "#{@cli_options} -f json".strip
end

#stylelint_executableObject



17
18
19
# File 'lib/pronto/stylelint.rb', line 17

def stylelint_executable
  @stylelint_executable || 'stylelint'.freeze
end

Instance Method Details

#files_to_lintObject



25
26
27
# File 'lib/pronto/stylelint.rb', line 25

def files_to_lint
  @files_to_lint || /\.(c|sc|sa|le)ss$/.freeze
end

#files_to_lint=(regexp) ⇒ Object



29
30
31
# File 'lib/pronto/stylelint.rb', line 29

def files_to_lint=(regexp)
  @files_to_lint = regexp.is_a?(Regexp) ? regexp : Regexp.new(regexp)
end

#read_configObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/pronto/stylelint.rb', line 33

def read_config
  config_file = File.join(git_repo_path, CONFIG_FILE)
  return unless File.exist?(config_file)
  config = YAML.load_file(config_file)

  CONFIG_KEYS.each do |config_key|
    next unless config[config_key]
    send("#{config_key}=", config[config_key])
  end
end

#runObject



44
45
46
47
48
49
50
51
52
# File 'lib/pronto/stylelint.rb', line 44

def run
  return [] if !@patches || @patches.count.zero?

  @patches
    .select { |patch| patch.additions > 0 }
    .select { |patch| style_file?(patch.new_file_full_path) }
    .map { |patch| inspect(patch) }
    .flatten.compact
end