lib/slim_lint/runner.rb in slim_lint-0.20.2 vs lib/slim_lint/runner.rb in slim_lint-0.21.0

- old
+ new

@@ -13,17 +13,21 @@ # @option options :included_linters [Array<String>] # @option options :excluded_linters [Array<String>] # @return [SlimLint::Report] a summary of all lints found def run(options = {}) config = load_applicable_config(options) - files = extract_applicable_files(config, options) - linter_selector = SlimLint::LinterSelector.new(config, options) - lints = files.map do |file| - collect_lints(file, linter_selector, config) - end.flatten + if options[:stdin_file_path].nil? + files = extract_applicable_files(config, options) + lints = files.map do |file| + collect_lints(File.read(file), file, linter_selector, config) + end.flatten + else + files = [options[:stdin_file_path]] + lints = collect_lints($stdin.read, options[:stdin_file_path], linter_selector, config) + end SlimLint::Report.new(lints, files) end private @@ -47,17 +51,17 @@ # file. # # @param file [String] path to file to lint # @param linter_selector [SlimLint::LinterSelector] # @param config [SlimLint::Configuration] - def collect_lints(file, linter_selector, config) + def collect_lints(file_content, file_name, linter_selector, config) begin - document = SlimLint::Document.new(File.read(file), file: file, config: config) + document = SlimLint::Document.new(file_content, file: file_name, config: config) rescue SlimLint::Exceptions::ParseError => e return [SlimLint::Lint.new(nil, file, e.lineno, e.error, :error)] end - linter_selector.linters_for_file(file).map do |linter| + linter_selector.linters_for_file(file_name).map do |linter| linter.run(document) end.flatten end # Returns the list of files that should be linted given the specified