Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config: case warning #565

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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