-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For the time being, this will only be used to build informative lints.
- Loading branch information
Showing
31 changed files
with
1,947 additions
and
41 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2023 Helsing GmbH | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// Parsed protocol buffer definitions. | ||
pub mod data; | ||
|
||
/// Rules for protocol buffer definitions. | ||
pub mod rules; | ||
|
||
mod parse; | ||
|
||
/// Serde utilities. | ||
pub(crate) mod serde; | ||
|
||
mod violation; | ||
|
||
/// Rules for checking package differences. | ||
pub mod diff; | ||
|
||
pub use self::{ | ||
parse::{ParseError, Parser}, | ||
violation::*, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2023 Helsing GmbH | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::{ | ||
collections::{btree_map::Entry, BTreeMap}, | ||
path::PathBuf, | ||
}; | ||
|
||
use diff::Diff; | ||
use miette::Diagnostic; | ||
use protobuf::descriptor::{ | ||
field_descriptor_proto::{Label as FieldDescriptorLabel, Type as FieldDescriptorType}, | ||
*, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use thiserror::Error; | ||
|
||
use crate::validation::{ | ||
rules::{Rule, RuleSet}, | ||
Violations, | ||
}; | ||
|
||
mod entity; | ||
mod r#enum; | ||
mod message; | ||
mod package; | ||
mod packages; | ||
mod service; | ||
|
||
pub use self::{entity::*, message::*, package::*, packages::*, r#enum::*, service::*}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use super::*; | ||
|
||
/// Entity that can be defined in a protocol buffer file. | ||
#[derive(Serialize, Deserialize, Clone, Debug, derive_more::From, PartialEq, Eq, Diff)] | ||
#[serde(tag = "kind", rename_all = "snake_case")] | ||
#[diff(attr( | ||
#[derive(Debug)] | ||
#[allow(missing_docs)] | ||
))] | ||
pub enum Entity { | ||
/// Enumeration. | ||
Enum(Enum), | ||
/// Service definition. | ||
Service(Service), | ||
/// Message definition. | ||
Message(Message), | ||
} | ||
|
||
impl Entity { | ||
/// Check [`Entity`] against [`RuleSet`] for [`Violations`]. | ||
pub fn check(&self, _rules: &mut RuleSet) -> Violations { | ||
Violations::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use super::*; | ||
|
||
/// Error parsing package. | ||
#[derive(Error, Debug, Diagnostic)] | ||
#[allow(missing_docs)] | ||
pub enum EnumError { | ||
#[error("missing value number")] | ||
ValueNumberMissing, | ||
|
||
#[error("missing value name")] | ||
ValueNameMissing, | ||
} | ||
|
||
/// Enumeration definition. | ||
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq, Diff)] | ||
#[diff(attr( | ||
#[derive(Debug)] | ||
#[allow(missing_docs)] | ||
))] | ||
pub struct Enum { | ||
/// Variants of this enum. | ||
#[serde(deserialize_with = "crate::validation::serde::de_int_key")] | ||
pub values: BTreeMap<i32, EnumValue>, | ||
} | ||
|
||
impl Enum { | ||
/// Attempt to create new from [`EnumDescriptorProto`]. | ||
pub fn new(descriptor: &EnumDescriptorProto) -> Result<Self, EnumError> { | ||
let mut entity = Self::default(); | ||
|
||
for value in &descriptor.value { | ||
entity.add(value)?; | ||
} | ||
|
||
Ok(entity) | ||
} | ||
|
||
/// Add an [`EnumValue`] to this enum definition. | ||
pub fn add(&mut self, value: &EnumValueDescriptorProto) -> Result<(), EnumError> { | ||
let number = value.number.ok_or(EnumError::ValueNumberMissing)?; | ||
self.values.insert(number, EnumValue::new(value)?); | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// Single value for an [`Enum`]. | ||
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq, Diff)] | ||
#[diff(attr( | ||
#[derive(Debug)] | ||
#[allow(missing_docs)] | ||
))] | ||
pub struct EnumValue { | ||
/// Name of this enum value. | ||
pub name: String, | ||
} | ||
|
||
impl EnumValue { | ||
/// Attempt to create new from [`EnumValueDescriptorProto`]. | ||
pub fn new(descriptor: &EnumValueDescriptorProto) -> Result<Self, EnumError> { | ||
Ok(Self { | ||
name: descriptor.name.clone().ok_or(EnumError::ValueNameMissing)?, | ||
}) | ||
} | ||
} |
Oops, something went wrong.