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 #11033] Change warning message for Lint/Syntax when using LSP #12586

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
6 changes: 6 additions & 0 deletions lib/rubocop/cop/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ def range_for_original(range)
range.end_pos + @current_offset
)
end

# This experimental feature has been under consideration for a while.
# @api private
def lsp_mode?
ARGV.include?('--lsp')
end
end
end
end
9 changes: 6 additions & 3 deletions lib/rubocop/cop/lint/syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ def on_other_file
private

def add_offense_from_diagnostic(diagnostic, ruby_version)
message =
"#{diagnostic.message}\n(Using Ruby #{ruby_version} parser; " \
'configure using `TargetRubyVersion` parameter, under `AllCops`)'
message = if lsp_mode?
diagnostic.message
else
"#{diagnostic.message}\n(Using Ruby #{ruby_version} parser; " \
'configure using `TargetRubyVersion` parameter, under `AllCops`)'
end
add_offense(diagnostic.location, message: message, severity: diagnostic.level)
end

Expand Down
6 changes: 6 additions & 0 deletions lib/rubocop/rspec/shared_contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def source_range(range, buffer: source_buffer)
end
end

RSpec.shared_context 'lsp mode' do
before do
allow(cop).to receive(:lsp_mode?).and_return(true)
end
end

RSpec.shared_context 'ruby 2.0' do
let(:ruby_version) { 2.0 }
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/rspec/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
config.include HostEnvironmentSimulatorHelper
config.include_context 'config', :config
config.include_context 'isolated environment', :isolated_environment
config.include_context 'lsp mode', :lsp_mode
config.include_context 'maintain registry', :restore_registry
config.include_context 'ruby 2.0', :ruby20
config.include_context 'ruby 2.1', :ruby21
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/lint/syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
expect(offense.severity).to eq(:fatal)
end
end

context 'with `--lsp` option', :lsp_mode do
it 'does not include a configuration information in the offense message' do
expect(offenses.first.message).to eq('unexpected token $end')
end
end
end

context 'with a parser error' do
Expand Down