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

[Fix #9617] Disable suggested extensions when using the --stdin option #9618

Merged
merged 1 commit into from Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
* [#9617](https://github.com/rubocop/rubocop/issues/9617): Disable suggested extensions when using the `--stdin` option. ([@dvandersluis][])
3 changes: 2 additions & 1 deletion lib/rubocop/cli/command/suggest_extensions.rb
Expand Up @@ -43,7 +43,8 @@ def skip?
# 2. When given RuboCop options that it doesn't make sense for
# 3. For all formatters except specified in `INCLUDED_FORMATTERS'`
ENV['CI'] ||
@options[:only] || @options[:debug] || @options[:list_target_files] || @options[:out] ||
@options[:only] || @options[:debug] || @options[:list_target_files] ||
@options[:out] || @options[:stdin] ||
!INCLUDED_FORMATTERS.include?(current_formatter)
end

Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cli_spec.rb
Expand Up @@ -2057,6 +2057,17 @@ def find_suggestions
end
end

context 'when given --stdin' do
it 'does not show the suggestion' do
begin
$stdin = StringIO.new('p $/')
expect { cli.run(['--stdin', 'example.rb']) }.not_to suggest_extensions
ensure
$stdin = STDIN
end
end
end

context 'when given a non-supported formatter' do
it 'does not show the suggestion' do
expect { cli.run(['example.rb', '--format', 'simple']) }.not_to suggest_extensions
Expand Down