Skip to content

Commit

Permalink
Merge 8880ae1 into e838071
Browse files Browse the repository at this point in the history
  • Loading branch information
benmelz committed Jan 23, 2024
2 parents e838071 + 8880ae1 commit e7607e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/haml_lint/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ def autocorrect_document(document, linters)
# @return [Array<HamlLint::Source>]
def extract_applicable_sources(config, options)
if options[:stdin]
[HamlLint::Source.new($stdin, options[:stdin])]
[HamlLint::Source.new(io: $stdin, path: options[:stdin])]
else
included_patterns = options[:files]
excluded_patterns = config['exclude']
excluded_patterns += options.fetch(:excluded_files, [])

HamlLint::FileFinder.new(config).find(included_patterns, excluded_patterns).map do |file_path|
HamlLint::Source.new File.new(file_path), file_path
HamlLint::Source.new path: file_path
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/haml_lint/source.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# frozen_string_literal: true

module HamlLint
# Wrapper class representing a single target for HamlLint::Runner to run against, comprised of an IO object
# containing haml code, as well as a file path.
# Wrapper class representing a single target for HamlLint::Runner to run against, comprised of a file path to
# eventually read from, and an optional IO argument to override with.
class Source
# @return [String] File path associated with the given IO object.
attr_reader :path

# Wraps an IO object and file path to a source object.
# Wraps an optional IO object and file path to a source object.
#
# @param [IO] io
# @param [String] path
def initialize(io, path)
@io = io
# @param [IO] io
def initialize(path: nil, io: nil)
@path = path
@io = io
end

# @return [String] Contents of the given IO object.
def contents
@contents ||= @io.read
@contents ||= @io&.read || File.read(path)
end
end
end
4 changes: 3 additions & 1 deletion spec/haml_lint/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
subject { runner.run(options) }

context 'general tests' do
let(:stubbed_sources) { %w[file1.slim file2.slim].map { |path| HamlLint::Source.new StringIO.new, path } }
let(:stubbed_sources) do
%w[file1.slim file2.slim].map { |path| HamlLint::Source.new io: StringIO.new, path: path }
end

let(:options) do
base_options.merge(reporter: reporter)
Expand Down

0 comments on commit e7607e1

Please sign in to comment.