Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Formatting using rubocop garbles document #519

Closed
tkoenig opened this issue Aug 21, 2019 · 0 comments
Closed

Formatting using rubocop garbles document #519

tkoenig opened this issue Aug 21, 2019 · 0 comments
Assignees
Labels
bug Bug reports

Comments

@tkoenig
Copy link

tkoenig commented Aug 21, 2019

Your environment

  • vscode-ruby version: 0.24.2
  • Ruby version: 2.6.2
  • Ruby version manager (if any):
  • VS Code version: 1.37.1
  • Operating System: macOS Mojave 10.14.5
  • Using language server? (eg useLanguageServer is true?) Yes

Expected behavior

It should format correctly the following file using rubocop:

Input:

# frozen_string_literal: true

puts "this is a test"
puts "\n=========================================================="
puts "okokokok"

Expected output (works when using rubocop standalone):

# frozen_string_literal: true

puts 'this is a test'
puts "\n=========================================================="
puts 'okokokok'

Actual behavior

The actual output when calling Format document removes most of the document:

"
puts 'okokokok'

More info

It looks like the issue is when parsing the output from rubocop it
thinks that the line with multiple ==== is the marker from rubocop when the actual file content starts.

~ ruby-2.6.2 🍔  cat test-rubocop.rb | rubocop -s test-rubocop.rb -a 
Inspecting 1 file
C

Offenses:

test-rubocop.rb:1:1: C: Naming/FileName: The name of this source file (test-rubocop.rb) should use snake_case.
# frozen_string_literal: true
^
test-rubocop.rb:3:6: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
puts "this is a test"
     ^^^^^^^^^^^^^^^^
test-rubocop.rb:5:6: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
puts "okokokok"
     ^^^^^^^^^^

1 file inspected, 3 offenses detected, 2 offenses corrected
====================
# frozen_string_literal: true

puts 'this is a test'
puts "\n=========================================================="
puts 'okokokok'
tkoenig added a commit to tkoenig/vscode-ruby that referenced this issue Aug 21, 2019
This would be a quick fix for rubyide#519. (I tested this quickly modifying the extensions js file)

Given more thought it might be better to get the **first** instance of `FORMATTED_OUTPUT_DELIMITER`and not the last one to detect the end of rubocop diagnostics?
@wingrunr21 wingrunr21 self-assigned this Aug 26, 2019
@wingrunr21 wingrunr21 added the bug Bug reports label Aug 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug reports
Projects
None yet
Development

No branches or pull requests

2 participants