-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Offer RuboCop autocorrection for contextual offenses (#2171)
When `RuboCop::LSP.enable` is called, contextual autocorrect will not offer itself as `correctable?` to prevent annoying changes while typing. Instead check if a corrector is present. If it is, then that means some code transformation can be applied.
- Loading branch information
Showing
3 changed files
with
121 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
test/expectations/diagnostics/rubocop_contextual_autocorrect.exp.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"result": [ | ||
{ | ||
"range": { | ||
"start": { | ||
"line": 4, | ||
"character": 2 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"character": 5 | ||
} | ||
}, | ||
"severity": 2, | ||
"source": "Prism", | ||
"message": "assigned but unused variable - foo" | ||
}, | ||
{ | ||
"range": { | ||
"start": { | ||
"line": 4, | ||
"character": 2 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"character": 5 | ||
} | ||
}, | ||
"severity": 2, | ||
"code": "Lint/UselessAssignment", | ||
"codeDescription": { | ||
"href": "https://docs.rubocop.org/rubocop/cops_lint.html#lintuselessassignment" | ||
}, | ||
"source": "RuboCop", | ||
"message": "Lint/UselessAssignment: Useless assignment to variable - `foo`.", | ||
"data": { | ||
"correctable": true, | ||
"code_actions": [ | ||
{ | ||
"title": "Autocorrect Lint/UselessAssignment", | ||
"kind": "quickfix", | ||
"isPreferred": true, | ||
"edit": { | ||
"documentChanges": [ | ||
{ | ||
"textDocument": { | ||
"uri": "file:///fake", | ||
"version": null | ||
}, | ||
"edits": [ | ||
{ | ||
"range": { | ||
"start": { | ||
"line": 4, | ||
"character": 2 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"character": 13 | ||
} | ||
}, | ||
"newText": "\"bar\"" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"title": "Disable Lint/UselessAssignment for this line", | ||
"kind": "quickfix", | ||
"edit": { | ||
"documentChanges": [ | ||
{ | ||
"textDocument": { | ||
"uri": "file:///fake", | ||
"version": null | ||
}, | ||
"edits": [ | ||
{ | ||
"range": { | ||
"start": { | ||
"line": 4, | ||
"character": 13 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"character": 13 | ||
} | ||
}, | ||
"newText": " # rubocop:disable Lint/UselessAssignment" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
def useless_assignment | ||
foo = "bar" | ||
baz | ||
end |