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

Add problem: ByNamePackagePrefixedWithNumber #122

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Ben-PH
Copy link
Contributor

@Ben-PH Ben-PH commented Oct 29, 2024

Reference issue: #107

This is first time putting together something of substance for this repo.

@Ben-PH
Copy link
Contributor Author

Ben-PH commented Oct 29, 2024

@philiptaron I think I have the bulk of the idea here.

  • copy one of the tests/ directories. rename things to trigger the new vet-check
  • creat a new module in problem module templated by a similar problem
  • have the Display match the expected file in the new tests/ dir-entry

...I'm just not sure about this: https://github.com/NixOS/nixpkgs-vet/actions/runs/11570703378/job/32207036558?pr=122#step:4:907 (I see that I should probably be going by the invalid-shard-name test. That resolves the local test failure)

...and feedback on what the error message should actually be (I'm pretty sure the suggestion is wrong)

@Ben-PH Ben-PH marked this pull request as ready for review October 29, 2024 10:04
Copy link
Member

@willbush willbush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contributions!

} = self;
write!(
f,
r#"- {relative_package_dir}: Attribute `{package_name}` should not be number-prefixed. It is suggestet to `"`-wrap this name"#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestet

typo

"-wrap this name

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

@willbush willbush Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh looking at this again, realized they're not talking about the pname but the directory name for the package (which is what this checks 😂). Can you instead only recommend the _ prefix?

$ 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 = \"_"

tests/by-name-numprefix/pkgs/by-name/_1/10foo/package.nix Outdated Show resolved Hide resolved
src/structure.rs Outdated Show resolved Hide resolved
@willbush
Copy link
Member

willbush commented Oct 30, 2024

@philiptaron @infinisil forgot how where landed on how clean commit history should be for feature branches since we merge commit them into main? For example, should requested fix changes on a PR be rebased?

@willbush
Copy link
Member

@Ben-PH Just thought of the readme mentioning checks. Might be worth updating that too?

@willbush willbush self-requested a review October 30, 2024 09:48
use relative_path::RelativePathBuf;

#[derive(Clone, new)]
pub struct ByNamePackegPrefixedWithNumber {
Copy link
Member

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

@@ -69,6 +69,7 @@ The following checks are performed when calling the binary:
- `pkgs/by-name` must only contain subdirectories of the form `${shard}/${name}`, called _package directories_.
- The `name`'s of package directories must be unique when lowercased.
- `name` is a string only consisting of the ASCII characters `a-z`, `A-Z`, `0-9`, `-` or `_`.
- `name` only starts with an ASCII character `a-z`, `A-Z`, `-` or `_`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `name` only starts with an ASCII character `a-z`, `A-Z`, `-` or `_`.
- `name` only starts with an ASCII character `a-z`, `A-Z` or `_`.

It cannot start with -. - will be parsed to a negation operator.

Copy link
Member

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 :)

Copy link
Member

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 :)

It's not allowed in the regex already.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Left some comments :)

Copy link
Member

Choose a reason for hiding this comment

The 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, _1/10foo is rather unlikely, so instead it's better to make sure it triggers on 10/10foo.

@@ -69,6 +69,7 @@ The following checks are performed when calling the binary:
- `pkgs/by-name` must only contain subdirectories of the form `${shard}/${name}`, called _package directories_.
- The `name`'s of package directories must be unique when lowercased.
- `name` is a string only consisting of the ASCII characters `a-z`, `A-Z`, `0-9`, `-` or `_`.
- `name` only starts with an ASCII character `a-z`, `A-Z`, `-` or `_`.
Copy link
Member

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 :)

Comment on lines +21 to +23
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();
static ref SHARD_NAME_REGEX: Regex = Regex::new(r"^[a-z_-][a-z0-9_-]?$").unwrap();
static ref PACKAGE_NAME_REGEX: Regex = Regex::new(r"^[a-zA-Z_-][a-zA-Z0-9_-]*$").unwrap();

I think this is a bit simpler to understand

Copy link
Member

Choose a reason for hiding this comment

The 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:

"- {relative_shard_path}: Invalid directory name \"{shard_name}\", must be at most 2 ASCII characters consisting of a-z, 0-9, \"-\" or \"_\".",
and
"- {relative_package_dir}: Invalid package directory name \"{package_name}\", must be ASCII characters consisting of a-z, A-Z, 0-9, \"-\" or \"_\".",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static ref PACKAGE_NAME_REGEX: Regex = Regex::new(r"^[a-zA-Z_-][a-zA-Z0-9_-]*$").unwrap();

This allows _abc and even ___ as package name.

@Aleksanaa
Copy link
Member

Hi, do you still want to work on this?

@Ben-PH
Copy link
Contributor Author

Ben-PH commented Nov 27, 2024

Yeah. Thanks for prompting this, had some other commitments that pulled me away from it, but ready to come back to it before the end of the week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants