Skip to content

Commit

Permalink
Use target instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
GearsDatapacks authored and lpil committed Nov 20, 2024
1 parent 425326a commit 56d0d61
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
4 changes: 2 additions & 2 deletions compiler-core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3298,15 +3298,15 @@ functions are declared separately from types.";
self.warnings
.push(DeprecatedSyntaxWarning::DeprecatedTargetShorthand {
location: SrcSpan { start, end },
full_name: "javascript",
target: Target::JavaScript,
});
Ok(Target::JavaScript)
}
"erl" => {
self.warnings
.push(DeprecatedSyntaxWarning::DeprecatedTargetShorthand {
location: SrcSpan { start, end },
full_name: "erlang",
target: Target::Erlang,
});
Ok(Target::Erlang)
}
Expand Down
66 changes: 39 additions & 27 deletions compiler-core/src/warning.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
ast::{SrcSpan, TodoKind},
build::Target,
diagnostic::{self, Diagnostic, Location},
error::wrap,
type_::{
Expand Down Expand Up @@ -167,7 +168,9 @@ pub enum Warning {
pub enum DeprecatedSyntaxWarning {
/// If someone uses the deprecated syntax to append to a list:
/// `["a"..rest]`, notice how there's no comma!
DeprecatedListPrepend { location: SrcSpan },
DeprecatedListPrepend {
location: SrcSpan,
},

/// If someone uses the deprecated syntax to pattern match on a list:
/// ```gleam
Expand All @@ -178,7 +181,9 @@ pub enum DeprecatedSyntaxWarning {
/// }
/// ```
///
DeprecatedListPattern { location: SrcSpan },
DeprecatedListPattern {
location: SrcSpan,
},

/// If someone uses the deprecated syntax to match on all lists instead of
/// a common `_`:
Expand All @@ -190,7 +195,9 @@ pub enum DeprecatedSyntaxWarning {
/// }
/// ```
///
DeprecatedListCatchAllPattern { location: SrcSpan },
DeprecatedListCatchAllPattern {
location: SrcSpan,
},

/// If a record pattern has a spread that is not preceded by a comma:
/// ```gleam
Expand All @@ -200,10 +207,12 @@ pub enum DeprecatedSyntaxWarning {
/// }
/// ```
///
DeprecatedRecordSpreadPattern { location: SrcSpan },
DeprecatedRecordSpreadPattern {
location: SrcSpan,
},

DeprecatedTargetShorthand {
full_name: &'static str,
target: Target,
location: SrcSpan,
},
}
Expand Down Expand Up @@ -319,28 +328,31 @@ To match on all possible lists, use the `_` catch-all pattern instead.",
Warning::DeprecatedSyntax {
path,
src,
warning:
DeprecatedSyntaxWarning::DeprecatedTargetShorthand {
location,
full_name,
},
} => Diagnostic {
title: "Deprecated target shorthand syntax".into(),
text: wrap(&format!(
"This shorthand target name is deprecated. Use the full name: `{full_name}` instead."
)),
hint: None,
level: diagnostic::Level::Warning,
location: Some(Location {
label: diagnostic::Label {
text: Some(format!("This should be replaced with `{full_name}`")),
span: *location,
},
path: path.clone(),
src: src.clone(),
extra_labels: vec![],
}),
},
warning: DeprecatedSyntaxWarning::DeprecatedTargetShorthand { location, target },
} => {
let full_name = match target {
Target::Erlang => "erlang",
Target::JavaScript => "javascript",
};

Diagnostic {
title: "Deprecated target shorthand syntax".into(),
text: wrap(&format!(
"This shorthand target name is deprecated. Use the full name: `{full_name}` instead."
)),
hint: None,
level: diagnostic::Level::Warning,
location: Some(Location {
label: diagnostic::Label {
text: Some(format!("This should be replaced with `{full_name}`")),
span: *location,
},
path: path.clone(),
src: src.clone(),
extra_labels: vec![],
}),
}
}

Self::Type { path, warning, src } => match warning {
type_::Warning::Todo {
Expand Down

0 comments on commit 56d0d61

Please sign in to comment.