class HamlLint::Runner
Responsible for running the applicable linters against the desired files.
Attributes
The {HamlLint::Configuration} that should be used for this run.
@return [HamlLint::Configuration]
A flag for whether to fail after the first failure.
@return [true, false]
A flag for whether to fail after the first failure.
@return [true, false]
The list of files to lint during this run.
@return [Array<String>]
The selector for which linters to run during this run.
@return [HamlLint::LinterSelector]
Public Instance Methods
Runs the appropriate linters against the desired files given the specified options.
@param [Hash] options @option options :config_file [String] path of configuration file to load @option options :config [HamlLint::Configuration] configuration to use @option options :excluded_files [Array<String>] @option options :included_linters [Array<String>] @option options :excluded_linters [Array<String>] @option options :fail_fast [true, false] flag for failing after first failure @option options :fail_level @option options :reporter [HamlLint::Reporter] @return [HamlLint::Report] a summary of all lints found
# File lib/haml_lint/runner.rb, line 19 def run(options = {}) @config = load_applicable_config(options) @files = extract_applicable_files(config, options) @linter_selector = HamlLint::LinterSelector.new(config, options) @fail_fast = options.fetch(:fail_fast, false) report(options) end
Private Instance Methods
Runs all provided linters using the specified config against the given file.
@param file [String] path to file to lint @param linter_selector
[HamlLint::LinterSelector] @param config [HamlLint::Configuration]
# File lib/haml_lint/runner.rb, line 80 def collect_lints(file, linter_selector, config) begin document = HamlLint::Document.new(File.read(file), file: file, config: config) rescue HamlLint::Exceptions::ParseError => e return [HamlLint::Lint.new(HamlLint::Linter::Syntax.new(config), file, e.line, e.to_s, :error)] end linter_selector.linters_for_file(file).map do |linter| linter.run(document) end.flatten end
Returns the list of files that should be linted given the specified configuration and options.
@param config [HamlLint::Configuration] @param options [Hash] @return [Array<String>]
# File lib/haml_lint/runner.rb, line 99 def extract_applicable_files(config, options) included_patterns = options[:files] excluded_patterns = config['exclude'] excluded_patterns += options.fetch(:excluded_files, []) HamlLint::FileFinder.new(config).find(included_patterns, excluded_patterns) end
Returns the {HamlLint::Configuration} that should be used given the specified options.
@param options [Hash] @return [HamlLint::Configuration]
# File lib/haml_lint/runner.rb, line 61 def load_applicable_config(options) if options[:config] options[:config] elsif options[:auto_gen_config] HamlLint::ConfigurationLoader.load_applicable_config( options[:config_file], exclude_files: [HamlLint::ConfigurationLoader::AUTO_GENERATED_FILE] ) else HamlLint::ConfigurationLoader.load_applicable_config(options[:config_file]) end end
Process a file and add it to the given report.
@param file [String] the name of the file to process @param report [HamlLint::Report] @return [void]
# File lib/haml_lint/runner.rb, line 123 def process_file(file, report) lints = collect_lints(file, linter_selector, config) lints.each { |lint| report.add_lint(lint) } report.finish_file(file, lints) end
Process the files and add them to the given report.
@param report [HamlLint::Report] @return [void]
# File lib/haml_lint/runner.rb, line 111 def process_files(report) files.each do |file| process_file(file, report) break if report.failed? && fail_fast? end end
Generates a report based on the given options.
@param options [Hash] @option options :reporter [HamlLint::Reporter] the reporter to report with @return [HamlLint::Report]
# File lib/haml_lint/runner.rb, line 134 def report(options) report = HamlLint::Report.new(reporter: options[:reporter], fail_level: options[:fail_level]) report.start(@files) process_files(report) report end