From 4776b96d156c8bbca09b1cc13549deb6c7d705b5 Mon Sep 17 00:00:00 2001 From: Kampfkarren Date: Wed, 4 Nov 2020 22:16:57 -0800 Subject: [PATCH] Makes JSON output consistent --- CHANGELOG.md | 4 +++ Cargo.lock | 2 +- selene-lib/src/rules.rs | 2 +- selene/Cargo.toml | 2 +- selene/src/json_output.rs | 54 +++++++++++++++++++++++++++++++++++++++ selene/src/main.rs | 8 +++++- 6 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 selene/src/json_output.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index c91b84c0..6a0cb966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.1] - 2020-11-04 +### Fixed +- Fixed `--display-style=json` giving an output incompatible with previous tooling. + ## [0.9.0] - 2020-11-04 ### Added - Arguments that aren't required can now be filled with nil. diff --git a/Cargo.lock b/Cargo.lock index eaa9202e..36ee615a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1384,7 +1384,7 @@ dependencies = [ [[package]] name = "selene" -version = "0.9.0" +version = "0.9.1" dependencies = [ "atty", "cfg-if 0.1.10", diff --git a/selene-lib/src/rules.rs b/selene-lib/src/rules.rs index 4aebb2a1..821d8b6a 100644 --- a/selene-lib/src/rules.rs +++ b/selene-lib/src/rules.rs @@ -125,7 +125,7 @@ impl Diagnostic { code: Some(self.code.to_owned()), labels, message: self.message.to_owned(), - notes: self.notes.to_owned(), + notes: self.notes, severity, } } diff --git a/selene/Cargo.toml b/selene/Cargo.toml index ba641116..9a730c46 100644 --- a/selene/Cargo.toml +++ b/selene/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "selene" -version = "0.9.0" +version = "0.9.1" license = "MPL-2.0" authors = ["Kampfkarren "] description = "A blazing-fast modern Lua linter written in Rust" diff --git a/selene/src/json_output.rs b/selene/src/json_output.rs new file mode 100644 index 00000000..3a59e6cd --- /dev/null +++ b/selene/src/json_output.rs @@ -0,0 +1,54 @@ +use codespan_reporting::diagnostic::{ + Diagnostic as CodespanDiagnostic, Label as CodespanLabel, LabelStyle, Severity, +}; +use serde::Serialize; + +#[derive(Serialize)] +struct JsonDiagnostic { + severity: Severity, + code: Option, + message: String, + primary_label: Label, + notes: Vec, + secondary_labels: Vec