Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/cli/src/analyser/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Analyser {
super::loader::load_from_path(path)
}

pub fn report(&mut self, will_exit: bool) {
pub fn report(&mut self, will_exit: bool, with_warning: bool) {
// Run analysis passes
for dt in self.data_types.clone() {
self.analyse_data_type(&dt);
Expand All @@ -50,7 +50,7 @@ impl Analyser {
for f in self.functions.clone() {
self.analyse_runtime_function(&f);
}
self.reporter.print(will_exit);
self.reporter.print(will_exit, true, with_warning);
}

pub fn data_type_identifier_exists(&self, identifier: &str, except_id: Option<i16>) -> bool {
Expand Down
19 changes: 19 additions & 0 deletions crates/cli/src/analyser/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ impl Analyser {
));
}

if dt.alias.is_empty() {
self.reporter.add(Diagnose::new(
dt.identifier.clone(),
adt.original_definition.clone(),
DiagnosticKind::MissingTranslation {
translation_field: "alias".into(),
},
));
}

if dt.display_message.is_empty() {
self.reporter.add(Diagnose::new(
dt.identifier.clone(),
adt.original_definition.clone(),
DiagnosticKind::MissingTranslation {
translation_field: "displayMessage".into(),
},
));
}
let mut detected: Vec<String> = vec![];
for optional_rule in &dt.rules {
if let Some(config) = &optional_rule.config {
Expand Down
29 changes: 29 additions & 0 deletions crates/cli/src/analyser/flow_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ impl Analyser {
let name = flow.identifier.clone();
let original = aft.original_definition.clone();

if flow.display_icon.is_empty() {
self.reporter.add(Diagnose::new(
name.clone(),
original.clone(),
DiagnosticKind::NullField {
field_name: "displayIcon".into(),
},
))
}
if flow.alias.is_empty() {
self.reporter.add(Diagnose::new(
name.clone(),
original.clone(),
DiagnosticKind::MissingTranslation {
translation_field: "alias".into(),
},
));
}

if flow.display_message.is_empty() {
self.reporter.add(Diagnose::new(
name.clone(),
original.clone(),
DiagnosticKind::MissingTranslation {
translation_field: "displayMessage".into(),
},
));
}

if flow.name.is_empty() {
self.reporter.add(Diagnose::new(
name.clone(),
Expand Down
30 changes: 30 additions & 0 deletions crates/cli/src/analyser/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@ impl Analyser {
let function = &af.function;
let original = af.original_definition.clone();

if function.display_icon.is_empty() {
self.reporter.add(Diagnose::new(
name.clone(),
original.clone(),
DiagnosticKind::NullField {
field_name: "displayIcon".into(),
},
))
}

if function.alias.is_empty() {
self.reporter.add(Diagnose::new(
name.clone(),
original.clone(),
DiagnosticKind::MissingTranslation {
translation_field: "alias".into(),
},
));
}

if function.display_message.is_empty() {
self.reporter.add(Diagnose::new(
name.clone(),
original.clone(),
DiagnosticKind::MissingTranslation {
translation_field: "displayMessage".into(),
},
));
}

if function.name.is_empty() {
self.reporter.add(Diagnose::new(
name.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn search_feature(name: Option<String>, path: Option<String>) {
};

let mut analyser = Analyser::new(dir_path.as_str());
analyser.report(true);
analyser.report(true, true);

let features = match name {
None => parser.features.clone(),
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/command/push/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn push(token: String, url: String, path: Option<String>) {
info(String::from("Press Ctrl+C to stop watching..."));

{
Analyser::new(dir_path.as_str()).report(false);
Analyser::new(dir_path.as_str()).report(false, true);
}

// Set up file watcher
Expand Down Expand Up @@ -82,7 +82,7 @@ pub async fn push(token: String, url: String, path: Option<String>) {
.await;
}

analyzer.report(false);
analyzer.report(false, true);

last_run = Instant::now();
}
Expand Down Expand Up @@ -126,7 +126,7 @@ pub async fn push(token: String, url: String, path: Option<String>) {
.await;
}

analyzer.report(false);
analyzer.report(false, true);
last_run = Instant::now();
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn report_errors(path: Option<String>) {
};

let mut analyser = Analyser::new(dir_path.as_str());
analyser.report(true);
analyser.report(true, true);

let rows = summary_table(&parser.features);
success_table(rows);
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/src/command/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use notify::{EventKind, RecursiveMode, Watcher, recommended_watcher};
use std::sync::mpsc::channel;
use std::time::{Duration, Instant};

pub async fn watch_for_changes(path: Option<String>) {
pub async fn watch_for_changes(path: Option<String>, with_warning: bool) {
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());

info(format!("Watching directory: {dir_path}"));
info(String::from("Press Ctrl+C to stop watching..."));

{
Analyser::new(dir_path.as_str()).report(false);
Analyser::new(dir_path.as_str()).report(false, with_warning);
}

// Set up file watcher
Expand All @@ -35,7 +35,7 @@ pub async fn watch_for_changes(path: Option<String>) {
"\n\n\n--------------------------------------------------------------------------\n\n",
));
info(String::from("Change detected! Regenerating report..."));
Analyser::new(dir_path.as_str()).report(false);
Analyser::new(dir_path.as_str()).report(false, with_warning);
last_run = Instant::now();
}
}
Expand All @@ -45,7 +45,7 @@ pub async fn watch_for_changes(path: Option<String>) {
"\n\n\n--------------------------------------------------------------------------\n\n",
));
info(String::from("Change detected! Regenerating report..."));
Analyser::new(dir_path.as_str()).report(false);
Analyser::new(dir_path.as_str()).report(false, with_warning);
last_run = Instant::now();
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/cli/src/diagnostics/diagnose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ impl Diagnose {
),
&path,
),
MissingTranslation { translation_field } => error(
format!(
"`{}` has an required empty field (`{}`) of translations!",
self.definition_name, translation_field
),
&path,
),
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/diagnostics/kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum DiagnosticKind {
UnusedGenericKey { key: String },
UndefinedGenericKey { key: String },
UndefinedTranslation { translation_field: String },
MissingTranslation { translation_field: String },
}

impl DiagnosticKind {
Expand All @@ -32,7 +33,8 @@ impl DiagnosticKind {
| NullField { .. }
| ForbiddenVariant
| UnusedGenericKey { .. }
| UndefinedGenericKey { .. } => Severity::Error,
| UndefinedGenericKey { .. }
| MissingTranslation { .. } => Severity::Error,
UndefinedTranslation { .. } => Severity::Warning,
}
}
Expand Down
16 changes: 11 additions & 5 deletions crates/cli/src/diagnostics/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ impl Reporter {
self.diagnostics.is_empty()
}

pub fn print(&self, will_exit: bool) {
for d in self.errors() {
println!("{}", d.print());
pub fn print(&self, will_exit: bool, print_errors: bool, print_warning: bool) {
if print_warning {
for d in self.warnings() {
println!("{}", d.print());
}
}
for d in self.warnings() {
println!("{}", d.print());

if print_errors {
for d in self.errors() {
println!("{}", d.print());
}
}

if self
.diagnostics
.iter()
Expand Down
8 changes: 7 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ enum Commands {
/// Optional path to root directory of all definitions.
#[arg(short, long)]
path: Option<String>,
/// Should ignore warnings, true on default
#[arg(short, long, default_value_t = false)]
ignore_warnings: bool,
},
Push {
/// Runtime Token for Sagittarius.
Expand Down Expand Up @@ -80,7 +83,10 @@ async fn main() {
Commands::Download { tag, features } => {
command::download::handle_download(tag, features).await
}
Commands::Watch { path } => command::watch::watch_for_changes(path).await,
Commands::Watch {
path,
ignore_warnings,
} => command::watch::watch_for_changes(path, !ignore_warnings).await,
Commands::Push { token, url, path } => command::push::push(token, url, path).await,
}
}