Skip to content

Commit

Permalink
Fix regression in --require flag
Browse files Browse the repository at this point in the history
This was broken by a refactor in d20b3c3. The problem was that we were
no longer `require`ing the path before attempting to reference the
reporter class.

Change-Id: I463f680d70461c5fe4e7300b17e82a49095b49b1
Reviewed-on: http://gerrit.causes.com/45453
Tested-by: jenkins <[email protected]>
Reviewed-by: Shane da Silva <[email protected]>
  • Loading branch information
sds committed Dec 24, 2014
1 parent ec2b899 commit 1fcce19
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Fix regression in rake task
* Fix grammar of lints reported by `SelectorFormat`
* Add .projections.json configuration file
* Fix regression in `--require` switch that caused custom formatters to
not be `require`d before they were created

## 0.31.0

Expand Down
13 changes: 13 additions & 0 deletions lib/scss_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def run(args)

def act_on_options(options)
load_required_paths(options)
load_reporters(options)

if options[:help]
print_help(options)
Expand Down Expand Up @@ -176,6 +177,18 @@ def load_required_paths(options)
end
end

def load_reporters(options)
options[:reporters].map! do |reporter_name, output_file|
begin
reporter = SCSSLint::Reporter.const_get(reporter_name + 'Reporter')
rescue NameError
raise SCSSLint::Exceptions::InvalidCLIOption,
"Invalid output format specified: #{reporter_name}"
end
[reporter, output_file]
end
end

def print_formatters
puts 'Installed formatters:'

Expand Down
14 changes: 5 additions & 9 deletions lib/scss_lint/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module SCSSLint
# Handles option parsing for the command line application.
class Options
DEFAULT_REPORTER = [SCSSLint::Reporter::DefaultReporter, :stdout]
DEFAULT_REPORTER = ['Default', :stdout]

# Parses command line options into an options hash.
#
Expand Down Expand Up @@ -48,14 +48,10 @@ def add_display_options(parser)

# @param format [String]
def define_output_format(format)
unless @options[:reporters] == [DEFAULT_REPORTER] && format == 'Default'
@options[:reporters].reject! { |i| i == DEFAULT_REPORTER }
reporter = SCSSLint::Reporter.const_get(format + 'Reporter')
@options[:reporters] << [reporter, :stdout]
end
rescue NameError
raise SCSSLint::Exceptions::InvalidCLIOption,
"Invalid output format specified: #{format}"
return if @options[:reporters] == [DEFAULT_REPORTER] && format == 'Default'

@options[:reporters].reject! { |i| i == DEFAULT_REPORTER }
@options[:reporters] << [format, :stdout]
end

def add_linter_options(parser)
Expand Down
10 changes: 1 addition & 9 deletions spec/scss_lint/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
end

it 'specifies the DefaultReporter by default' do
subject[:reporters].first.should include SCSSLint::Reporter::DefaultReporter
subject[:reporters].first.should include 'Default'
end

it 'outputs to STDOUT' do
Expand All @@ -30,13 +30,5 @@
expect { subject }.to raise_error SCSSLint::Exceptions::InvalidCLIOption
end
end

context 'when a non-existent reporter is specified' do
let(:args) { %w[--format NonExistentReporter] }

it 'raises an error' do
expect { subject }.to raise_error SCSSLint::Exceptions::InvalidCLIOption
end
end
end
end

0 comments on commit 1fcce19

Please sign in to comment.