diff --git a/crates/document-tree/src/lib.rs b/crates/document-tree/src/lib.rs index 6f36f2aa..44cf0d7e 100644 --- a/crates/document-tree/src/lib.rs +++ b/crates/document-tree/src/lib.rs @@ -2,6 +2,7 @@ mod error; mod key; pub mod support; mod value; +mod value_type; pub use error::Error; pub use key::{Key, KeyKind}; @@ -12,6 +13,7 @@ pub use value::{ Array, ArrayKind, Boolean, Float, Integer, IntegerKind, LocalDate, LocalDateTime, LocalTime, OffsetDateTime, String, StringKind, Table, TableKind, Value, }; +pub use value_type::ValueType; #[derive(Debug, Clone, PartialEq)] pub struct Root(Table); @@ -36,6 +38,12 @@ enum RootItem { KeyValue(Table), } +pub trait ValueImpl { + fn value_type(&self) -> ValueType; + + fn range(&self) -> text::Range; +} + pub trait TryIntoDocumentTree { fn try_into_document_tree(self, toml_version: TomlVersion) -> Result>; } diff --git a/crates/document-tree/src/value.rs b/crates/document-tree/src/value.rs index 7722ee88..c2434793 100644 --- a/crates/document-tree/src/value.rs +++ b/crates/document-tree/src/value.rs @@ -65,6 +65,27 @@ impl Value { } } +impl crate::ValueImpl for Value { + fn value_type(&self) -> crate::ValueType { + match self { + Value::Boolean(boolean) => boolean.value_type(), + Value::Integer(integer) => integer.value_type(), + Value::Float(float) => float.value_type(), + Value::String(string) => string.value_type(), + Value::OffsetDateTime(offset_date_time) => offset_date_time.value_type(), + Value::LocalDateTime(local_date_time) => local_date_time.value_type(), + Value::LocalDate(local_date) => local_date.value_type(), + Value::LocalTime(local_time) => local_time.value_type(), + Value::Array(array) => array.value_type(), + Value::Table(table) => table.value_type(), + } + } + + fn range(&self) -> text::Range { + self.range() + } +} + impl TryIntoDocumentTree for ast::Value { fn try_into_document_tree( self, diff --git a/crates/document-tree/src/value/array.rs b/crates/document-tree/src/value/array.rs index 593069ab..fb721a03 100644 --- a/crates/document-tree/src/value/array.rs +++ b/crates/document-tree/src/value/array.rs @@ -1,6 +1,6 @@ use ast::AstNode; -use crate::{support::comment::try_new_comment, TryIntoDocumentTree, Value}; +use crate::{support::comment::try_new_comment, TryIntoDocumentTree, Value, ValueImpl, ValueType}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum ArrayKind { @@ -153,6 +153,16 @@ impl Array { } } +impl ValueImpl for Array { + fn value_type(&self) -> ValueType { + ValueType::Array + } + + fn range(&self) -> text::Range { + self.range() + } +} + impl TryIntoDocumentTree for ast::Array { fn try_into_document_tree( self, diff --git a/crates/document-tree/src/value/boolean.rs b/crates/document-tree/src/value/boolean.rs index 08b1d712..bf0947b9 100644 --- a/crates/document-tree/src/value/boolean.rs +++ b/crates/document-tree/src/value/boolean.rs @@ -1,3 +1,5 @@ +use crate::{ValueImpl, ValueType}; + #[derive(Debug, Clone, PartialEq, Eq)] pub struct Boolean { value: bool, @@ -26,6 +28,16 @@ impl Boolean { } } +impl ValueImpl for Boolean { + fn value_type(&self) -> ValueType { + ValueType::Boolean + } + + fn range(&self) -> text::Range { + self.range() + } +} + impl TryFrom for Boolean { type Error = Vec; diff --git a/crates/document-tree/src/value/date_time.rs b/crates/document-tree/src/value/date_time.rs index f814ba4a..080b696c 100644 --- a/crates/document-tree/src/value/date_time.rs +++ b/crates/document-tree/src/value/date_time.rs @@ -2,7 +2,7 @@ use crate::{ support::chrono::{ try_new_local_date, try_new_local_date_time, try_new_local_time, try_new_offset_date_time, }, - TryIntoDocumentTree, + TryIntoDocumentTree, ValueImpl, ValueType, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -119,6 +119,46 @@ impl LocalTime { } } +impl ValueImpl for OffsetDateTime { + fn value_type(&self) -> ValueType { + ValueType::OffsetDateTime + } + + fn range(&self) -> text::Range { + self.range() + } +} + +impl ValueImpl for LocalDateTime { + fn value_type(&self) -> ValueType { + ValueType::LocalDateTime + } + + fn range(&self) -> text::Range { + self.range() + } +} + +impl ValueImpl for LocalDate { + fn value_type(&self) -> ValueType { + ValueType::LocalDate + } + + fn range(&self) -> text::Range { + self.range() + } +} + +impl ValueImpl for LocalTime { + fn value_type(&self) -> ValueType { + ValueType::LocalTime + } + + fn range(&self) -> text::Range { + self.range() + } +} + impl TryIntoDocumentTree for ast::OffsetDateTime { fn try_into_document_tree( self, diff --git a/crates/document-tree/src/value/float.rs b/crates/document-tree/src/value/float.rs index b849c7b1..9b603981 100644 --- a/crates/document-tree/src/value/float.rs +++ b/crates/document-tree/src/value/float.rs @@ -1,4 +1,4 @@ -use crate::support::float::try_from_float; +use crate::{support::float::try_from_float, ValueImpl, ValueType}; #[derive(Debug, Clone, PartialEq)] pub struct Float { @@ -28,6 +28,16 @@ impl Float { } } +impl ValueImpl for Float { + fn value_type(&self) -> ValueType { + ValueType::Float + } + + fn range(&self) -> text::Range { + self.range() + } +} + impl TryFrom for Float { type Error = Vec; diff --git a/crates/document-tree/src/value/integer.rs b/crates/document-tree/src/value/integer.rs index 6074cc9f..1422d0e7 100644 --- a/crates/document-tree/src/value/integer.rs +++ b/crates/document-tree/src/value/integer.rs @@ -1,5 +1,6 @@ -use crate::support::integer::{ - try_from_binary, try_from_decimal, try_from_hexadecimal, try_from_octal, +use crate::{ + support::integer::{try_from_binary, try_from_decimal, try_from_hexadecimal, try_from_octal}, + ValueImpl, ValueType, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -45,6 +46,16 @@ impl Integer { } } +impl ValueImpl for Integer { + fn value_type(&self) -> ValueType { + ValueType::Integer + } + + fn range(&self) -> text::Range { + self.range() + } +} + impl TryFrom for Integer { type Error = Vec; diff --git a/crates/document-tree/src/value/string.rs b/crates/document-tree/src/value/string.rs index 6758f517..e3be7386 100644 --- a/crates/document-tree/src/value/string.rs +++ b/crates/document-tree/src/value/string.rs @@ -1,6 +1,6 @@ use toml_version::TomlVersion; -use crate::TryIntoDocumentTree; +use crate::{TryIntoDocumentTree, ValueImpl, ValueType}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum StringKind { @@ -84,6 +84,16 @@ impl String { } } +impl ValueImpl for String { + fn value_type(&self) -> ValueType { + ValueType::String + } + + fn range(&self) -> text::Range { + self.range() + } +} + impl TryIntoDocumentTree for ast::BasicString { fn try_into_document_tree( self, diff --git a/crates/document-tree/src/value/table.rs b/crates/document-tree/src/value/table.rs index 498f1096..499e362f 100644 --- a/crates/document-tree/src/value/table.rs +++ b/crates/document-tree/src/value/table.rs @@ -4,7 +4,9 @@ use indexmap::IndexMap; use itertools::Itertools; use toml_version::TomlVersion; -use crate::{support::comment::try_new_comment, Array, Key, TryIntoDocumentTree, Value}; +use crate::{ + support::comment::try_new_comment, Array, Key, TryIntoDocumentTree, Value, ValueImpl, ValueType, +}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum TableKind { @@ -266,6 +268,16 @@ impl From for IndexMap { } } +impl ValueImpl for Table { + fn value_type(&self) -> ValueType { + ValueType::Table + } + + fn range(&self) -> text::Range { + self.range() + } +} + impl TryIntoDocumentTree
for ast::Table { fn try_into_document_tree(self, toml_version: TomlVersion) -> Result> { let mut table = Table::new_table(&self); diff --git a/crates/document-tree/src/value_type.rs b/crates/document-tree/src/value_type.rs new file mode 100644 index 00000000..210d6cad --- /dev/null +++ b/crates/document-tree/src/value_type.rs @@ -0,0 +1,19 @@ +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ValueType { + Boolean, + Integer, + Float, + String, + OffsetDateTime, + LocalDateTime, + LocalDate, + LocalTime, + Array, + Table, +} + +impl std::fmt::Display for ValueType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} diff --git a/crates/linter/src/error.rs b/crates/linter/src/error.rs index ef8b0ab9..0bcf6eb9 100644 --- a/crates/linter/src/error.rs +++ b/crates/linter/src/error.rs @@ -1,5 +1,3 @@ -use schema_store::ValueType; - #[derive(thiserror::Error, Debug)] pub enum ErrorKind { #[error("An empty quoted key is allowed, but it is not recommended")] @@ -13,8 +11,8 @@ pub enum ErrorKind { #[error("Expected a value of type {expected}, but found {actual}")] TypeMismatch { - expected: ValueType, - actual: ValueType, + expected: schema_store::ValueType, + actual: document_tree::ValueType, }, #[error("The value must be one of [{}], but found {actual}", .expected.join(", "))] diff --git a/crates/linter/src/validation.rs b/crates/linter/src/validation.rs index 6e387689..7baede8f 100644 --- a/crates/linter/src/validation.rs +++ b/crates/linter/src/validation.rs @@ -11,6 +11,7 @@ mod table; mod value; use config::TomlVersion; +use document_tree::ValueImpl; use schema_store::OneOfSchema; use schema_store::SchemaDefinitions; use schema_store::ValueSchema; @@ -43,7 +44,7 @@ fn validate_one_of( definitions: &SchemaDefinitions, ) -> Result<(), Vec> where - T: Validate, + T: Validate + ValueImpl, { let mut errors = vec![]; @@ -54,12 +55,66 @@ where let Ok(value_schema) = referable_schema.resolve(definitions) else { continue; }; - match value.validate(toml_version, value_schema, definitions) { - Ok(()) => { - valid_count += 1; - break; + + match (value.value_type(), value_schema) { + (document_tree::ValueType::Boolean, ValueSchema::Boolean(_)) + | (document_tree::ValueType::Integer, ValueSchema::Integer(_)) + | (document_tree::ValueType::Float, ValueSchema::Float(_)) + | (document_tree::ValueType::String, ValueSchema::String(_)) + | (document_tree::ValueType::OffsetDateTime, ValueSchema::OffsetDateTime(_)) + | (document_tree::ValueType::LocalDateTime, ValueSchema::LocalDateTime(_)) + | (document_tree::ValueType::LocalDate, ValueSchema::LocalDate(_)) + | (document_tree::ValueType::LocalTime, ValueSchema::LocalTime(_)) + | (document_tree::ValueType::Table, ValueSchema::Table(_)) + | (document_tree::ValueType::Array, ValueSchema::Array(_)) => { + match value.validate(toml_version, value_schema, definitions) { + Ok(()) => { + valid_count += 1; + break; + } + Err(mut schema_errors) => errors.append(&mut schema_errors), + } + } + (_, ValueSchema::Boolean(_)) + | (_, ValueSchema::Integer(_)) + | (_, ValueSchema::Float(_)) + | (_, ValueSchema::String(_)) + | (_, ValueSchema::OffsetDateTime(_)) + | (_, ValueSchema::LocalDateTime(_)) + | (_, ValueSchema::LocalDate(_)) + | (_, ValueSchema::LocalTime(_)) + | (_, ValueSchema::Table(_)) + | (_, ValueSchema::Array(_)) + | (_, ValueSchema::Null) => { + continue; + } + (_, ValueSchema::OneOf(one_of_schema)) => { + match validate_one_of(value, toml_version, one_of_schema, definitions) { + Ok(()) => { + valid_count += 1; + break; + } + Err(mut schema_errors) => errors.append(&mut schema_errors), + } + } + (_, ValueSchema::AnyOf(any_of_schema)) => { + match validate_any_of(value, toml_version, &any_of_schema, definitions) { + Ok(()) => { + valid_count += 1; + break; + } + Err(mut schema_errors) => errors.append(&mut schema_errors), + } + } + (_, ValueSchema::AllOf(all_of_schema)) => { + match validate_all_of(value, toml_version, &all_of_schema, definitions) { + Ok(()) => { + valid_count += 1; + break; + } + Err(mut schema_errors) => errors.append(&mut schema_errors), + } } - Err(mut schema_errors) => errors.append(&mut schema_errors), } } } @@ -78,7 +133,7 @@ fn validate_any_of( definitions: &schema_store::SchemaDefinitions, ) -> Result<(), Vec> where - T: Validate, + T: Validate + ValueImpl, { let mut errors = vec![]; @@ -87,11 +142,67 @@ where let Ok(value_schema) = referable_schema.resolve(definitions) else { continue; }; - match value.validate(toml_version, value_schema, definitions) { - Ok(()) => { - return Ok(()); + match (value.value_type(), value_schema) { + (document_tree::ValueType::Boolean, ValueSchema::Boolean(_)) + | (document_tree::ValueType::Integer, ValueSchema::Integer(_)) + | (document_tree::ValueType::Float, ValueSchema::Float(_)) + | (document_tree::ValueType::String, ValueSchema::String(_)) + | (document_tree::ValueType::OffsetDateTime, ValueSchema::OffsetDateTime(_)) + | (document_tree::ValueType::LocalDateTime, ValueSchema::LocalDateTime(_)) + | (document_tree::ValueType::LocalDate, ValueSchema::LocalDate(_)) + | (document_tree::ValueType::LocalTime, ValueSchema::LocalTime(_)) + | (document_tree::ValueType::Table, ValueSchema::Table(_)) + | (document_tree::ValueType::Array, ValueSchema::Array(_)) => { + match value.validate(toml_version, value_schema, definitions) { + Ok(()) => { + return Ok(()); + } + Err(mut schema_errors) => errors.append(&mut schema_errors), + } + } + (_, ValueSchema::Boolean(_)) + | (_, ValueSchema::Integer(_)) + | (_, ValueSchema::Float(_)) + | (_, ValueSchema::String(_)) + | (_, ValueSchema::OffsetDateTime(_)) + | (_, ValueSchema::LocalDateTime(_)) + | (_, ValueSchema::LocalDate(_)) + | (_, ValueSchema::LocalTime(_)) + | (_, ValueSchema::Table(_)) + | (_, ValueSchema::Array(_)) + | (_, ValueSchema::Null) => { + errors.push(crate::Error { + kind: crate::ErrorKind::TypeMismatch { + expected: value_schema.value_type(), + actual: value.value_type(), + }, + range: value.range(), + }); + } + (_, ValueSchema::OneOf(one_of_schema)) => { + match validate_one_of(value, toml_version, &one_of_schema, definitions) { + Ok(()) => { + return Ok(()); + } + Err(mut schema_errors) => errors.append(&mut schema_errors), + } + } + (_, ValueSchema::AnyOf(any_of_schema)) => { + match validate_any_of(value, toml_version, &any_of_schema, definitions) { + Ok(()) => { + return Ok(()); + } + Err(mut schema_errors) => errors.append(&mut schema_errors), + } + } + (_, ValueSchema::AllOf(all_of_schema)) => { + match validate_all_of(value, toml_version, &all_of_schema, definitions) { + Ok(()) => { + return Ok(()); + } + Err(mut schema_errors) => errors.append(&mut schema_errors), + } } - Err(mut schema_errors) => errors.append(&mut schema_errors), } } } diff --git a/crates/linter/src/validation/array.rs b/crates/linter/src/validation/array.rs index e7f346b3..b5a54bb9 100644 --- a/crates/linter/src/validation/array.rs +++ b/crates/linter/src/validation/array.rs @@ -1,4 +1,5 @@ use config::TomlVersion; +use document_tree::ValueImpl; use schema_store::{ValueSchema, ValueType}; use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; @@ -13,11 +14,11 @@ impl Validate for document_tree::Array { match value_schema.value_type() { ValueType::Array | ValueType::OneOf(_) | ValueType::AnyOf(_) | ValueType::AllOf(_) => {} ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: ValueType::Array, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }]) diff --git a/crates/linter/src/validation/boolean.rs b/crates/linter/src/validation/boolean.rs index 84d1c0fd..dd9e96bc 100644 --- a/crates/linter/src/validation/boolean.rs +++ b/crates/linter/src/validation/boolean.rs @@ -1,4 +1,5 @@ use config::TomlVersion; +use document_tree::ValueImpl; use schema_store::{SchemaDefinitions, ValueSchema, ValueType}; use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; @@ -18,11 +19,11 @@ impl Validate for document_tree::Boolean { | ValueType::AnyOf(_) | ValueType::AllOf(_) => {} ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: ValueType::Boolean, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }]); diff --git a/crates/linter/src/validation/float.rs b/crates/linter/src/validation/float.rs index a8b7de3b..397990f6 100644 --- a/crates/linter/src/validation/float.rs +++ b/crates/linter/src/validation/float.rs @@ -1,3 +1,4 @@ +use document_tree::ValueImpl; use schema_store::ValueType; use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; @@ -14,11 +15,11 @@ impl Validate for document_tree::Float { match value_schema.value_type() { ValueType::Float | ValueType::OneOf(_) | ValueType::AnyOf(_) | ValueType::AllOf(_) => {} ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: schema_store::ValueType::Float, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }]); diff --git a/crates/linter/src/validation/integer.rs b/crates/linter/src/validation/integer.rs index 7ba28387..03d68469 100644 --- a/crates/linter/src/validation/integer.rs +++ b/crates/linter/src/validation/integer.rs @@ -1,3 +1,4 @@ +use document_tree::ValueImpl; use schema_store::ValueType; use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; @@ -17,11 +18,11 @@ impl Validate for document_tree::Integer { | ValueType::AnyOf(_) | ValueType::AllOf(_) => {} ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: schema_store::ValueType::Integer, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }]); diff --git a/crates/linter/src/validation/local_date.rs b/crates/linter/src/validation/local_date.rs index cf1d4edd..d2ee7ac6 100644 --- a/crates/linter/src/validation/local_date.rs +++ b/crates/linter/src/validation/local_date.rs @@ -1,7 +1,8 @@ -use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; -use document_tree::LocalDate; +use document_tree::{LocalDate, ValueImpl}; use schema_store::ValueType; +use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; + impl Validate for LocalDate { fn validate( &self, @@ -17,11 +18,11 @@ impl Validate for LocalDate { | ValueType::AnyOf(_) | ValueType::AllOf(_) => {} ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: ValueType::LocalDate, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }]); diff --git a/crates/linter/src/validation/local_date_time.rs b/crates/linter/src/validation/local_date_time.rs index 9eee7e89..6d252b44 100644 --- a/crates/linter/src/validation/local_date_time.rs +++ b/crates/linter/src/validation/local_date_time.rs @@ -1,7 +1,8 @@ -use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; -use document_tree::LocalDateTime; +use document_tree::{LocalDateTime, ValueImpl}; use schema_store::ValueType; +use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; + impl Validate for LocalDateTime { fn validate( &self, @@ -17,11 +18,11 @@ impl Validate for LocalDateTime { | ValueType::AnyOf(_) | ValueType::AllOf(_) => {} ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: schema_store::ValueType::LocalDateTime, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }]); diff --git a/crates/linter/src/validation/local_time.rs b/crates/linter/src/validation/local_time.rs index e830032a..cb57cbc3 100644 --- a/crates/linter/src/validation/local_time.rs +++ b/crates/linter/src/validation/local_time.rs @@ -1,7 +1,8 @@ -use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; -use document_tree::LocalTime; +use document_tree::{LocalTime, ValueImpl}; use schema_store::ValueType; +use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; + impl Validate for LocalTime { fn validate( &self, @@ -17,11 +18,11 @@ impl Validate for LocalTime { | ValueType::AnyOf(_) | ValueType::AllOf(_) => {} ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: ValueType::LocalTime, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }]); diff --git a/crates/linter/src/validation/offset_date_time.rs b/crates/linter/src/validation/offset_date_time.rs index 74e3eccb..c7a85dd0 100644 --- a/crates/linter/src/validation/offset_date_time.rs +++ b/crates/linter/src/validation/offset_date_time.rs @@ -1,7 +1,8 @@ -use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; -use document_tree::OffsetDateTime; +use document_tree::{OffsetDateTime, ValueImpl}; use schema_store::ValueType; +use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; + impl Validate for OffsetDateTime { fn validate( &self, @@ -17,11 +18,11 @@ impl Validate for OffsetDateTime { | ValueType::AnyOf(_) | ValueType::AllOf(_) => {} ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: ValueType::OffsetDateTime, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }]); diff --git a/crates/linter/src/validation/string.rs b/crates/linter/src/validation/string.rs index 8bf6b345..ecc443ca 100644 --- a/crates/linter/src/validation/string.rs +++ b/crates/linter/src/validation/string.rs @@ -1,3 +1,4 @@ +use document_tree::ValueImpl; use regex::Regex; use schema_store::ValueType; @@ -16,11 +17,11 @@ impl Validate for document_tree::String { ValueType::String | ValueType::OneOf(_) | ValueType::AnyOf(_) | ValueType::AllOf(_) => { } ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: ValueType::String, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }]); diff --git a/crates/linter/src/validation/table.rs b/crates/linter/src/validation/table.rs index c26670ed..1eeabac4 100644 --- a/crates/linter/src/validation/table.rs +++ b/crates/linter/src/validation/table.rs @@ -1,4 +1,5 @@ use config::TomlVersion; +use document_tree::ValueImpl; use schema_store::{Accessor, ValueSchema, ValueType}; use super::{validate_all_of, validate_any_of, validate_one_of, Validate}; @@ -14,11 +15,11 @@ impl Validate for document_tree::Table { match value_schema.value_type() { ValueType::Table | ValueType::OneOf(_) | ValueType::AnyOf(_) | ValueType::AllOf(_) => {} ValueType::Null => return Ok(()), - value_type => { + _ => { return Err(vec![crate::Error { kind: crate::ErrorKind::TypeMismatch { expected: schema_store::ValueType::Table, - actual: value_type, + actual: self.value_type(), }, range: self.range(), }])