-
-
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 9 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 { | ||
#[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, | ||
r#"- {relative_package_dir}: Attribute `{package_name}` should not be number-prefixed. It is suggestet to `"`-wrap this name"# | ||
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.
typo
I had to read that a couple of times before realizing what was meant. I think I'd prefer if it said something like "Wrap the name in quotes." However, it wasn't too clear to me when reading NixOS/nixpkgs#333281 if wrapping in quotes is preferred over underscore prefix. 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. I'm not sure what the recommendation should be. This was a best guess. I'd happily take direction on what the warning should explicitly be. 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. Oh looking at this again, realized they're not talking about the $ pwd
/home/will/code/external/nixpkgs/pkgs/by-name
$ find . -type d -name '_*'
./_1
./_1/_1oom
./_1/_1fps
./_2
./_2/_2ship2harkinian
./_4
./_4/_4ti2
./_4/_4th
./_4/_4d-minesweeper
./_6
./_6/_64gram
./_9
./_9/_9base
./_9/_9menu
./mi/micro/tests/_001-hello-expect
./_0
./_0/_0xpropo
./_0/_0ver
$ rg "pname = \"1"
_1/_1fps/package.nix
8: pname = "1fps";
_1/_1oom/package.nix
19: pname = "1oom";
$ rg "pname = \"_" |
||
) | ||
} | ||
} |
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
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/// Deterministic file listing so that tests are reproducible. | ||||||||||||||||
|
@@ -137,11 +140,23 @@ 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 | ||||||||||||||||
willbush marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
.chars() | ||||||||||||||||
.next() | ||||||||||||||||
.is_some_and(|c| 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. 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. |
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,4 @@ | ||
{ someDrv }: | ||
SomeDrv | ||
# If we caused an actual Nix failure | ||
# builtins.trace "This should be on stderr!" throw "This is an error!" | ||
willbush marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Just noticed this typo
Packeg