-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add problem: ByNamePackagePrefixedWithNumber #122
base: main
Are you sure you want to change the base?
Changes from all commits
5006491
85a1b53
af703c9
fd4a72f
e693e74
884c807
05bafef
c20b06e
7f3e6ce
932f6ef
837cba7
2e54489
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::fmt; | ||
|
||
use derive_new::new; | ||
use relative_path::RelativePathBuf; | ||
|
||
#[derive(Clone, new)] | ||
pub struct ByNamePackegPrefixedWithNumber { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed this typo |
||
#[new(into)] | ||
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 { | ||
package_name, | ||
relative_package_dir, | ||
} = self; | ||
write!( | ||
f, | ||
"- {relative_package_dir}: Attribute `{package_name}` should not be number-prefixed. Prefix with `_`, or wrap in quotes" | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,7 +7,9 @@ use lazy_static::lazy_static; | |||||||||||||||
use regex::Regex; | ||||||||||||||||
use relative_path::RelativePathBuf; | ||||||||||||||||
|
||||||||||||||||
use crate::problem::{npv_109, npv_110, npv_111, npv_140, npv_141, npv_142, npv_143, npv_144}; | ||||||||||||||||
use crate::problem::{ | ||||||||||||||||
npv_109, npv_110, npv_111, npv_140, npv_141, npv_142, npv_143, npv_144, npv_170, | ||||||||||||||||
}; | ||||||||||||||||
use crate::references; | ||||||||||||||||
use crate::validation::{self, ResultIteratorExt, Validation::Success}; | ||||||||||||||||
use crate::NixFileStore; | ||||||||||||||||
|
@@ -16,8 +18,9 @@ pub const BASE_SUBPATH: &str = "pkgs/by-name"; | |||||||||||||||
pub const PACKAGE_NIX_FILENAME: &str = "package.nix"; | ||||||||||||||||
|
||||||||||||||||
lazy_static! { | ||||||||||||||||
static ref SHARD_NAME_REGEX: Regex = Regex::new(r"^[a-z0-9_-]{1,2}$").unwrap(); | ||||||||||||||||
static ref PACKAGE_NAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_-]+$").unwrap(); | ||||||||||||||||
static ref SHARD_NAME_REGEX: Regex = Regex::new(r"^((_[0-9])|([a-z][a-z0-9_-]?))$").unwrap(); | ||||||||||||||||
static ref PACKAGE_NAME_REGEX: Regex = | ||||||||||||||||
Regex::new(r"^((_[0-9])|[a-zA-Z])[a-zA-Z0-9_-]*$").unwrap(); | ||||||||||||||||
Comment on lines
+21
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this is a bit simpler to understand There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We actually don't even need a new error type for this, because we can just update the message for when these regexes don't match here: nixpkgs-vet/src/problem/npv_110.rs Line 19 in 02db8e4
nixpkgs-vet/src/problem/npv_141.rs Line 22 in 02db8e4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This allows |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/// Deterministic file listing so that tests are reproducible. | ||||||||||||||||
|
@@ -137,11 +140,19 @@ fn check_package( | |||||||||||||||
} else { | ||||||||||||||||
let package_name_valid = PACKAGE_NAME_REGEX.is_match(&package_name); | ||||||||||||||||
let result = if !package_name_valid { | ||||||||||||||||
npv_141::InvalidPackageDirectoryName::new( | ||||||||||||||||
package_name.clone(), | ||||||||||||||||
relative_package_dir.clone(), | ||||||||||||||||
) | ||||||||||||||||
.into() | ||||||||||||||||
if package_name.starts_with(|c: char| c.is_ascii_digit()) { | ||||||||||||||||
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() | ||||||||||||||||
} | ||||||||||||||||
} else { | ||||||||||||||||
Success(()) | ||||||||||||||||
}; | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import <test-nixpkgs> { root = ./.; } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- pkgs/by-name/_1/10foo: Attribute `10foo` should not be number-prefixed. Prefix with `_`, or wrap in quotes | ||
This PR introduces the problems listed above. Please fix them before merging, otherwise the base branch would break. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something to think about is how users are likely to run into a problem. Since users will know that the first two chars of the shard need to match the attribute name, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ someDrv }: SomeDrv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It cannot start with
-
.-
will be parsed to a negation operator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be done in this same PR, since it's technically a separate problem, but yeah this would be good too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not allowed in the regex already.