Move checks to common package and add Makefile
Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
23910383a6
commit
6c7b81d401
|
@ -0,0 +1,7 @@
|
|||
.PHONY: build
|
||||
build:
|
||||
go build
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
go fmt ./...
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package imports
|
||||
package checks
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
@ -10,13 +10,13 @@ import (
|
|||
"golang.org/x/tools/go/analysis"
|
||||
)
|
||||
|
||||
var Analyzer = &analysis.Analyzer{
|
||||
var Imports = &analysis.Analyzer{
|
||||
Name: "imports",
|
||||
Doc: "check for import order.",
|
||||
Run: run,
|
||||
Run: runImports,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func runImports(pass *analysis.Pass) (interface{}, error) {
|
||||
for _, file := range pass.Files {
|
||||
level := 0
|
||||
for _, im := range file.Imports {
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package license
|
||||
package checks
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
@ -17,13 +17,13 @@ var (
|
|||
buildTag = "// +build"
|
||||
)
|
||||
|
||||
var Analyzer = &analysis.Analyzer{
|
||||
var License = &analysis.Analyzer{
|
||||
Name: "license",
|
||||
Doc: "check for a copyright header.",
|
||||
Run: run,
|
||||
Run: runLicense,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func runLicense(pass *analysis.Pass) (interface{}, error) {
|
||||
for _, file := range pass.Files {
|
||||
if len(file.Comments) == 0 {
|
||||
pass.Reportf(file.Pos(), "Copyright not found")
|
8
main.go
8
main.go
|
@ -5,15 +5,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"gitea.com/jolheiser/gitea-vet/checks"
|
||||
"golang.org/x/tools/go/analysis/unitchecker"
|
||||
|
||||
"gitea.com/jolheiser/gitea-vet/imports"
|
||||
"gitea.com/jolheiser/gitea-vet/license"
|
||||
)
|
||||
|
||||
func main() {
|
||||
unitchecker.Main(
|
||||
license.Analyzer,
|
||||
imports.Analyzer,
|
||||
checks.Imports,
|
||||
checks.License,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue