-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR introduces a new `gno lint` subcommand, currently focused on checking for the presence of a `gno.mod` file in a package, and it's linked with the CI. In the future, we plan to expand `gno lint` to support additional checks, enhancing its utility for developers and CI integration. Addresses #850 Addresses #927 Related with #965 (comment) Signed-off-by: Manfred Touron <[email protected]> Co-authored-by: Miloš Živković <[email protected]>
- Loading branch information
1 parent
6c9a1c6
commit 3ade982
Showing
28 changed files
with
240 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module gno.land/p/demo/grc/exts/vault | ||
|
||
require ( | ||
"gno.land/p/demo/avl" v0.0.0-latest | ||
"gno.land/p/demo/grc/grc20" v0.0.0-latest | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module gno.land/p/demo/merkle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module gno.land/p/demo/microblog | ||
|
||
require ( | ||
"gno.land/p/demo/avl" v0.0.0-latest | ||
"gno.land/p/demo/ufmt" v0.0.0-latest | ||
"gno.land/r/demo/users" v0.0.0-latest | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module gno.land/r/demo/microblog | ||
|
||
require ( | ||
"gno.land/p/demo/microblog" v0.0.0-latest | ||
"gno.land/r/demo/users" v0.0.0-latest | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module gno.land/r/demo/ui | ||
|
||
require ( | ||
"gno.land/p/demo/ui" v0.0.0-latest | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# `x/` Experimentation Area | ||
|
||
Welcome to the `x/` directory, designed for experimentation. | ||
|
||
Code in this area is less reviewed and more subject to change or break over | ||
time. It's a great place to publish experiments and proposals for significant | ||
challenges before they become an MVP and move to another directory. | ||
|
||
While publishing code here provides core developers with more examples and edge | ||
cases to work on through CI, consider alternative options such as working on | ||
other repositories, keeping your work in a pull request, or exploring | ||
[https://github.com/gnolang/hackerspace](https://github.com/gnolang/hackerspace) | ||
for broader visibility and collaboration within the Gno community. | ||
|
||
Exercise caution as code in this directory may be less stable or secure due to | ||
its experimental nature. | ||
|
||
Feel free to explore, experiment, and contribute to the exciting developments | ||
happening in the `x/` directory. Together, we can shape the future of GnoVM. |
2 changes: 1 addition & 1 deletion
2
examples/gno.land/r/demo/x/outfmt/README.md → ...les/gno.land/r/x/manfred_outfmt/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# r/x/outfmt | ||
# r/x/manfred_outfmt | ||
|
||
PoC of output formatting options. |
2 changes: 1 addition & 1 deletion
2
examples/gno.land/r/demo/x/outfmt/gno.mod → examples/gno.land/r/x/manfred_outfmt/gno.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Draft | ||
|
||
module gno.land/r/x/manfred_upgrade_patterns |
4 changes: 2 additions & 2 deletions
4
.../x/upgrade/upgrade-a/integration_test.gno → ...e_patterns/upgrade-a/integration_test.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...land/r/demo/x/upgrade/upgrade-c/v1/v1.gno → ...fred_upgrade_patterns/upgrade-c/v1/v1.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...land/r/demo/x/upgrade/upgrade-c/v2/v2.gno → ...fred_upgrade_patterns/upgrade-c/v2/v2.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/gnolang/gno/tm2/pkg/commands" | ||
osm "github.com/gnolang/gno/tm2/pkg/os" | ||
) | ||
|
||
type lintCfg struct { | ||
verbose bool | ||
rootDir string | ||
setExitStatus int | ||
// min_confidence: minimum confidence of a problem to print it (default 0.8) | ||
// auto-fix: apply suggested fixes automatically. | ||
} | ||
|
||
func newLintCmd(io *commands.IO) *commands.Command { | ||
cfg := &lintCfg{} | ||
|
||
return commands.NewCommand( | ||
commands.Metadata{ | ||
Name: "lint", | ||
ShortUsage: "lint [flags] <package> [<package>...]", | ||
ShortHelp: "Runs the linter for the specified packages", | ||
}, | ||
cfg, | ||
func(_ context.Context, args []string) error { | ||
return execLint(cfg, args, io) | ||
}, | ||
) | ||
} | ||
|
||
func (c *lintCfg) RegisterFlags(fs *flag.FlagSet) { | ||
fs.BoolVar(&c.verbose, "verbose", false, "verbose output when lintning") | ||
fs.StringVar(&c.rootDir, "root-dir", "", "clone location of github.com/gnolang/gno (gnodev tries to guess it)") | ||
fs.IntVar(&c.setExitStatus, "set_exit_status", 1, "set exit status to 1 if any issues are found") | ||
} | ||
|
||
func execLint(cfg *lintCfg, args []string, io *commands.IO) error { | ||
if len(args) < 1 { | ||
return flag.ErrHelp | ||
} | ||
|
||
var ( | ||
verbose = cfg.verbose | ||
rootDir = cfg.rootDir | ||
) | ||
if rootDir == "" { | ||
rootDir = guessRootDir() | ||
} | ||
|
||
pkgPaths, err := gnoPackagesFromArgs(args) | ||
if err != nil { | ||
return fmt.Errorf("list packages from args: %w", err) | ||
} | ||
|
||
hasError := false | ||
addIssue := func(issue lintIssue) { | ||
hasError = true | ||
fmt.Fprint(io.Err, issue.String()+"\n") | ||
} | ||
|
||
for _, pkgPath := range pkgPaths { | ||
if verbose { | ||
fmt.Fprintf(io.Err, "Linting %q...\n", pkgPath) | ||
} | ||
|
||
// 'gno.mod' exists? | ||
gnoModPath := filepath.Join(pkgPath, "gno.mod") | ||
if !osm.FileExists(gnoModPath) { | ||
addIssue(lintIssue{ | ||
Code: lintNoGnoMod, | ||
Confidence: 1, | ||
Location: pkgPath, | ||
Msg: "missing 'gno.mod' file", | ||
}) | ||
} | ||
|
||
// TODO: add more checkers | ||
} | ||
|
||
if hasError && cfg.setExitStatus != 0 { | ||
os.Exit(cfg.setExitStatus) | ||
} | ||
return nil | ||
} | ||
|
||
type lintCode int | ||
|
||
const ( | ||
lintUnknown lintCode = 0 | ||
lintNoGnoMod lintCode = iota | ||
// TODO: add new linter codes here. | ||
) | ||
|
||
type lintIssue struct { | ||
Code lintCode | ||
Msg string | ||
Confidence float64 // 1 is 100% | ||
Location string // file:line, or equivalent | ||
// TODO: consider writing fix suggestions | ||
} | ||
|
||
func (i lintIssue) String() string { | ||
// TODO: consider crafting a doc URL based on Code. | ||
return fmt.Sprintf("%s: %s (code=%d).", i.Location, i.Msg, i.Code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestLintApp(t *testing.T) { | ||
tc := []testMainCase{ | ||
{ | ||
args: []string{"lint"}, | ||
errShouldBe: "flag: help requested", | ||
}, { | ||
args: []string{"lint", "--set_exit_status=0", "../../tests/integ/run-main/"}, | ||
stderrShouldContain: "./../../tests/integ/run-main: missing 'gno.mod' file (code=1).", | ||
}, { | ||
args: []string{"lint", "--set_exit_status=0", "../../tests/integ/run-main/"}, | ||
stderrShouldContain: "./../../tests/integ/run-main: missing 'gno.mod' file (code=1).", | ||
}, { | ||
args: []string{"lint", "--set_exit_status=0", "../../tests/integ/minimalist-gnomod/"}, | ||
// TODO: raise an error because there is a gno.mod, but no .gno files | ||
}, { | ||
args: []string{"lint", "--set_exit_status=0", "../../tests/integ/invalid-module-name/"}, | ||
// TODO: raise an error because gno.mod is invalid | ||
}, | ||
// TODO: 'gno mod' is valid? | ||
// TODO: is gno source valid? | ||
// TODO: are dependencies valid? | ||
// TODO: is gno source using unsafe/discouraged features? | ||
// TODO: consider making `gno precompile; go lint *gen.go` | ||
// TODO: check for imports of native libs from non _test.gno files | ||
} | ||
testMainCaseRun(t, tc) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters