-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve gno linter with basic errors support (#1202)
I've improved the linter by using `RunMemPackage` in the same way that `gno test` does for testing. A direct use case for this PR is to provide a simple and reliable method for editors to integrate `gno linting`. (There might be a better way to achieve what I've done, of which I'm not aware) --- ### Below a sample of `gno lint` output: <img width="875" alt="Screenshot 2023-10-06 at 23 00 06" src="https://github.com/gnolang/gno/assets/8671905/f9b62026-1393-436c-9785-74ae665560c5"> --- ### And here's a brief demo using basic integration with emacs:  <details><summary>Contributors' checklist...</summary> - [ ] 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](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
- Loading branch information
Showing
19 changed files
with
360 additions
and
18 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
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,19 @@ | ||
# testing gno lint command: bad import error | ||
|
||
! gno lint ./bad_file.gno | ||
|
||
cmp stdout stdout.golden | ||
cmp stderr stderr.golden | ||
|
||
-- bad_file.gno -- | ||
package main | ||
|
||
import "python" | ||
|
||
func main() { | ||
fmt.Println("Hello", 42) | ||
} | ||
|
||
-- stdout.golden -- | ||
-- stderr.golden -- | ||
bad_file.gno:1: unknown import path python (code=2). |
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,20 @@ | ||
# gno lint: test file error | ||
|
||
! gno lint ./i_have_error_test.gno | ||
|
||
cmp stdout stdout.golden | ||
cmp stderr stderr.golden | ||
|
||
-- i_have_error_test.gno -- | ||
package main | ||
|
||
import "fmt" | ||
|
||
func TestIHaveSomeError() { | ||
i := undefined_variable | ||
fmt.Println("Hello", 42) | ||
} | ||
|
||
-- stdout.golden -- | ||
-- stderr.golden -- | ||
i_have_error_test.gno:6: name undefined_variable not declared (code=2). |
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,20 @@ | ||
# gno lint: test file error | ||
|
||
! gno lint ./i_have_error_test.gno | ||
|
||
cmp stdout stdout.golden | ||
cmp stderr stderr.golden | ||
|
||
-- i_have_error_test.gno -- | ||
package main | ||
|
||
import "fmt" | ||
|
||
func TestIHaveSomeError() { | ||
i := undefined_variable | ||
fmt.Println("Hello", 42) | ||
} | ||
|
||
-- stdout.golden -- | ||
-- stderr.golden -- | ||
i_have_error_test.gno:6: name undefined_variable not declared (code=2). |
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,18 @@ | ||
# testing simple gno lint command with any error | ||
|
||
gno lint ./good_file.gno | ||
|
||
cmp stdout stdout.golden | ||
cmp stdout stderr.golden | ||
|
||
-- good_file.gno -- | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Hello", 42) | ||
} | ||
|
||
-- stdout.golden -- | ||
-- stderr.golden -- |
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 @@ | ||
# gno lint: no gnomod | ||
|
||
! gno lint . | ||
|
||
cmp stdout stdout.golden | ||
cmp stderr stderr.golden | ||
|
||
-- good_file.gno -- | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Hello", 42) | ||
} | ||
|
||
-- stdout.golden -- | ||
-- stderr.golden -- | ||
./.: missing 'gno.mod' file (code=1). |
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,20 @@ | ||
# testing gno lint command: not declared error | ||
|
||
! gno lint ./bad_file.gno | ||
|
||
cmp stdout stdout.golden | ||
cmp stderr stderr.golden | ||
|
||
-- bad_file.gno -- | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
hello.Foo() | ||
fmt.Println("Hello", 42) | ||
} | ||
|
||
-- stdout.golden -- | ||
-- stderr.golden -- | ||
bad_file.gno:6: name hello not declared (code=2). |
Oops, something went wrong.