Skip to content

Commit

Permalink
Add Fix::applicability to JSON output
Browse files Browse the repository at this point in the history
Add the `Fix::applicability` to the JSON output.
I'll use the presence of the new field to detect whether this ruff version emits
one-based indices for edits or not.
  • Loading branch information
MichaReiser committed May 10, 2023
1 parent a2b8487 commit b809be9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions crates/ruff/src/message/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ impl Serialize for ExpandedMessages<'_> {

let fix = message.fix.as_ref().map(|fix| {
json!({
"message": message.kind.suggestion.as_deref(),
"edits": &ExpandedEdits { edits: fix.edits(), source_code: &source_code },
"applicability": fix.applicability(),
"message": message.kind.suggestion.as_deref(),
"edits": &ExpandedEdits { edits: fix.edits(), source_code: &source_code },
})
});

Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,13 @@ def fibonacci(n):

let fib_source = SourceFileBuilder::new("fib.py", fib).finish();

#[allow(deprecated)]
let unused_variable = Diagnostic::new(
UnusedVariable {
name: "x".to_string(),
},
TextRange::new(TextSize::from(94), TextSize::from(95)),
)
.with_fix(Fix::unspecified(Edit::deletion(
.with_fix(Fix::suggested(Edit::deletion(
TextSize::from(94),
TextSize::from(99),
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ expression: content
"code": "F401",
"message": "`os` imported but unused",
"fix": {
"applicability": "Suggested",
"message": "Remove unused import: `os`",
"edits": [
{
Expand Down Expand Up @@ -37,6 +38,7 @@ expression: content
"code": "F841",
"message": "Local variable `x` is assigned to but never used",
"fix": {
"applicability": "Suggested",
"message": "Remove assignment to unused variable `x`",
"edits": [
{
Expand Down

0 comments on commit b809be9

Please sign in to comment.