Skip to content

Commit

Permalink
[Fix rubocop#9617] Disable suggested extensions when using the `--std…
Browse files Browse the repository at this point in the history
…in` option.
  • Loading branch information
dvandersluis committed Mar 18, 2021
1 parent 5cd6116 commit e1f7ec4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
@@ -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

0 comments on commit e1f7ec4

Please sign in to comment.