You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-08-08 04:42:07 +03:00
Add self-contained gometalinter build tooling.
This commit is contained in:
39
tools/vendor/github.com/walle/lll/CONTRIBUTING.md
generated
vendored
Normal file
39
tools/vendor/github.com/walle/lll/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# Contributing
|
||||
|
||||
## Issues
|
||||
|
||||
When opening issues, try to be as clear as possible when describing the bug or
|
||||
feature request. Tag the issue accordingly.
|
||||
|
||||
## Pull Requests
|
||||
|
||||
### Hack on lll
|
||||
|
||||
1. Install as usual (`go get github.com/walle/lll`)
|
||||
2. Write code and tests for your new feature
|
||||
3. Ensure everything works and the tests pass (see below)
|
||||
4. Consider contributing your code upstream
|
||||
|
||||
### Contribute upstream
|
||||
|
||||
1. Fork ll on GitHub
|
||||
2. Add your fork (`git remote add fork git@github.com:myuser/lll.git`)
|
||||
3. Checkout your fork (`git checkout -t fork/master`)
|
||||
4. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
5. Write code and tests for your new feature
|
||||
6. Rebase against upstream to get changes \
|
||||
(`git fetch origin && git rebase origin/master`)
|
||||
7. Ensure everything works and the tests pass (see below)
|
||||
8. Commit your changes
|
||||
9. Push the branch to github (`git push fork my-new-feature`)
|
||||
10. Create a new Pull Request on GitHub
|
||||
|
||||
Notice: Always use the original import path by installing with `go get`.
|
||||
|
||||
## Testing
|
||||
|
||||
To run the test suite use the command
|
||||
|
||||
```shell
|
||||
$ go test -cover
|
||||
```
|
20
tools/vendor/github.com/walle/lll/LICENSE
generated
vendored
Normal file
20
tools/vendor/github.com/walle/lll/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
Copyright (c) 2016 Fredrik Wallgren
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
64
tools/vendor/github.com/walle/lll/README.md
generated
vendored
Normal file
64
tools/vendor/github.com/walle/lll/README.md
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
[](https://travis-ci.org/walle/lll)
|
||||
[](https://codecov.io/github/walle/lll)
|
||||
[](https://godoc.org/github.com/walle/lll)
|
||||
[](https://raw.githubusercontent.com/walle/lll/master/LICENSE)
|
||||
[](http:/goreportcard.com/report/walle/lll)
|
||||
|
||||
# lll
|
||||
|
||||
Line length linter, used to enforce line length in files.
|
||||
Support for only checking go files.
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
$ go get github.com/walle/lll/...
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```shell
|
||||
usage: lll [--maxlength MAXLENGTH] [--tabwidth TABWIDTH] [--goonly] [--skiplist SKIPLIST] [--vendor] [--files] [--exclude EXCLUDE] [INPUT [INPUT ...]]
|
||||
|
||||
positional arguments:
|
||||
input
|
||||
|
||||
options:
|
||||
--maxlength MAXLENGTH, -l MAXLENGTH
|
||||
max line length to check for [default: 80]
|
||||
--tabwidth TABWIDTH, -w TABWIDTH
|
||||
tab width in spaces [default: 1]
|
||||
--goonly, -g only check .go files
|
||||
--skiplist SKIPLIST, -s SKIPLIST
|
||||
list of dirs to skip [default: [.git vendor]]
|
||||
--vendor check files in vendor directory
|
||||
--files read file names from stdin one at each line
|
||||
--exclude EXCLUDE, -e EXCLUDE
|
||||
exclude lines that matches this regex
|
||||
--help, -h display this help and exit
|
||||
```
|
||||
|
||||
Example usage to check only go files for lines more than 100 characters.
|
||||
Excluding lines that contain the words TODO or FIXME.
|
||||
`lll -l 100 -g -e "TODO|FIXME" path/to/myproject`.
|
||||
|
||||
You can also define the flags using environment variables, eg.
|
||||
`MAXLENGTH=100 GOONLY=true lll path/to/my/project`.
|
||||
|
||||
## Testing
|
||||
|
||||
Use the `go test` tool.
|
||||
|
||||
```shell
|
||||
$ go test -cover
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
All contributions are welcome! See [CONTRIBUTING](CONTRIBUTING.md) for more
|
||||
info.
|
||||
|
||||
## License
|
||||
|
||||
The code is under the MIT license. See [LICENSE](LICENSE) for more
|
||||
information.
|
89
tools/vendor/github.com/walle/lll/cmd/lll/main.go
generated
vendored
Normal file
89
tools/vendor/github.com/walle/lll/cmd/lll/main.go
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/alexflint/go-arg"
|
||||
|
||||
"github.com/walle/lll"
|
||||
)
|
||||
|
||||
var args struct {
|
||||
MaxLength int `arg:"-l,env,help:max line length to check for"`
|
||||
TabWidth int `arg:"-w,env,help:tab width in spaces"`
|
||||
GoOnly bool `arg:"-g,env,help:only check .go files"`
|
||||
Input []string `arg:"positional"`
|
||||
SkipList []string `arg:"-s,env,help:list of dirs to skip"`
|
||||
Vendor bool `arg:"env,help:check files in vendor directory"`
|
||||
Files bool `arg:"help:read file names from stdin one at each line"`
|
||||
Exclude string `arg:"-e,env,help:exclude lines that matches this regex"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
args.MaxLength = 80
|
||||
args.TabWidth = 1
|
||||
args.SkipList = []string{".git", "vendor"}
|
||||
arg.MustParse(&args)
|
||||
|
||||
var exclude *regexp.Regexp
|
||||
if args.Exclude != "" {
|
||||
e, err := regexp.Compile(args.Exclude)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error compiling exclude regexp: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
exclude = e
|
||||
}
|
||||
|
||||
// If we should include the vendor dir, attempt to remove it from the skip list
|
||||
if args.Vendor {
|
||||
for i, p := range args.SkipList {
|
||||
if p == "vendor" {
|
||||
args.SkipList = append(args.SkipList[:i], args.SkipList[:i]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we should read files from stdin, read each line and process the file
|
||||
if args.Files {
|
||||
s := bufio.NewScanner(os.Stdin)
|
||||
for s.Scan() {
|
||||
err := lll.ProcessFile(os.Stdout, s.Text(),
|
||||
args.MaxLength, args.TabWidth, exclude)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error processing file: %s\n", err)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Otherwise, walk the inputs recursively
|
||||
for _, d := range args.Input {
|
||||
err := filepath.Walk(d, func(p string, i os.FileInfo, e error) error {
|
||||
if i == nil {
|
||||
fmt.Fprintf(os.Stderr, "lll: %s no such file or directory\n", p)
|
||||
return nil
|
||||
}
|
||||
if e != nil {
|
||||
fmt.Fprintf(os.Stderr, "lll: %s\n", e)
|
||||
return nil
|
||||
}
|
||||
skip, ret := lll.ShouldSkip(p, i.IsDir(), args.SkipList, args.GoOnly)
|
||||
if skip {
|
||||
return ret
|
||||
}
|
||||
|
||||
err := lll.ProcessFile(os.Stdout, p, args.MaxLength, args.TabWidth, exclude)
|
||||
return err
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error walking the file system: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
101
tools/vendor/github.com/walle/lll/lll.go
generated
vendored
Normal file
101
tools/vendor/github.com/walle/lll/lll.go
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
// Package lll provides validation functions regarding line length
|
||||
package lll
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// ShouldSkip checks the input and determines if the path should be skipped.
|
||||
// Use the SkipList to quickly skip paths.
|
||||
// All directories are skipped, only files are processed.
|
||||
// If GoOnly is supplied check that the file is a go file.
|
||||
// Otherwise check so the file is a "text file".
|
||||
func ShouldSkip(path string, isDir bool, skipList []string,
|
||||
goOnly bool) (bool, error) {
|
||||
|
||||
name := filepath.Base(path)
|
||||
for _, d := range skipList {
|
||||
if name == d {
|
||||
if isDir {
|
||||
return true, filepath.SkipDir
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
if isDir {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if goOnly {
|
||||
if !strings.HasSuffix(path, ".go") {
|
||||
return true, nil
|
||||
}
|
||||
} else {
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
m := http.DetectContentType(b)
|
||||
if !strings.Contains(m, "text/") {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// ProcessFile checks all lines in the file and writes an error if the line
|
||||
// length is greater than MaxLength.
|
||||
func ProcessFile(w io.Writer, path string, maxLength, tabWidth int,
|
||||
exclude *regexp.Regexp) error {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
err := f.Close()
|
||||
if err != nil {
|
||||
fmt.Printf("Error closing file: %s\n", err)
|
||||
}
|
||||
}()
|
||||
|
||||
return Process(f, w, path, maxLength, tabWidth, exclude)
|
||||
}
|
||||
|
||||
// Process checks all lines in the reader and writes an error if the line length
|
||||
// is greater than MaxLength.
|
||||
func Process(r io.Reader, w io.Writer, path string, maxLength, tabWidth int,
|
||||
exclude *regexp.Regexp) error {
|
||||
spaces := strings.Repeat(" ", tabWidth)
|
||||
l := 1
|
||||
s := bufio.NewScanner(r)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
t = strings.Replace(t, "\t", spaces, -1)
|
||||
c := utf8.RuneCountInString(t)
|
||||
if c > maxLength {
|
||||
if exclude != nil {
|
||||
if exclude.MatchString(t) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(w, "%s:%d: line is %d characters\n", path, l, c)
|
||||
}
|
||||
l++
|
||||
}
|
||||
|
||||
if err := s.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user