mirror of
				https://github.com/matrix-org/gomatrix
				synced 2025-11-03 22:08:04 +00:00 
			
		
		
		
	Switch to golangci-lint
This commit is contained in:
		
							parent
							
								
									9e7906b676
								
							
						
					
					
						commit
						911b396dd1
					
				
					 6 changed files with 26 additions and 32 deletions
				
			
		
							
								
								
									
										16
									
								
								.golangci.yaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								.golangci.yaml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
---
 | 
			
		||||
linters:
 | 
			
		||||
  enable:
 | 
			
		||||
    - gocyclo
 | 
			
		||||
    - gofmt
 | 
			
		||||
    - goimports
 | 
			
		||||
    - golint
 | 
			
		||||
    - govet
 | 
			
		||||
    - ineffassign
 | 
			
		||||
    - misspell
 | 
			
		||||
 | 
			
		||||
linters-settings:
 | 
			
		||||
  gocyclo:
 | 
			
		||||
    min-complexity: 13
 | 
			
		||||
  govet:
 | 
			
		||||
    check-shadowing: true
 | 
			
		||||
| 
						 | 
				
			
			@ -1,9 +1,6 @@
 | 
			
		|||
language: go
 | 
			
		||||
go:
 | 
			
		||||
 - 1.10.x
 | 
			
		||||
 - 1.13.x
 | 
			
		||||
install:
 | 
			
		||||
 - go get github.com/golang/lint/golint
 | 
			
		||||
 - go get github.com/fzipp/gocyclo
 | 
			
		||||
 - go get github.com/client9/misspell/...
 | 
			
		||||
 - go get github.com/gordonklaus/ineffassign
 | 
			
		||||
 - go get github.com/golangci/golangci-lint/cmd/golangci-lint
 | 
			
		||||
script: ./hooks/pre-commit
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -56,9 +56,7 @@ func (e HTTPError) Error() string {
 | 
			
		|||
// BuildURL builds a URL with the Client's homserver/prefix/access_token set already.
 | 
			
		||||
func (cli *Client) BuildURL(urlPath ...string) string {
 | 
			
		||||
	ps := []string{cli.Prefix}
 | 
			
		||||
	for _, p := range urlPath {
 | 
			
		||||
		ps = append(ps, p)
 | 
			
		||||
	}
 | 
			
		||||
	ps = append(ps, urlPath...)
 | 
			
		||||
	return cli.BuildBaseURL(ps...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -195,7 +193,7 @@ func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{
 | 
			
		|||
	var err error
 | 
			
		||||
	if reqBody != nil {
 | 
			
		||||
		buf := new(bytes.Buffer)
 | 
			
		||||
		if err := json.NewEncoder(buf).Encode(reqBody); err != nil {
 | 
			
		||||
		if err = json.NewEncoder(buf).Encode(reqBody); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		req, err = http.NewRequest(method, httpURL, buf)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,7 +46,9 @@ func Example_customInterfaces() {
 | 
			
		|||
	cli.Client = http.DefaultClient
 | 
			
		||||
 | 
			
		||||
	// Once you call a function, you can't safely change the interfaces.
 | 
			
		||||
	cli.SendText("!foo:bar", "Down the rabbit hole")
 | 
			
		||||
	if _, err := cli.SendText("!foo:bar", "Down the rabbit hole"); err != nil {
 | 
			
		||||
		fmt.Println("SendText() returned ", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ExampleClient_BuildURLWithQuery() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,25 +2,6 @@
 | 
			
		|||
 | 
			
		||||
set -eu
 | 
			
		||||
 | 
			
		||||
golint
 | 
			
		||||
misspell --error .
 | 
			
		||||
golangci-lint run
 | 
			
		||||
 | 
			
		||||
# gofmt doesn't exit with an error code if the files don't match the expected
 | 
			
		||||
# format. So we have to run it and see if it outputs anything.
 | 
			
		||||
if gofmt -l -s . 2>&1 | read
 | 
			
		||||
then
 | 
			
		||||
    echo "Error: not all code had been formatted with gofmt."
 | 
			
		||||
    echo "Fixing the following files"
 | 
			
		||||
    gofmt -s -w -l .
 | 
			
		||||
    echo
 | 
			
		||||
    echo "Please add them to the commit"
 | 
			
		||||
    git status --short
 | 
			
		||||
    exit 1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
ineffassign .
 | 
			
		||||
 | 
			
		||||
go fmt
 | 
			
		||||
go tool vet --all --shadow .
 | 
			
		||||
gocyclo -over 12 .
 | 
			
		||||
go test -timeout 5s -test.v
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										4
									
								
								room.go
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								room.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -31,8 +31,8 @@ func (room Room) UpdateState(event *Event) {
 | 
			
		|||
 | 
			
		||||
// GetStateEvent returns the state event for the given type/state_key combo, or nil.
 | 
			
		||||
func (room Room) GetStateEvent(eventType string, stateKey string) *Event {
 | 
			
		||||
	stateEventMap, _ := room.State[eventType]
 | 
			
		||||
	event, _ := stateEventMap[stateKey]
 | 
			
		||||
	stateEventMap := room.State[eventType]
 | 
			
		||||
	event := stateEventMap[stateKey]
 | 
			
		||||
	return event
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue