Skip to content

Commit 8453bf3

Browse files
committed
Apply a few linter improvement suggestions
1 parent cb85d3e commit 8453bf3

21 files changed

+129
-67
lines changed

_examples/xmpp_chat_client/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ You can build the client using :
77
```
88
go build -o example_client
99
```
10-
and then run with (on unix for example):
10+
and then run with (on UNIX, for example):
1111
```
1212
./example_client
1313
```
14-
or you can simply build + run in one command while at the example directory root, like this:
14+
Alternatively, you can build and run in one command while at the example directory root, like this:
1515
```
1616
go run xmpp_chat_client.go interface.go
1717
```
@@ -24,7 +24,7 @@ To provide a different configuration file, pass the following argument to the ex
2424
go run xmpp_chat_client.go interface.go -c /path/to/config
2525
```
2626
where /path/to/config is the path to the directory containing the configuration file. The configuration file must be named
27-
"config" and be using the yaml format.
27+
"config" and be using the YAML format.
2828

2929
Required fields are :
3030
```yaml
@@ -36,16 +36,17 @@ Client : # This is you
3636

3737
# Contacts list, ";" separated
3838
Contacts : "testuser1@localhost;testuser3@localhost"
39-
# Should we log stanzas ?
39+
# Should we log stanzas?
4040
LogStanzas:
4141
- logger_on: "true"
4242
- logfile_path: "./logs" # Path to directory, not file.
4343
```
4444
4545
## How to use
46-
Shortcuts :
47-
- ctrl+space : switch between input window and menu window.
48-
- While in input window :
49-
- enter : sends a message if in message mode (see menu options)
50-
- ctrl+e : sends a raw stanza when in raw mode (see menu options)
51-
- ctrl+c : quit
46+
47+
Shortcuts:
48+
- ctrl+space: switch between input window and menu window.
49+
- While in the input window:
50+
- enter: sends a message if in message mode (see menu options)
51+
- ctrl+e: sends a raw stanza when in raw mode (see menu options)
52+
- ctrl+c: quit

_examples/xmpp_chat_client/interface.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package main
33
import (
44
"errors"
55
"fmt"
6-
"github.com/awesome-gocui/gocui"
76
"log"
87
"strings"
8+
9+
"github.com/awesome-gocui/gocui"
910
)
1011

1112
const (
@@ -283,7 +284,7 @@ func getLine(g *gocui.Gui, v *gocui.View) error {
283284
// Updating the current correspondent, back-end side.
284285
CorrespChan <- l
285286
viewState.currentContact = l
286-
// Showing the selected contact in contacts list
287+
// Showing the selected contact in the contacts list
287288
cl, _ := g.View(contactsListWindow)
288289
cts := cl.ViewBufferLines()
289290
cl.Clear()

_examples/xmpp_chat_client/xmpp_chat_client.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ import (
1010
"errors"
1111
"flag"
1212
"fmt"
13-
"github.com/awesome-gocui/gocui"
14-
"github.com/spf13/pflag"
15-
"github.com/spf13/viper"
16-
"gosrc.io/xmpp"
17-
"gosrc.io/xmpp/stanza"
1813
"log"
1914
"os"
2015
"path"
2116
"strconv"
2217
"strings"
2318
"time"
19+
20+
"github.com/awesome-gocui/gocui"
21+
"github.com/spf13/pflag"
22+
"github.com/spf13/viper"
23+
"gosrc.io/xmpp"
24+
"gosrc.io/xmpp/stanza"
2425
)
2526

2627
const (
@@ -247,9 +248,9 @@ func readConfig() *config {
247248
if err := viper.ReadInConfig(); err != nil {
248249
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
249250
log.Fatalf("%s %s", err, "Please make sure you give a path to the directory of the config and not to the config itself.")
250-
} else {
251-
log.Panicln(err)
252251
}
252+
253+
log.Panicln(err)
253254
}
254255

255256
viper.SetConfigType(configType)

_examples/xmpp_pubsub_client/xmpp_ps_client.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"encoding/xml"
66
"errors"
77
"fmt"
8-
"gosrc.io/xmpp"
9-
"gosrc.io/xmpp/stanza"
108
"log"
119
"time"
10+
11+
"gosrc.io/xmpp"
12+
"gosrc.io/xmpp/stanza"
1213
)
1314

1415
const (
@@ -101,27 +102,26 @@ func createNode(ctx context.Context, cancel context.CancelFunc, client *xmpp.Cli
101102
createCh, err := client.SendIQ(ctx, rqCreate)
102103
if err != nil {
103104
log.Fatalf("%+v", err)
104-
} else {
105+
}
105106

106-
if createCh != nil {
107-
select {
108-
case respCr := <-createCh:
109-
// Got response from server
110-
if respCr.Type == stanza.IQTypeError {
111-
if vld, err := respCr.IsValid(); !vld {
112-
log.Fatalf(invalidResp.Error()+" %+v"+" reason: %s", respCr, err)
113-
}
114-
if respCr.Error.Reason != "conflict" {
115-
log.Fatalf("%+v", respCr.Error.Text)
116-
}
117-
log.Println(respCr.Error.Text)
118-
} else {
119-
fmt.Print("successfully created channel")
107+
if createCh != nil {
108+
select {
109+
case respCr := <-createCh:
110+
// Got response from server
111+
if respCr.Type == stanza.IQTypeError {
112+
if vld, err := respCr.IsValid(); !vld {
113+
log.Fatalf(invalidResp.Error()+" %+v"+" reason: %s", respCr, err)
120114
}
121-
case <-time.After(100 * time.Millisecond):
122-
cancel()
123-
log.Fatal("No iq response was received in time while creating node")
115+
if respCr.Error.Reason != "conflict" {
116+
log.Fatalf("%+v", respCr.Error.Text)
117+
}
118+
log.Println(respCr.Error.Text)
119+
} else {
120+
fmt.Print("successfully created channel")
124121
}
122+
case <-time.After(100 * time.Millisecond):
123+
cancel()
124+
log.Fatal("No iq response was received in time while creating node")
125125
}
126126
}
127127
}

backoff_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77

88
func TestDurationForAttempt_NoJitter(t *testing.T) {
99
b := backoff{Base: 25, NoJitter: true}
10-
bInMS := time.Duration(b.Base) * time.Millisecond
11-
if b.durationForAttempt(0) != bInMS {
12-
t.Errorf("incorrect default duration for attempt #0 (%d) = %d", b.durationForAttempt(0)/time.Millisecond, bInMS/time.Millisecond)
10+
bInMilli := time.Duration(b.Base) * time.Millisecond
11+
if b.durationForAttempt(0) != bInMilli {
12+
t.Errorf("incorrect default duration for attempt #0 (%d) = %d", b.durationForAttempt(0)/time.Millisecond, bInMilli/time.Millisecond)
1313
}
1414
var prevDuration, d time.Duration
1515
for i := 0; i < 10; i++ {

client_internal_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"bytes"
55
"encoding/xml"
66
"fmt"
7-
"gosrc.io/xmpp/stanza"
87
"strconv"
98
"testing"
109
"time"
10+
11+
"gosrc.io/xmpp/stanza"
1112
)
1213

1314
const (

cmd/fluuxmpp/send.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package main
22

33
import (
44
"bufio"
5-
"gosrc.io/xmpp/stanza"
65
"os"
76
"strings"
87
"sync"
98

9+
"gosrc.io/xmpp/stanza"
10+
1011
"github.com/bdlm/log"
1112
"github.com/spf13/cobra"
1213
"github.com/spf13/viper"

component.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
"encoding/xml"
88
"errors"
99
"fmt"
10-
"gosrc.io/xmpp/stanza"
1110
"io"
11+
12+
"gosrc.io/xmpp/stanza"
1213
)
1314

1415
type ComponentOptions struct {
@@ -178,9 +179,8 @@ func (c *Component) sendWithWriter(writer io.Writer, packet []byte) error {
178179
// The provided context should have a timeout to prevent the client from waiting
179180
// forever for an IQ result. For example:
180181
//
181-
// ctx, _ := context.WithTimeout(context.Background(), 30 * time.Second)
182-
// result := <- client.SendIQ(ctx, iq)
183-
//
182+
// ctx, _ := context.WithTimeout(context.Background(), 30 * time.Second)
183+
// result := <- client.SendIQ(ctx, iq)
184184
func (c *Component) SendIQ(ctx context.Context, iq *stanza.IQ) (chan stanza.IQ, error) {
185185
if iq.Attrs.Type != stanza.IQTypeSet && iq.Attrs.Type != stanza.IQTypeGet {
186186
return nil, ErrCanOnlySendGetOrSetIq

config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package xmpp
22

33
import (
4-
"gosrc.io/xmpp/stanza"
54
"os"
65
"time"
6+
7+
"gosrc.io/xmpp/stanza"
78
)
89

910
// Config & TransportConfiguration must not be modified after having been passed to NewClient. Any

qodana.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#-------------------------------------------------------------------------------#
2+
# Qodana analysis is configured by qodana.yaml file #
3+
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
4+
#-------------------------------------------------------------------------------#
5+
6+
#################################################################################
7+
# WARNING: Do not store sensitive information in this file, #
8+
# as its contents will be included in the Qodana report. #
9+
#################################################################################
10+
version: "1.0"
11+
12+
#Specify inspection profile for code analysis
13+
profile:
14+
name: qodana.starter
15+
16+
#Enable inspections
17+
#include:
18+
# - name: <SomeEnabledInspectionId>
19+
20+
#Disable inspections
21+
#exclude:
22+
# - name: <SomeDisabledInspectionId>
23+
# paths:
24+
# - <path/where/not/run/inspection>
25+
26+
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
27+
#bootstrap: sh ./prepare-qodana.sh
28+
29+
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
30+
#plugins:
31+
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
32+
33+
# Quality gate. Will fail the CI/CD pipeline if any condition is not met
34+
# severityThresholds - configures maximum thresholds for different problem severities
35+
# testCoverageThresholds - configures minimum code coverage on a whole project and newly added code
36+
# Code Coverage is available in Ultimate and Ultimate Plus plans
37+
#failureConditions:
38+
# severityThresholds:
39+
# any: 15
40+
# critical: 5
41+
# testCoverageThresholds:
42+
# fresh: 70
43+
# total: 50
44+
45+
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
46+
linter: jetbrains/qodana-go:2025.3

0 commit comments

Comments
 (0)