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
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package imports
|
package checks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -10,13 +10,13 @@ import (
|
||||||
"golang.org/x/tools/go/analysis"
|
"golang.org/x/tools/go/analysis"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Analyzer = &analysis.Analyzer{
|
var Imports = &analysis.Analyzer{
|
||||||
Name: "imports",
|
Name: "imports",
|
||||||
Doc: "check for import order.",
|
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 {
|
for _, file := range pass.Files {
|
||||||
level := 0
|
level := 0
|
||||||
for _, im := range file.Imports {
|
for _, im := range file.Imports {
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package license
|
package checks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -17,13 +17,13 @@ var (
|
||||||
buildTag = "// +build"
|
buildTag = "// +build"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Analyzer = &analysis.Analyzer{
|
var License = &analysis.Analyzer{
|
||||||
Name: "license",
|
Name: "license",
|
||||||
Doc: "check for a copyright header.",
|
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 {
|
for _, file := range pass.Files {
|
||||||
if len(file.Comments) == 0 {
|
if len(file.Comments) == 0 {
|
||||||
pass.Reportf(file.Pos(), "Copyright not found")
|
pass.Reportf(file.Pos(), "Copyright not found")
|
8
main.go
8
main.go
|
@ -5,15 +5,13 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitea.com/jolheiser/gitea-vet/checks"
|
||||||
"golang.org/x/tools/go/analysis/unitchecker"
|
"golang.org/x/tools/go/analysis/unitchecker"
|
||||||
|
|
||||||
"gitea.com/jolheiser/gitea-vet/imports"
|
|
||||||
"gitea.com/jolheiser/gitea-vet/license"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
unitchecker.Main(
|
unitchecker.Main(
|
||||||
license.Analyzer,
|
checks.Imports,
|
||||||
imports.Analyzer,
|
checks.License,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue