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

feat: lint all files in folder before panicking #2202

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Villaquiranm
Copy link
Contributor

@Villaquiranm Villaquiranm commented May 26, 2024

This Pull request intents to follow up on #2011. As said on that Pull request, currently we show all lint errors on the first analyzed file.
If in a folder we have a.gno & b.gno both with lint errors. gno lint | run | test will only find the errors related to one of those files.

This PR aims to show all the lint errors present on the current folder.

Changes:
for lint & test cmd:

  • we modified ParseMemPackage function on gnovm/pkg/gnoland/nodes.go. Before this function returned as soon as an error was found while Parsing the gno file. So we introduced an error slice to keep track of all Parse errors. After parsing all the files we panic with the list of errors only if this list is not empty.
  • we did the same on parseMemPackageTests function
  • create a function printRuntimeError that handles the print of the errors inside catchRuntimeError function. We did this change in order to be able to recursively call the funtion and handle the case of an []error type composed of scanner.ErrorList errors.

Results

  • running on gnovm/tests/integ/several-files-multiple/errors
    LINT (before):
several-files-multiple-errors % gno lint .
file2.gno:3: expected 'IDENT', found '{' (code=2).
file2.gno:5: expected type, found '}' (code=2).

LINT (after):

gno lint .
file2.gno:3: expected 'IDENT', found '{' (code=2).
file2.gno:5: expected type, found '}' (code=2).
main.gno:5: expected ';', found example (code=2).
main.gno:6: expected '}', found 'EOF' (code=2).
exit status 1
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

Copy link

codecov bot commented May 26, 2024

Codecov Report

Attention: Patch coverage is 43.75000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 55.02%. Comparing base (5083bcb) to head (ff7c960).
Report is 7 commits behind head on master.

Files Patch % Lines
gnovm/cmd/gno/test.go 0.00% 5 Missing ⚠️
gnovm/pkg/gnolang/nodes.go 20.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2202   +/-   ##
=======================================
  Coverage   55.02%   55.02%           
=======================================
  Files         595      595           
  Lines       79662    79676   +14     
=======================================
+ Hits        43834    43842    +8     
- Misses      32512    32519    +7     
+ Partials     3316     3315    -1     
Flag Coverage Δ
contribs/gnodev 25.65% <ø> (-0.35%) ⬇️
contribs/gnofaucet 15.31% <ø> (+0.85%) ⬆️
contribs/gnokeykc 0.00% <ø> (ø)
contribs/gnomd 0.00% <ø> (ø)
gno.land 64.24% <ø> (ø)
gnovm 60.31% <43.75%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}()

action()
return
}

func printRuntimeError(r interface{}, pkgPath string, stderr io.WriteCloser) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this new function creation necessary? It seemed better to handle the runtime error within the existing catchRuntimeError function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I created the function is because I calling it recursively on this case:
When analysing several files we will panic with an array of errors
[]error or after the change you proposed a multierr.

knowing that inside each of these error there is a scanner.Errorlist that needs to be handled we have 2 options

  • with []error (multierr) first time we will enter on the case and call recursively printRuntimeError function again for each element (scanner.ErrorList)
case []error:
	for _, err := range verr {
		// recursive call to handle specifically each error type ex: scanner.ErrorList
		printRuntimeError(err, pkgPath, stderr)
	}

Second time we will enter

case scanner.ErrorList:
for _, err := range verr {
	fmt.Fprint(stderr, issueFromError(pkgPath, err).String()+"\n")
}
  • Second possibility is to keep the function as it were but having an extra for loop something like
case []error (multiErr):
	for _, errL := range verr {
		errorList := errL.(scanner.ErrorList)
		for _, err := range errorList {
                         fmt.Fprint(stderr, issueFromError(pkgPath, errors.New(err)).String()+"\n")
                 }
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implemented second possibility on 18fe895
Don't know if you consider it better

@@ -638,6 +638,7 @@ func loadTestFuncs(pkgName string, t *testFuncs, tfiles *gno.FileSet) *testFuncs
func parseMemPackageTests(memPkg *std.MemPackage) (tset, itset *gno.FileSet) {
tset = &gno.FileSet{}
itset = &gno.FileSet{}
errors := []error{}
Copy link
Member

Choose a reason for hiding this comment

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

We typically use multierr for this. Can you switch to it or explain why your solution is more suitable in this case?

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'll try to use multiErr I think it will fit perfectly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed on 18fe895

@Villaquiranm Villaquiranm force-pushed the lint-multiple-files branch 3 times, most recently from 955cb1a to 6be80ff Compare May 30, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: No status
Status: In Review
Development

Successfully merging this pull request may close these issues.

3 participants