Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always outputs to STDOUT even if --out specified #14

Closed
aeberlin opened this issue Oct 1, 2014 · 6 comments
Closed

Always outputs to STDOUT even if --out specified #14

aeberlin opened this issue Oct 1, 2014 · 6 comments

Comments

@aeberlin
Copy link

aeberlin commented Oct 1, 2014

Hi,

I recently discovered a bug in the runner which results in output being piped to $stdout even if the --out option is specified in the cli. Here are the steps to replicate:

  • Clone example project: git clone git@github.com:aeberlin/guard_example.git
  • Open up the project directory and replace RUBOCOP_OPTS in Guardfile with the text below:
RUBOCOP_OPTS = {
  all_on_start: false,
  cli: '--format RuboCop::Formatter::ClangStyleFormatter --out tmp/rubocop_results.log',
  notification: false
}
  • Run rake and allow to load, then touch lib/guard_example/foo.rb

Notice how output for the default formatter is redirected to $stdout in addition to the results for ProgressFormatter being written to tmp/progress_results.log.

For comparison, run a few of the statements below from bash and review the results.

rubocop --format RuboCop::Formatter::ProgressFormatter --out tmp/progress_results.log lib/guard_example/foo.rb
rubocop --out tmp/default_results.log --format RuboCop::Formatter::ClangStyleFormatter --out tmp/clang_results.log lib/guard_example/foo.rb

As you can see, the default formatter is properly omitted in the first example and then properly retained in the second example, with the specified formatter results always written to the designated path.

If you try to forcibly redirect output for the default formatter to another file, using the configuration below, you can also see that the results are still piped to $stdout.

RUBOCOP_OPTS = {
  all_on_start: false,
  cli: '--out tmp/default_results.log --format RuboCop::Formatter::ClangStyleFormatter --out tmp/progress_results.log',
  notification: true
}

Any thoughts?

Thanks, cheers!

@aeberlin
Copy link
Author

aeberlin commented Oct 6, 2014

Also, here are the versions I'm using. I will test later to see if this occurs with previous versions:

bundler (1.7.0)
cucumber (1.3.17)
guard (2.6.1)
guard-cucumber (1.4.1)
guard-rspec (4.3.1)
guard-rubocop (1.1.0)
guard-shell (0.6.1)
guard-shotgun (0.4.0)
rake (10.1.0)
rspec (3.1.0, 3.0.0)
rspec-core (3.1.3, 3.1.2, 3.0.4)
rspec-expectations (3.1.1, 3.1.0, 3.0.4)
rspec-mocks (3.1.0, 3.0.4)
rspec-support (3.1.0, 3.0.4)
rubocop (0.26.1, 0.26.0, 0.25.0)
terminal-notifier-guard (1.5.3)

@aeberlin
Copy link
Author

Looking through the source, I believe the problem lies here.

# lib/guard/rubocop/runner.rb

def include_formatter_for_console?(cli_args)
  index = -1
  formatter_args = cli_args.group_by do |arg|
    index += 1 if arg == '--format' || arg.start_with?('-f')
    index
  end
  formatter_args.delete(-1)

  formatter_args.each_value.any? do |args|
    args.none? { |a| a == '--out' || a.start_with?('-o') }
  end
end

The way the code is written, it expects that you will always want console output if an additional formatter and output source is specified, but that's not always the case. Please see the pull request in Issue #15.

@dolfolife
Copy link

👍

1 similar comment
@ashtonthomas
Copy link

👍

@aeberlin
Copy link
Author

Are you active?

@yujinakayama
Copy link
Collaborator

Closing as #15 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants