gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
841 stars 342 forks source link

feat(gnovm): enforce formatting of added packages #2464

Open moul opened 2 days ago

moul commented 2 days ago

RFC: Should we enforce basic code formatting, verify and return an error for bad formatting, or accept bad formatting?


This PR introduces the concept of automatically formatting packages during AddPkg. The advantage is that it's relatively inexpensive since we were already parsing the submitted source code AST to apply some verification.

I believe that having a consistent official formatting for the Go language is one of the things that makes it better, simpler, and more readable. I think Gno should strive to be as good as or better than Go in this regard.

Another justification for this approach is that Gno is not just the language but a platform (gno.land), like a PAAS, and AddPkg can be considered the "CD" process, while auto-formatting could be the "CI" component, which often go hand-in-hand in "CI/CD".

The biggest drawback I can see is that in practice, the code content may not be the same on the publisher's computer and on-chain.

codecov[bot] commented 2 days ago

Codecov Report

Attention: Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 54.73%. Comparing base (10a6f7e) to head (3741b5d).

Files Patch % Lines
gnovm/pkg/gnolang/go2gno.go 75.00% 2 Missing and 1 partial :warning:
gno.land/pkg/sdk/vm/keeper.go 75.00% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2464 +/- ## ========================================== + Coverage 54.71% 54.73% +0.01% ========================================== Files 583 583 Lines 78499 78509 +10 ========================================== + Hits 42947 42968 +21 + Misses 32344 32333 -11 Partials 3208 3208 ``` | [Flag](https://app.codecov.io/gh/gnolang/gno/pull/2464/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | Coverage Δ | | |---|---|---| | [contribs/gnodev](https://app.codecov.io/gh/gnolang/gno/pull/2464/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `23.81% <ø> (ø)` | | | [contribs/gnofaucet](https://app.codecov.io/gh/gnolang/gno/pull/2464/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `14.46% <ø> (ø)` | | | [contribs/gnokeykc](https://app.codecov.io/gh/gnolang/gno/pull/2464/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `0.00% <ø> (ø)` | | | [contribs/gnomd](https://app.codecov.io/gh/gnolang/gno/pull/2464/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `0.00% <ø> (ø)` | | | [gno.land](https://app.codecov.io/gh/gnolang/gno/pull/2464/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `62.56% <75.00%> (+0.01%)` | :arrow_up: | | [gnovm](https://app.codecov.io/gh/gnolang/gno/pull/2464/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `59.98% <75.00%> (+<0.01%)` | :arrow_up: | | [tm2](https://app.codecov.io/gh/gnolang/gno/pull/2464/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `54.39% <ø> (-0.05%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.