Skip to content

Commit

Permalink
Disallow hyphens in Noir package names in sindri init
Browse files Browse the repository at this point in the history
This updates the `sindri init` command logic around validating Noir package
names to disallow hyphens. Through trial and error, I found that it seems to be
fine with any mix of alphanumeric chacters and underscores, so I also relaxed
the validation around this. I think that the package name is never used in
code, unlike the Halo2 package names, and that's why it's OK for it to start
with a digit even though that wouldn't be a valid code identifier.

Merges #32

LGTM given by: @katiemckeon
  • Loading branch information
sangaline authored Dec 13, 2023
1 parent 0bcbc32 commit c1f7b21
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,15 @@ export const initCommand = new Command()
message: "Noir Package Name:",
default: circuitName
.toLowerCase()
.replace(/^[^a-z0-9_]*/, "")
.replace(/-+/g, "-"),
.replace(/[- ]/g, "_")
.replace(/[^a-zA-Z0-9_]+/, "")
.replace(/_+/g, "_"),
validate: (input): boolean | string => {
if (input.length === 0) {
return "You must specify a package name.";
}
if (!/^[a-z0-9_]+(?:-[a-z0-9_]+)*$$/.test(input)) {
return (
"Package names must begin with a lowercase letter, number, or underscore, and only " +
"be followed by lowercase or numeric characters and underscores (optionally " +
"separated hyphens)."
);
if (!/^[a-zA-Z0-9_]+$/.test(input)) {
return "Package names must only contain alphanumeric characters and underscores.";
}
return true;
},
Expand Down

0 comments on commit c1f7b21

Please sign in to comment.