-
Notifications
You must be signed in to change notification settings - Fork 286
Rubocop warnings with zero length do not show up in editor #466
Comments
I'm sure it is required as VSCode uses a 0 offset while RuboCop uses a 1 offset. Do you have an example file I can use? |
Is this true for both lines and columns? Example
# frozen_string_literal: true
class SomeController < ApplicationController
def show
@record = Record.find(params[:id])
# end
end
{
"metadata": {
"rubocop_version": "0.65.0",
"ruby_engine": "ruby",
"ruby_version": "2.6.2",
"ruby_patchlevel": "47",
"ruby_platform": "x86_64-darwin18"
},
"files": [
{
"path": "some_controller.rb",
"offenses": [
{
"severity": "error",
"message": "Lint/Syntax: unexpected token $end\n(Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)",
"cop_name": "Lint/Syntax",
"corrected": false,
"location": {
"start_line": 8,
"start_column": 1,
"last_line": 8,
"last_column": 0,
"length": 0,
"line": 8,
"column": 1
}
}
]
}
],
"summary": {
"offense_count": 1,
"target_file_count": 1,
"inspected_file_count": 1
}
} diff --git a/server/src/linters/RuboCop.ts b/server/src/linters/RuboCop.ts
index 2bc01c4..df27c20 100644
--- a/server/src/linters/RuboCop.ts
+++ b/server/src/linters/RuboCop.ts
@@ -71,6 +71,7 @@ export default class RuboCop extends BaseLinter {
const offenses: IRuboCopResults = JSON.parse(data);
for (const file of offenses.files) {
+ file.offenses.forEach(o => console.log(this.rubocopOffenseToDiagnostic(o)));
const diagnostics = file.offenses.map(o => this.rubocopOffenseToDiagnostic(o));
results = results.concat(diagnostics);
} Current behaviorRuby Language Server (Output)
Note Proposed changesdiff --git a/server/src/linters/RuboCop.ts b/server/src/linters/RuboCop.ts
index 2bc01c4..df27c20 100644
--- a/server/src/linters/RuboCop.ts
+++ b/server/src/linters/RuboCop.ts
@@ -91,7 +92,7 @@ export default class RuboCop extends BaseLinter {
},
end: {
line: offense.location.line - 1,
- character: offenseCharacter + offense.location.length - 1,
+ character: offenseCharacter + offense.location.length,
},
},
severity: this.DIAGNOSTIC_SEVERITIES[offense.severity], Ruby Language Server (Output)
Note 1 Problem |
yes it is true. You aren't taking into account that RuboCop is outputting an end position before the start position for this particular error. That's why it appears to "work" when you remove the subtraction. |
def foo
end Does that give you an |
Yes. Interestingly with both current behavior and proposed changes. {
"metadata": {
"rubocop_version": "0.65.0",
"ruby_engine": "ruby",
"ruby_version": "2.6.2",
"ruby_patchlevel": "47",
"ruby_platform": "x86_64-darwin18"
},
"files": [
{
"path": "some_controller.rb",
"offenses": [
{
"severity": "warning",
"message": "Lint/UselessAssignment: Useless assignment to variable - `unused`.",
"cop_name": "Lint/UselessAssignment",
"corrected": false,
"location": {
"start_line": 9,
"start_column": 5,
"last_line": 9,
"last_column": 10,
"length": 6,
"line": 9,
"column": 5
}
},
{
"severity": "convention",
"message": "Style/EmptyMethod: Put empty method definitions on a single line.",
"cop_name": "Style/EmptyMethod",
"corrected": false,
"location": {
"start_line": 12,
"start_column": 3,
"last_line": 13,
"last_column": 5,
"length": 13,
"line": 12,
"column": 3
}
}
]
}
],
"summary": {
"offense_count": 2,
"target_file_count": 1,
"inspected_file_count": 1
}
} Current behaviorProposed changesI agree it's probably not as straightforward as I think. Thanks for taking a closer look! |
Attempting to avoid any misconceptions, main issue being here that VSCode does not detect some errors at all (apparently those with |
I think there's two things that need fixed here:
|
Any news? Can I help? |
I'm troubleshooting a variety of RuboCop related errors. This will be looked at but there are A) more pressing bugs and B) I have limited time right now to spend on this. In addition, I'm trying to get a test suite/harness set up to allow easier community contribution. It'll get done but I've got a full time job + other life obligations. |
See this extension. It doesn't run into the issues here maybe you could compare your code to its code. |
@wingrunr21 Sorry, I did not mean to put you under pressure. Thank you for your effort! |
Just want to add I’m also seeing this issue on a ruby 2.6.3 project. Tried a few things anencephaly have been looking into the code and will update with a solution or PR if I find the problem. |
Your environment
vscode-ruby
version: 0.22.3Expected behavior
Extension reports all warnings detected by
rubocop
as problems and decorates significant characters.Actual behavior
I'm having the issue that some warnings reported by
rubocop
(when run manually) do not show up in the editor (0 problems, no decorations). I noticed this applies to errors wherestart_column/last_column
in JSON output ofrubocop
are identical.Hints
vscode-ruby/server/src/linters/RuboCop.ts
Lines 87 to 95 in 2d8e443
Are you sure it's required to subtract from
offense.location.length
? Removing the subtraction appears to fix this error and also a glitch where the last character of an error is not decorated.The text was updated successfully, but these errors were encountered: