Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
apskhem committed Mar 12, 2024
1 parent e8fe044 commit 041db23
Show file tree
Hide file tree
Showing 14 changed files with 594 additions and 564 deletions.
6 changes: 5 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
max_width = 100
max_width = 120
reorder_imports = true
tab_spaces = 2
trailing_comma = "Vertical"
Expand All @@ -8,3 +8,7 @@ control_brace_style = "AlwaysSameLine"
imports_layout = "Vertical"
imports_granularity = "Module"
group_imports = "StdExternalCrate"
reorder_impl_items = true
force_multiline_blocks = true
use_field_init_shorthand = true
use_try_shorthand = true
43 changes: 34 additions & 9 deletions src/analyzer/err.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ops::Range;

use derive_more::Display;

use pest::error::{
Error,
ErrorVariant,
Expand Down Expand Up @@ -58,15 +57,26 @@ pub enum Err {
InvalidEnum,
#[display(fmt = "Invalid data type")]
InvalidDataType,
#[display(fmt = "Invalid data type arguments: '{}' requires only {} argument(s)", raw_type, n_arg)]
#[display(
fmt = "Invalid data type arguments: '{}' requires only {} argument(s)",
raw_type,
n_arg
)]
InvalidDataTypeArguments { raw_type: String, n_arg: u32 },
#[display(fmt = "Invalid argument value: the value for the argument is not integer")]
InvalidArgumentValue,
#[display(fmt = "Invalid default value: the defualt value '{}' is not associated with '{}'", raw_value, raw_type)]
#[display(
fmt = "Invalid default value: the defualt value '{}' is not associated with '{}'",
raw_value,
raw_type
)]
InvalidDefaultValue { raw_value: String, raw_type: String },
#[display(fmt = "Default null in non-nullable: the default value cannot be null in non-nullable field")]
DefaultNullInNonNullable,
#[display(fmt = "Data type exceeded: the default value exceeds the maximum value of '{}'", raw_type)]
#[display(
fmt = "Data type exceeded: the default value exceeds the maximum value of '{}'",
raw_type
)]
DataTypeExceeded { raw_type: String },
#[display(fmt = "Table group not found")]
TableGroupNotFound,
Expand All @@ -80,8 +90,19 @@ pub enum Err {
EnumNotFound,
#[display(fmt = "Enum value not found")]
EnumValueNotFound,
#[display(fmt = "Mismatched foreign key type: '{}': '{}' (left) and '{}': '{}' (right) are incompatible", l_ident, l_type, r_ident, r_type)]
MismatchedForeignKeyType { r_ident: String, l_ident: String, r_type: String, l_type: String },
#[display(
fmt = "Mismatched foreign key type: '{}': '{}' (left) and '{}': '{}' (right) are incompatible",
l_ident,
l_type,
r_ident,
r_type
)]
MismatchedForeignKeyType {
r_ident: String,
l_ident: String,
r_type: String,
l_type: String,
},
#[display(fmt = "Invalid foreign key: {}", err)]
InvalidForeignKey { err: InvalidForeignKeyErr },
#[display(fmt = "Mismatched composite foreign key")]
Expand All @@ -96,12 +117,16 @@ pub enum InvalidForeignKeyErr {
NitherUniqueKeyNorPrimaryKeyComposite,
#[display(fmt = "either side of the one-to-one relation must be a primary key or a unique key")]
One2One,
#[display(fmt = "either side of the composite one-to-one relation must be a composite primary key or a composite unique key")]
#[display(
fmt = "either side of the composite one-to-one relation must be a composite primary key or a composite unique key"
)]
One2OneComposite,
#[display(fmt = "both sides of the many-to-many relation must be a primary key or a unique key")]
Many2Many,
#[display(fmt = "both sides of the composite many-to-many relation must be either a composite primary key or a composite unique key")]
Many2ManyComposite
#[display(
fmt = "both sides of the composite many-to-many relation must be either a composite primary key or a composite unique key"
)]
Many2ManyComposite,
}

pub(super) fn throw_err<T>(err: Err, span_range: &Range<usize>, input: &str) -> AnalyzerResult<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ pub(super) fn check_prop_duplicate_keys(attrs: &Vec<Property>, input: &str) -> A

pub(super) fn eq_elements<T: Eq + Ord>(lhs: impl Iterator<Item = T>, rhs: impl Iterator<Item = T>) -> bool {
BTreeSet::from_iter(lhs) == BTreeSet::from_iter(rhs)
}
}
Loading

0 comments on commit 041db23

Please sign in to comment.