class Pronto::ERBLint
Constants
- DEFAULT_CONFIG_FILENAME
Public Class Methods
new(_, _ = nil)
click to toggle source
Calls superclass method
# File lib/pronto/erb_lint.rb, line 10 def initialize(_, _ = nil) super @options = {} load_config end
Public Instance Methods
autocorrect?()
click to toggle source
# File lib/pronto/erb_lint.rb, line 77 def autocorrect? @options[:autocorrect] end
config_filename()
click to toggle source
# File lib/pronto/erb_lint.rb, line 37 def config_filename @config_filename ||= @options[:config] || ::ERBLint::CLI::DEFAULT_CONFIG_FILENAME end
enabled_linter_classes()
click to toggle source
# File lib/pronto/erb_lint.rb, line 62 def enabled_linter_classes @enabled_linter_classes ||= ::ERBLint::LinterRegistry.linters .select { |klass| linter_can_run?(klass) && enabled_linter_names.include?(klass.simple_name.underscore) } end
enabled_linter_names()
click to toggle source
# File lib/pronto/erb_lint.rb, line 55 def enabled_linter_names @enabled_linter_names ||= @options[:enabled_linters] || known_linter_names .select { |name| @config.for_linter(name.camelize).enabled? } end
erb_file?(path)
click to toggle source
# File lib/pronto/erb_lint.rb, line 87 def erb_file?(path) File.extname(path) == '.erb' end
excluded?(filename)
click to toggle source
# File lib/pronto/erb_lint.rb, line 91 def excluded?(filename) @config.global_exclude.any? do |path| File.fnmatch?(path, filename) end end
file_loader()
click to toggle source
# File lib/pronto/erb_lint.rb, line 41 def file_loader @file_loader ||= ::ERBLint::FileLoader.new(Dir.pwd) end
inspect(patch)
click to toggle source
# File lib/pronto/erb_lint.rb, line 97 def inspect(patch) inspector = ::ERBLint::Runner.new(file_loader, @config) inspector.run(processed_source_for(patch)) inspector.offenses.map do |offence| patch.added_lines .select { |line| offence.line_range.include? line.new_lineno } .map { |line| new_message(offence, line) } end end
known_linter_names()
click to toggle source
# File lib/pronto/erb_lint.rb, line 67 def known_linter_names @known_linter_names ||= ::ERBLint::LinterRegistry.linters .map(&:simple_name) .map(&:underscore) end
linter_can_run?(klass)
click to toggle source
# File lib/pronto/erb_lint.rb, line 73 def linter_can_run?(klass) !autocorrect? || klass.support_autocorrect? end
load_config()
click to toggle source
# File lib/pronto/erb_lint.rb, line 24 def load_config if File.exist?(config_filename) config = ::ERBLint::RunnerConfig.new(file_loader.yaml(config_filename)) @config = ::ERBLint::RunnerConfig.default.merge(config) else warn "#{config_filename} not found: using default config".yellow @config = RunnerConfig.default end @config.merge!(runner_config_override) rescue Psych::SyntaxError => e failure!("error parsing config: #{e.message}") end
new_message(offence, line)
click to toggle source
# File lib/pronto/erb_lint.rb, line 107 def new_message(offence, line) path = line.patch.delta.new_file[:path] level = :error Message.new(path, line, level, offence.message, nil, self.class) end
processed_source_for(patch)
click to toggle source
# File lib/pronto/erb_lint.rb, line 113 def processed_source_for(patch) path = patch.new_file_full_path.to_s file_content = File.read(path, encoding: 'ISO8859-1:utf-8') ::ERBLint::ProcessedSource.new(path, file_content) end
run()
click to toggle source
# File lib/pronto/erb_lint.rb, line 16 def run return [] unless @patches @patches.select { |patch| valid_patch?(patch) } .map { |patch| inspect(patch) } .flatten.compact end
runner_config_override()
click to toggle source
# File lib/pronto/erb_lint.rb, line 45 def runner_config_override ::ERBLint::RunnerConfig.new( linters: {}.tap do |linters| ::ERBLint::LinterRegistry.linters.map do |klass| linters[klass.simple_name] = { 'enabled' => enabled_linter_classes.include?(klass) } end end ) end
valid_patch?(patch)
click to toggle source
# File lib/pronto/erb_lint.rb, line 81 def valid_patch?(patch) return false if patch.additions < 1 path = patch.new_file_full_path erb_file?(path) && !excluded?(path) end