Skip to content

Commit

Permalink
Revert one-indexed columns for JSON ouptut
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Apr 20, 2023
1 parent ab7438e commit 49cdd85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions crates/ruff/src/message/json.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::message::{Emitter, EmitterContext, Message};
use crate::registry::AsRule;
use ruff_diagnostics::Edit;
use ruff_python_ast::source_code::SourceCode;
use ruff_python_ast::source_code::{SourceCode, SourceLocation};
use serde::ser::SerializeSeq;
use serde::{Serialize, Serializer};
use serde_json::json;
use serde_json::{json, Value};
use std::io::Write;

#[derive(Default)]
Expand Down Expand Up @@ -84,8 +84,8 @@ impl Serialize for ExpandedEdits<'_> {
let end_location = self.source_code.source_location(edit.end());
let value = json!({
"content": edit.content().unwrap_or_default(),
"location": start_location,
"end_location": end_location
"location": to_zero_indexed_column(&start_location),
"end_location": to_zero_indexed_column(&end_location)
});

s.serialize_element(&value)?;
Expand All @@ -95,6 +95,13 @@ impl Serialize for ExpandedEdits<'_> {
}
}

fn to_zero_indexed_column(location: &SourceLocation) -> Value {
json!({
"row": location.row,
"column": location.column.to_zero_indexed()
})
}

#[cfg(test)]
mod tests {
use crate::message::tests::{capture_emitter_output, create_messages};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ expression: content
"content": "",
"location": {
"row": 6,
"column": 5
"column": 4
},
"end_location": {
"row": 6,
"column": 10
"column": 9
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_cli/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ fn test_stdin_json() -> Result<()> {
"content": "",
"location": {{
"row": 1,
"column": 1
"column": 0
}},
"end_location": {{
"row": 2,
"column": 1
"column": 0
}}
}}
]
Expand Down

0 comments on commit 49cdd85

Please sign in to comment.