diff --git a/changelog/change_disable_suggested_extensions_when_using.md b/changelog/change_disable_suggested_extensions_when_using.md new file mode 100644 index 00000000000..2d464669716 --- /dev/null +++ b/changelog/change_disable_suggested_extensions_when_using.md @@ -0,0 +1 @@ +* [#9617](https://github.com/rubocop/rubocop/issues/9617): Disable suggested extensions when using the `--stdin` option. ([@dvandersluis][]) diff --git a/lib/rubocop/cli/command/suggest_extensions.rb b/lib/rubocop/cli/command/suggest_extensions.rb index 468f9f033b3..c71fc697717 100644 --- a/lib/rubocop/cli/command/suggest_extensions.rb +++ b/lib/rubocop/cli/command/suggest_extensions.rb @@ -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 diff --git a/spec/rubocop/cli_spec.rb b/spec/rubocop/cli_spec.rb index a3b7a366d4b..cd02752cc3a 100644 --- a/spec/rubocop/cli_spec.rb +++ b/spec/rubocop/cli_spec.rb @@ -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