Skip to content

Commit

Permalink
config: case warning (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson authored Sep 27, 2023
1 parent e02a4d4 commit c701cb0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/src/modules/rapifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub fn rapify(path: WorkspacePath, _ctx: &Context) -> (Vec<String>, Result<(), E
))),
);
}
let out = if path.filename() == "config.cpp" {
let out = if path.filename().to_lowercase() == "config.cpp" {
path.parent().join("config.bin").unwrap()
} else {
path
Expand Down
1 change: 1 addition & 0 deletions libs/preprocessor/src/codes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ pub mod pe8_if_undefined;
pub mod pe9_function_call_argument_count;

pub mod pw1_redefine;
pub mod pw2_invalid_config_case;
43 changes: 43 additions & 0 deletions libs/preprocessor/src/codes/pw2_invalid_config_case.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use ariadne::Fmt;
use hemtt_common::{reporting::Code, workspace::WorkspacePath};

#[allow(unused)]
/// Unexpected token
pub struct InvalidConfigCase {
/// The [`WorkspacePath`] that was named with an invalid case
pub(crate) path: WorkspacePath,
}

impl Code for InvalidConfigCase {
fn ident(&self) -> &'static str {
"PW2"
}

fn message(&self) -> String {
format!(
"`{}` is not a valid case for a config",
self.path.filename()
)
}

fn label_message(&self) -> String {
format!(
"`{}` is not a valid case for a config",
self.path.filename()
)
}

fn help(&self) -> Option<String> {
Some(format!("Rename to `{}`", self.path.as_str().to_lowercase()))
}

fn generate_report(&self) -> Option<String> {
Some(format!(
"{} {}\n {}: {}",
format!("[{}] Warning:", self.ident()).fg(ariadne::Color::Yellow),
self.message(),
"Help".fg(ariadne::Color::Fixed(115)),
self.help().expect("help should be Some")
))
}
}
7 changes: 7 additions & 0 deletions libs/preprocessor/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use peekmore::{PeekMore, PeekMoreIterator};
use crate::codes::pe18_eoi_ifstate::EoiIfState;
use crate::codes::pe2_unexpected_eof::UnexpectedEOF;
use crate::codes::pe3_expected_ident::ExpectedIdent;
use crate::codes::pw2_invalid_config_case::InvalidConfigCase;
use crate::defines::Defines;
use crate::ifstate::IfStates;
use crate::Error;
Expand Down Expand Up @@ -66,6 +67,12 @@ impl Processor {
})));
}

if path.filename() == "Config.cpp" {
processor
.warnings
.push(Box::new(InvalidConfigCase { path: path.clone() }));
}

Processed::new(
buffer,
processor.usage,
Expand Down

0 comments on commit c701cb0

Please sign in to comment.