-
Notifications
You must be signed in to change notification settings - Fork 445
feat(gnovm/lint): enforce last elem of pkg path to match pkg name #5048
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
base: master
Are you sure you want to change the base?
feat(gnovm/lint): enforce last elem of pkg path to match pkg name #5048
Conversation
…t-elem-import-path
🛠 PR Checks Summary🔴 Changes to 'docs' folder must be reviewed/authored by at least one devrel and one tech-staff Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
|
||
| // LastPathElement extracts the last meaningful element from a package path. | ||
| // For versioned paths like "gno.land/r/foo/v2" or "gno.land/r/foo/v1", it | ||
| // returns "foo" since version suffixes (v1, v2, ...) are skipped. |
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.
The Go language spec says:
- For a final path element of the form /vN where N looks numeric (ASCII digits and dots), N must not begin with a leading zero, must not be /v1
Go doesn't want you to use a package ending in /v1 . But we do this in Gno. Should Gno also forbid /v1?
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.
Currently there is no alternative way to express the contract version other than this, I think it seems best to handle it as a special case as described in issue #1571
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.
also v1 is widely used in the existing packages, i would like an input from core team to tell me whether i should do it or not.
|
Note: If this is merged we should create an issue on the LSP of Gno about this new feature. |
Davphla
left a comment
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.
…t-elem-import-path
…t-elem-import-path
…t-elem-import-path
…t-elem-import-path


fix #1571
Description
Closes #1571
Enforces that package names must match the last element of their import path, following Go conventions.
BREAKING CHANGE: Packages with names that don't match their path's last element will be rejected on deployment. Existing on-chain packages are unaffected, but new deployments must comply. For example, deploying a
package fooat pathgno.land/r/demo/barwill now fail.Changes
Core validation (
gnovm/pkg/gnolang/mempackage.go):LastPathElement()- extracts the last meaningful path element, skipping version suffixesValidatePkgNameMatchesPath()- ensures package name matches path elementv1,v2,v3, ...) are recognized and skipped when matchingEnforcement:
gno lintwarns about mismatches before deploymentkeeper.AddPackage()blocks deployment of non-compliant packagesExample package renames:
gnoblog→bloggnopages→pagesfoo20→grc20factoryeval→math_evaltodolistrealm→todolistemitevents→eventsimage_embed→img_embedtests→vm(r/tests/vm)mapdelete→map_deletenir1218_evaluation_proposal→ moved to subfolder/evaluationExamples
gno.land/r/demo/countercountergno.land/r/demo/counterfoogno.land/r/demo/foo/v2foogno.land/r/demo/foo/v1fooContributors' checklist
BREAKING CHANGE: xxxmessage was included in the description