Skip to content

Commit 4316712

Browse files
authored
Remove "manual" check for beats import && use revive instead (#16)
1 parent 185b343 commit 4316712

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

.golangci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ linters:
6464
- unconvert # Remove unnecessary type conversions
6565
- wastedassign # wastedassign finds wasted assignment statements.
6666
- godox # tool for detection of FIXME, TODO and other comment keywords
67+
- revive # avoid bad imports
6768

6869
# all available settings of specific linters
6970
linters-settings:
@@ -136,6 +137,15 @@ linters-settings:
136137
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
137138
require-specific: true
138139

140+
revive:
141+
enable-all-rules: false
142+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
143+
rules:
144+
- name: imports-blacklist
145+
arguments:
146+
- github.com/pkg/errors
147+
- github.com/elastic/beats/v7
148+
139149
staticcheck:
140150
# Select the Go version to target. The default is '1.13'.
141151
go: "1.17.6"

magefile.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
package main
2222

2323
import (
24-
"bufio"
25-
"bytes"
2624
"errors"
2725
"fmt"
2826
"io"
@@ -199,7 +197,7 @@ func (l Linter) LastChange() error {
199197
// Check runs all the checks
200198
// nolint: deadcode,unparam // it's used as a `mage` target and requires returning an error
201199
func Check() error {
202-
mg.Deps(Deps.CheckNoBeats, Deps.CheckModuleTidy, Linter.LastChange)
200+
mg.Deps(Deps.CheckModuleTidy, Linter.LastChange)
203201
return nil
204202
}
205203

@@ -213,33 +211,6 @@ func UpdateGoVersion() error {
213211
// Deps contains targets related to checking dependencies
214212
type Deps mg.Namespace
215213

216-
// CheckNoBeats is required to make sure we are not introducing
217-
// dependency on elastic/beats.
218-
func (Deps) CheckNoBeats() error {
219-
goModPath, err := filepath.Abs("go.mod")
220-
if err != nil {
221-
return err
222-
}
223-
goModFile, err := os.Open(goModPath)
224-
if err != nil {
225-
return fmt.Errorf("failed to open module file: %w", err)
226-
}
227-
beatsImport := []byte("github.com/elastic/beats")
228-
scanner := bufio.NewScanner(goModFile)
229-
lineCount := 1
230-
for scanner.Scan() {
231-
line := scanner.Bytes()
232-
if bytes.Contains(line, beatsImport) {
233-
return fmt.Errorf("line %d is a beats dependency: '%s'\nPlease, make sure you are not adding anything that depends on %s", lineCount, line, beatsImport)
234-
}
235-
lineCount++
236-
}
237-
if err := scanner.Err(); err != nil {
238-
return err
239-
}
240-
return nil
241-
}
242-
243214
// CheckModuleTidy checks if `go mod tidy` was run before the last commit.
244215
func (Deps) CheckModuleTidy() error {
245216
err := sh.Run("go", "mod", "tidy")

0 commit comments

Comments
 (0)