mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-08 10:08:42 +08:00
Reopen ruleguard and format code
Signed-off-by: cai.zhang <cai.zhang@zilliz.com>
This commit is contained in:
parent
1104f059ee
commit
3d885742ee
4
Makefile
4
Makefile
@ -24,7 +24,7 @@ get-build-deps:
|
|||||||
getdeps:
|
getdeps:
|
||||||
@mkdir -p ${GOPATH}/bin
|
@mkdir -p ${GOPATH}/bin
|
||||||
@which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.27.0)
|
@which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.27.0)
|
||||||
@which ruleguard 1>/dev/null || (echo "Installing ruleguard" && GO111MODULE=off go get github.com/quasilyte/go-ruleguard/...)
|
@which ruleguard 1>/dev/null || (echo "Installing ruleguard" && go get github.com/quasilyte/go-ruleguard/cmd/ruleguard@v0.2.1)
|
||||||
|
|
||||||
tools/bin/revive: tools/check/go.mod
|
tools/bin/revive: tools/check/go.mod
|
||||||
cd tools/check; \
|
cd tools/check; \
|
||||||
@ -82,7 +82,7 @@ else
|
|||||||
@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./tests/go/...
|
@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./tests/go/...
|
||||||
endif
|
endif
|
||||||
|
|
||||||
verifiers: getdeps cppcheck fmt static-check
|
verifiers: getdeps cppcheck fmt static-check ruleguard
|
||||||
|
|
||||||
# Builds various components locally.
|
# Builds various components locally.
|
||||||
build-go: build-cpp get-rocksdb
|
build-go: build-cpp get-rocksdb
|
||||||
|
|||||||
2
build/docker/env/cpu/ubuntu18.04/Dockerfile
vendored
2
build/docker/env/cpu/ubuntu18.04/Dockerfile
vendored
@ -40,7 +40,7 @@ ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH
|
|||||||
RUN mkdir -p /usr/local/go && wget -qO- "https://golang.org/dl/go1.15.2.linux-amd64.tar.gz" | tar --strip-components=1 -xz -C /usr/local/go && \
|
RUN mkdir -p /usr/local/go && wget -qO- "https://golang.org/dl/go1.15.2.linux-amd64.tar.gz" | tar --strip-components=1 -xz -C /usr/local/go && \
|
||||||
mkdir -p "$GOPATH/src" "$GOPATH/bin" && \
|
mkdir -p "$GOPATH/src" "$GOPATH/bin" && \
|
||||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v1.27.0 && \
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v1.27.0 && \
|
||||||
export GO111MODULE=off && go get github.com/quasilyte/go-ruleguard/... && \
|
export GO111MODULE=on && go get github.com/quasilyte/go-ruleguard/cmd/ruleguard@v0.2.1 && \
|
||||||
chmod -R 777 "$GOPATH" && chmod -R a+w $(go env GOTOOLDIR)
|
chmod -R 777 "$GOPATH" && chmod -R a+w $(go env GOTOOLDIR)
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
|||||||
@ -572,7 +572,7 @@ func (qt *QueryTask) PostExecute() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
distance := hits[q][i].Scores[loc]
|
distance := hits[q][i].Scores[loc]
|
||||||
if distance > maxDistance || (distance == maxDistance && choice != q) {
|
if distance > maxDistance || (math.Abs(float64(distance-maxDistance)) < math.SmallestNonzeroFloat32 && choice != q) {
|
||||||
choice = q
|
choice = q
|
||||||
maxDistance = distance
|
maxDistance = distance
|
||||||
valid = true
|
valid = true
|
||||||
|
|||||||
@ -46,6 +46,7 @@ func unconvert(m fluent.Matcher) {
|
|||||||
func timeeq(m fluent.Matcher) {
|
func timeeq(m fluent.Matcher) {
|
||||||
m.Match("$t0 == $t1").Where(m["t0"].Type.Is("time.Time")).Report("using == with time.Time")
|
m.Match("$t0 == $t1").Where(m["t0"].Type.Is("time.Time")).Report("using == with time.Time")
|
||||||
m.Match("$t0 != $t1").Where(m["t0"].Type.Is("time.Time")).Report("using != with time.Time")
|
m.Match("$t0 != $t1").Where(m["t0"].Type.Is("time.Time")).Report("using != with time.Time")
|
||||||
|
m.Match(`map[$k]$v`).Where(m["k"].Type.Is("time.Time")).Report("map with time.Time keys are easy to misuse")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrong err in error check
|
// Wrong err in error check
|
||||||
@ -213,10 +214,13 @@ func ifreturn(m fluent.Matcher) {
|
|||||||
func oddifsequence(m fluent.Matcher) {
|
func oddifsequence(m fluent.Matcher) {
|
||||||
/*
|
/*
|
||||||
m.Match("if $x { $*_ }; if $x {$*_ }").Report("odd sequence of if test")
|
m.Match("if $x { $*_ }; if $x {$*_ }").Report("odd sequence of if test")
|
||||||
|
|
||||||
m.Match("if $x == $y { $*_ }; if $y == $x {$*_ }").Report("odd sequence of if tests")
|
m.Match("if $x == $y { $*_ }; if $y == $x {$*_ }").Report("odd sequence of if tests")
|
||||||
m.Match("if $x != $y { $*_ }; if $y != $x {$*_ }").Report("odd sequence of if tests")
|
m.Match("if $x != $y { $*_ }; if $y != $x {$*_ }").Report("odd sequence of if tests")
|
||||||
|
|
||||||
m.Match("if $x < $y { $*_ }; if $y > $x {$*_ }").Report("odd sequence of if tests")
|
m.Match("if $x < $y { $*_ }; if $y > $x {$*_ }").Report("odd sequence of if tests")
|
||||||
m.Match("if $x <= $y { $*_ }; if $y >= $x {$*_ }").Report("odd sequence of if tests")
|
m.Match("if $x <= $y { $*_ }; if $y >= $x {$*_ }").Report("odd sequence of if tests")
|
||||||
|
|
||||||
m.Match("if $x > $y { $*_ }; if $y < $x {$*_ }").Report("odd sequence of if tests")
|
m.Match("if $x > $y { $*_ }; if $y < $x {$*_ }").Report("odd sequence of if tests")
|
||||||
m.Match("if $x >= $y { $*_ }; if $y <= $x {$*_ }").Report("odd sequence of if tests")
|
m.Match("if $x >= $y { $*_ }; if $y <= $x {$*_ }").Report("odd sequence of if tests")
|
||||||
*/
|
*/
|
||||||
@ -357,7 +361,7 @@ func largeloopcopy(m fluent.Matcher) {
|
|||||||
m.Match(
|
m.Match(
|
||||||
`for $_, $v := range $_ { $*_ }`,
|
`for $_, $v := range $_ { $*_ }`,
|
||||||
).
|
).
|
||||||
Where(m["v"].Type.Size > 512).
|
Where(m["v"].Type.Size > 1024).
|
||||||
Report(`loop copies large value each iteration`)
|
Report(`loop copies large value each iteration`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,3 +458,20 @@ func hmacnew(m fluent.Matcher) {
|
|||||||
).Where(m["x"].Pure).
|
).Where(m["x"].Pure).
|
||||||
Report("invalid hash passed to hmac.New()")
|
Report("invalid hash passed to hmac.New()")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func writestring(m fluent.Matcher) {
|
||||||
|
m.Match(`io.WriteString($w, string($b))`).
|
||||||
|
Where(m["b"].Type.Is("[]byte")).
|
||||||
|
Suggest("$w.Write($b)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func badlock(m fluent.Matcher) {
|
||||||
|
// Shouldn't give many false positives without type filter
|
||||||
|
// as Lock+Unlock pairs in combination with defer gives us pretty
|
||||||
|
// a good chance to guess correctly. If we constrain the type to sync.Mutex
|
||||||
|
// then it'll be harder to match embedded locks and custom methods
|
||||||
|
// that may forward the call to the sync.Mutex (or other synchronization primitive).
|
||||||
|
|
||||||
|
m.Match(`$mu.Lock(); defer $mu.RUnlock()`).Report(`maybe $mu.RLock() was intended?`)
|
||||||
|
m.Match(`$mu.RLock(); defer $mu.Unlock()`).Report(`maybe $mu.Lock() was intended?`)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user