pavius / impi Goto Github PK
View Code? Open in Web Editor NEWVerify proper golang import directives, beyond the capability of gofmt and goimports.
License: MIT License
Verify proper golang import directives, beyond the capability of gofmt and goimports.
License: MIT License
I noticed whilst testing changes over the weekend that a deadlock can occur if a local prefix is supplied that doesn't match any import (unsure what the exact reason is at this stage). This occurs on v0.0.1
so it's not linked to any recent changes. I'm happy to take a look at some point, just raising for visibility at the moment.
$ /Users/nicholas/Dev/impi/cmd/impi/impi --local github.com/invalid/prefix --scheme stdThirdPartyLocal --ignore-generated=true ./...
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send]:
github.com/pavius/impi.(*Impi).addFilePathToFilePathsChan(0xc00004a3c0, 0xc0004106c0, 0x25)
/Users/nicholas/Dev/impi/impi.go:254 +0x1df
github.com/pavius/impi.(*Impi).populatePathsChan(0xc00004a3c0, 0x7ffeefbffa8d, 0x5, 0x0, 0x135a008)
/Users/nicholas/Dev/impi/impi.go:144 +0x29b
github.com/pavius/impi.(*Impi).Verify(0xc00004a3c0, 0x7ffeefbffa8d, 0x5, 0xc00004a400, 0x11d1020, 0x1306c10, 0x15, 0xc0000403e0)
/Users/nicholas/Dev/impi/impi.go:105 +0x162
main.run(0x17, 0xc000097f58)
/Users/nicholas/Dev/impi/cmd/impi/main.go:70 +0x405
main.main()
/Users/nicholas/Dev/impi/cmd/impi/main.go:92 +0x41
goroutine 4 [chan send]:
github.com/pavius/impi.(*Impi).verifyPathsFromChan(0xc00004a3c0, 0x118a660, 0x60)
/Users/nicholas/Dev/impi/impi.go:215 +0x18b
created by github.com/pavius/impi.(*Impi).createWorkers
/Users/nicholas/Dev/impi/impi.go:184 +0x48
goroutine 5 [chan send]:
github.com/pavius/impi.(*Impi).verifyPathsFromChan(0xc00004a3c0, 0x118a660, 0x60)
/Users/nicholas/Dev/impi/impi.go:215 +0x18b
created by github.com/pavius/impi.(*Impi).createWorkers
/Users/nicholas/Dev/impi/impi.go:184 +0x48
goroutine 6 [chan send]:
github.com/pavius/impi.(*Impi).verifyPathsFromChan(0xc00004a3c0, 0x118a660, 0x60)
/Users/nicholas/Dev/impi/impi.go:215 +0x18b
created by github.com/pavius/impi.(*Impi).createWorkers
/Users/nicholas/Dev/impi/impi.go:184 +0x48
goroutine 7 [chan send]:
github.com/pavius/impi.(*Impi).verifyPathsFromChan(0xc00004a3c0, 0x118a660, 0x60)
/Users/nicholas/Dev/impi/impi.go:215 +0x18b
created by github.com/pavius/impi.(*Impi).createWorkers
/Users/nicholas/Dev/impi/impi.go:184 +0x48
When using import "C"
the C code in the comments need to be right before the directive. Which means we can get 4 groups of imports.
If we have code like:
import (
"fmt"
"net/http"
"os"
goruntime "runtime"
"strings"
"unsafe"
"github.com/nuclio/nuclio/pkg/errors"
"github.com/nuclio/nuclio/pkg/processor/runtime"
"github.com/nuclio/logger"
"github.com/nuclio/nuclio-sdk-go"
)
/*
#include <Python.h>
#include <stdlib.h>
#include "types.h"
extern response_t call_handler(unsigned long event_ptr, unsigned long logger_ptr);
extern char *py_last_error();
void free_response_t(response_t response);
*/
import "C"
Then impi
thinks there are 4 import groups due to the empty line in the comment before `import "C"
$ impi --local github.com/nuclio/nuclio/ --scheme stdLocalThirdParty ./cmd/... ./pkg/...
pkg/processor/runtime/python3/runtime.go: Expected no more than 3 groups, got 4
If we remove the empty line after #include "types.h"
then impi
is happy.
This example, should pass (I hope):
test.go
package test
import (
"crypto/hmac"
"crypto/md5" // #nosec
"crypto/sha1" // #nosec
"encoding/base64"
)
but it fails: $ impi --scheme stdThirdPartyLocal test.go
- Import group 0 is not sorted
-- Got:
crypto/hmac
// #nosec
// #nosec
encoding/base64
-- Expected:
// #nosec
// #nosec
crypto/hmac
encoding/base64
We need to inline the // #nosec
on import statements (for gosec -- "safe" usage of md5/sha1 in out codebase). This utility is conflicting with gofumpt and gosec -- can't make all three happy simultaneously :)
I believe this utility should allow inline comments on import statements. From the Got/Expected output, it seems this linter is eating the imported package name and trying to sort based on the inline'd comment...
It would be nice to have an option to skip files that have the standard header comment indicating they were generated with a code generator:
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
import (
"io"
"io/ioutil"
"net/textproto"
"strings"
imap "github.com/emersion/go-imap"
"github.com/emersion/go-imap/client"
// register all charsets
_ "github.com/emersion/go-message/charset"
"github.com/emersion/go-message/mail"
"github.com/pkg/errors"
"github.com/agflow/agflow/pkg/log"
"github.com/agflow/agflow/pkg/util/convert"
)
In the above code, golint
requires comment, gofmt
puts blank line then impi
complains. How to handle this case?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.