Skip to content

Commit

Permalink
Cleanup err-msg and match(ish) it with expected
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-PH committed Oct 29, 2024
1 parent 884c807 commit 05bafef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/problem/npv_170.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use std::fmt;

use derive_new::new;
use relative_path::RelativePathBuf;

#[derive(Clone, new)]
pub struct ByNamePackegPrefixedWithNumber {
#[new(into)]
attribute_name: String,
package_name: String,
#[new(into)]
relative_package_dir: RelativePathBuf,
}

impl fmt::Display for ByNamePackegPrefixedWithNumber {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Self { attribute_name } = self;
let Self {
package_name,
relative_package_dir,
} = self;
write!(
f,
r#"- pkgs.{attribute_name}: "Attribute names should not be number-prefixed. It is suggestet to `"`-wrap this name"#
r#"- {relative_package_dir}: Attribute `{package_name}` should not be number-prefixed. It is suggestet to `"`-wrap this name"#
)
}
}
9 changes: 7 additions & 2 deletions src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,17 @@ fn check_package(
.next()
.is_some_and(|c| c.is_ascii_digit())
{
npv_170::ByNamePackegPrefixedWithNumber::new(package_name.clone()).into()
npv_170::ByNamePackegPrefixedWithNumber::new(
package_name.clone(),
relative_package_dir.clone(),
)
.into()
} else {
npv_141::InvalidPackageDirectoryName::new(
package_name.clone(),
relative_package_dir.clone(),
).into()
)
.into()
}
} else {
Success(())
Expand Down
2 changes: 1 addition & 1 deletion tests/by-name-numprefix/expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
trace: This should be on stderr!
@REDACTED@error: This is an error!@REDACTED@
- Nix evaluation failed for some package in `pkgs/by-name`, see error above
- pkgs/by-name/_1/10foo: Attribute `10foo` should not be number-prefixed. It is suggestet to `"`-wrap this name
This PR introduces the problems listed above. Please fix them before merging, otherwise the base branch would break.

0 comments on commit 05bafef

Please sign in to comment.