mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
821 B
40 lines
821 B
5 years ago
|
package rule
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/mgechev/revive/lint"
|
||
|
)
|
||
|
|
||
|
// DuplicatedImportsRule lints given else constructs.
|
||
|
type DuplicatedImportsRule struct{}
|
||
|
|
||
|
// Apply applies the rule to given file.
|
||
|
func (r *DuplicatedImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
|
||
|
var failures []lint.Failure
|
||
|
|
||
|
impPaths := map[string]struct{}{}
|
||
|
for _, imp := range file.AST.Imports {
|
||
|
path := imp.Path.Value
|
||
|
_, ok := impPaths[path]
|
||
|
if ok {
|
||
|
failures = append(failures, lint.Failure{
|
||
|
Confidence: 1,
|
||
|
Failure: fmt.Sprintf("Package %s already imported", path),
|
||
|
Node: imp,
|
||
|
Category: "imports",
|
||
|
})
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
impPaths[path] = struct{}{}
|
||
|
}
|
||
|
|
||
|
return failures
|
||
|
}
|
||
|
|
||
|
// Name returns the rule name.
|
||
|
func (r *DuplicatedImportsRule) Name() string {
|
||
|
return "duplicated-imports"
|
||
|
}
|