Skip to content

Add CI workflow to lint and check formatting of Go code #2

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

Merged
merged 6 commits into from
May 7, 2021
Merged

Add CI workflow to lint and check formatting of Go code #2

merged 6 commits into from
May 7, 2021

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented May 6, 2021

On every push and pull request that affects relevant files, and periodically, lint and check formatting of the
repository's Go module.

per1234 added 6 commits May 6, 2021 02:52
An environment variable was used instead of the intended dynamic variable.
On every push and pull request that affects relevant files, and periodically, lint and check formatting of the
repository's Go module.
@per1234 per1234 added the type: enhancement Proposed improvement label May 6, 2021
@per1234
Copy link
Contributor Author

per1234 commented May 6, 2021

There is the remaining go vet error I didn't tackle yet because I'm not knowledgeable about the subject matter:

libraries/db/db.go:213:34: call of json.MarshalIndent copies lock value: arduino.cc/repository/libraries/db.DB contains sync.Mutex

If I'm to guess, it would be this:

diff --git a/libraries/db/db.go b/libraries/db/db.go
index d02bee9..d313367 100644
--- a/libraries/db/db.go
+++ b/libraries/db/db.go
@@ -210,7 +210,7 @@ func (db *DB) Save(r io.Writer) error {
 }

 func (db *DB) save(r io.Writer) error {
-       buff, err := json.MarshalIndent(*db, "", "  ")
+       buff, err := json.MarshalIndent(db, "", "  ")
        if err != nil {
                return err
        }

@silvanocerza
Copy link
Contributor

silvanocerza commented May 6, 2021

@per1234 I think this should be the fix, much like in other DB methods.

diff --git a/libraries/db/db.go b/libraries/db/db.go
index d02bee9..d313367 100644
--- a/libraries/db/db.go
+++ b/libraries/db/db.go
@@ -210,7 +210,7 @@ func (db *DB) Save(r io.Writer) error {
 }

 func (db *DB) save(r io.Writer) error {
+	db.mutex.Lock()
+	defer db.mutex.Unlock()
        buff, err := json.MarshalIndent(*db, "", "  ")
        if err != nil {
                return err
        }

I didn't test it though.

@per1234
Copy link
Contributor Author

per1234 commented May 7, 2021

Thanks @silvanocerza! Since the go vet violation was not introduced by this PR, but only exposed by it, I'm going to merge this as is. Hopefully the repository can be brought into full compliance in the near future.


UPDATE: fixed in #46

@per1234 per1234 merged commit 150767a into arduino:master May 7, 2021
@per1234 per1234 deleted the check-go branch May 7, 2021 06:20
@per1234 per1234 self-assigned this Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants