2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-15 12:47:52 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-16 18:26:13 +00:00
|
|
|
// +build ignore
|
|
|
|
|
2018-11-15 12:47:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
2018-11-27 12:16:52 +00:00
|
|
|
var checkFiles = map[string]bool{
|
|
|
|
".go": true,
|
|
|
|
".ts": true,
|
|
|
|
".js": true,
|
|
|
|
".vue": true,
|
|
|
|
}
|
|
|
|
|
2019-09-05 14:32:46 +01:00
|
|
|
var ignoreFolder = map[string]bool{
|
|
|
|
".git": true,
|
|
|
|
"node_modules": true,
|
|
|
|
"coverage": true,
|
|
|
|
"dist": true,
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:47:52 +00:00
|
|
|
func main() {
|
|
|
|
var failed int
|
|
|
|
|
|
|
|
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return nil
|
|
|
|
}
|
2019-09-05 14:32:46 +01:00
|
|
|
if info.IsDir() && ignoreFolder[info.Name()] {
|
2018-11-15 12:47:52 +00:00
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
2018-11-27 12:16:52 +00:00
|
|
|
if !checkFiles[filepath.Ext(path)] {
|
2018-11-15 12:47:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
file, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
failed++
|
|
|
|
fmt.Printf("failed to read %v: %v\n", path, err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := file.Close(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
var header [256]byte
|
|
|
|
n, err := file.Read(header[:])
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
fmt.Printf("failed to read %v: %v\n", path, err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if bytes.Contains(header[:n], []byte(`AUTOGENERATED`)) ||
|
|
|
|
bytes.Contains(header[:n], []byte(`Code generated`)) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Contains(header[:n], []byte(`Copyright `)) {
|
|
|
|
failed++
|
|
|
|
fmt.Printf("missing copyright: %v\n", path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if failed > 0 {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|