Skip to content

Commit d20cf3c

Browse files
committed
lint: fix issues
Fixes mostly missing periods at the end of sentences (in comments of globals) and misspellings. It also adds t.Parallel() to test files (where appropriate).
1 parent de8d9df commit d20cf3c

File tree

15 files changed

+124
-70
lines changed

15 files changed

+124
-70
lines changed

at.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (d *Device) sendInteractive(part1, part2 string, prompt byte) (err error) {
129129
exitInteractive()
130130
return
131131
}
132-
return
132+
return nil
133133
}
134134

135135
// sanityCheck checks whether ports are opened and (if requested) that the initialization
@@ -217,7 +217,7 @@ func (d *Device) Send(req string) (reply string, err error) {
217217
t.Reset(Timeout)
218218
}
219219
}
220-
return
220+
return reply, err
221221
}
222222

223223
// Watch starts a monitoring process that will wait for events
@@ -357,7 +357,7 @@ func (d *Device) handleReport(str string) (err error) {
357357
return errors.New("at: unknown report: " + str)
358358
}
359359
}
360-
return
360+
return nil
361361
}
362362

363363
// Open is used to open serial ports of the device. This should be used first.

commands.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (b *bootHandshakeReport) Parse(str string) (err error) {
167167
return
168168
}
169169

170-
// Ussd type represents the USSD query string
170+
// Ussd type represents the USSD query string.
171171
type Ussd string
172172

173173
// Encode converts the query string into bytes according to the
@@ -278,7 +278,7 @@ func (p *DefaultProfile) CNMI(mode, mt, bm, ds, bfr int) (err error) {
278278
}
279279

280280
// CMGF sends AT+CMGF with the given value to the device. It toggles
281-
// the mode of message handling betwen PDU and TEXT.
281+
// the mode of message handling between PDU and TEXT.
282282
//
283283
// Note, that the at package works only in PDU mode.
284284
func (p *DefaultProfile) CMGF(text bool) (err error) {
@@ -292,7 +292,7 @@ func (p *DefaultProfile) CMGF(text bool) (err error) {
292292
}
293293

294294
// CMGL sends AT+CMGL with the given filtering flag to the device and then parses
295-
// the list of received messages that match ther filter. See MessageFlags for the
295+
// the list of received messages that match their filter. See MessageFlags for the
296296
// list of supported filters.
297297
func (p *DefaultProfile) CMGL(flag Opt) (octets map[uint64][]byte, err error) {
298298
req := fmt.Sprintf(`AT+CMGL=%d`, flag.ID)
@@ -381,7 +381,7 @@ func (s *SystemInfoReport) Parse(str string) (err error) {
381381
if n, err := strconv.ParseUint(str, 10, 8); err != nil {
382382
return err
383383
} else if opt := resolver(int(n)); opt == UnknownOpt {
384-
return errors.New("resolver: unknwon opt")
384+
return errors.New("resolver: unknown opt")
385385
} else {
386386
*field = opt
387387
return nil
@@ -406,7 +406,7 @@ func (s *SystemInfoReport) Parse(str string) (err error) {
406406
if err = fetch(fields[6], &s.SystemSubmode, SystemSubmodes.Resolve); err != nil {
407407
return ErrParseReport
408408
}
409-
return
409+
return nil
410410
}
411411

412412
// SYSINFO sends AT^SYSINFO to the device and parses the output.
@@ -421,7 +421,7 @@ func (p *DefaultProfile) SYSINFO() (info *SystemInfoReport, err error) {
421421
}
422422

423423
// COPS sends AT+COPS to the device with parameters that define autosearch and
424-
// the operator's name representation. The default represenation is numerical.
424+
// the operator's name representation. The default representation is numerical.
425425
func (p *DefaultProfile) COPS(auto bool, text bool) (err error) {
426426
var a, t int
427427
if !auto {

doc.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
// Package at is a framework for communication with AT-compatible devices like Huawei modems via serial port.
2-
// Currently this package is well-suited for Huawei devices and since AT-commands set may vary from device
3-
// to device, sometimes you'll be forced to implement some logic by yourself.
1+
// Package at is a framework for communication with AT-compatible devices
2+
// like Huawei modems via serial port. Currently this package is well-suited
3+
// for Huawei devices and since AT-commands set may vary from device to
4+
// device, sometimes you'll be forced to implement some logic by yourself.
45
//
56
// Framework
67
//
7-
// This framework includes facilities for device monitoring, sending and receiving AT-commands, encoding and decoding SMS
8-
// messages from or to PDU octet representation (as specified in 3GPP TS 23.040). An example of incoming SMS monitor application is given.
8+
// This framework includes facilities for device monitoring, sending and
9+
// receiving AT-commands, encoding and decoding SMS messages from or to PDU
10+
// octet representation (as specified in 3GPP TS 23.040). An example of
11+
// incoming SMS monitor application is given.
912
//
1013
// Device-specific config
1114
//
12-
// In order to introduce your own logic (i.e. custom modem Init function), you should derive your profile from
13-
// the default DeviceProfile and override its methods.
15+
// In order to introduce your own logic (i.e. custom modem Init function),
16+
// you should derive your profile from the default DeviceProfile and
17+
// override its methods.
1418
//
1519
// About
1620
//

opts.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ var UnknownOpt = Opt{ID: -1, Description: "-"}
2424
// UnknownStringOpt represents a string option that was parsed incorrectly or was not parsed at all.
2525
var UnknownStringOpt = StringOpt{ID: "nil", Description: "Unknown"}
2626

27-
// KillCmd is an artifical AT command that may be successfully sent to device in order
28-
// to emulate the responce from it. In other words, if a connection with device stalled and
27+
// KillCmd is an artificial AT command that may be successfully sent to device in order
28+
// to emulate the response from it. In other words, if a connection with device stalled and
2929
// no bytes could be read, then this command is used to read something and then close the connection.
3030
const KillCmd = "AT_KILL"
3131

3232
// NoopCmd is like a ping command that signals that the device is responsive.
3333
const NoopCmd = "AT"
3434

35-
type optMap map[int]Opt
36-
type stringOpts []StringOpt
35+
type (
36+
optMap map[int]Opt
37+
stringOpts []StringOpt
38+
)
3739

3840
func (o optMap) Resolve(id int) Opt {
3941
if opt, ok := o[id]; ok {

opts_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ import (
88

99
// Test the field access for an opt.
1010
func TestOpt(t *testing.T) {
11+
t.Parallel()
12+
1113
opt := ServiceStates.Restricted
1214
assert.Equal(t, 1, opt.ID)
1315
assert.Equal(t, "Restricted service", opt.Description)
1416
}
1517

1618
// Test the resolve function of an opt.
1719
func TestResolve(t *testing.T) {
20+
t.Parallel()
21+
1822
opt := ServiceStates.Restricted
1923
assert.Equal(t, opt, ServiceStates.Resolve(1))
2024
}

pdu/7bit.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ import (
66
"fmt"
77
)
88

9-
// Esc code.
10-
const Esc byte = 0x1B
11-
12-
// Ctrl+Z code.
13-
const Sub byte = 0x1A
14-
15-
// <CR> code.
16-
const CR byte = 0x0D
9+
const (
10+
Esc byte = 0x1B // Esc code.
11+
Sub byte = 0x1A // Ctrl+Z code.
12+
CR byte = 0x0D // <CR> code.
13+
)
1714

18-
var crcr = []byte{CR, CR}
19-
var cr = []byte{CR}
15+
var (
16+
crcr = []byte{CR, CR}
17+
cr = []byte{CR}
18+
)
2019

2120
const (
2221
max byte = 0x7F
@@ -105,12 +104,12 @@ func pack7Bit(raw7 []byte) []byte {
105104
// N.B. in order to not confuse 7 zero-bits with @
106105
// <CR> code is added to the packed bits.
107106
if 8-bit == 7 {
108-
oct, bit = pack(pack7, CR, oct, bit)
107+
pack(pack7, CR, oct, bit)
109108
} else if bit == 0 && b == CR {
110109
// and if data ends with <CR> on the octet boundary,
111110
// then we add an additional octet with <CR>. See (3GPP TS 23.038).
112111
pack7 = append(pack7, 0x00)
113-
oct, bit = pack(pack7, CR, oct, bit)
112+
pack(pack7, CR, oct, bit)
114113
}
115114
return pack7
116115
}
@@ -204,7 +203,7 @@ func (rt *runeTable) Rune(idx int) rune {
204203
return unknown
205204
}
206205

207-
// Thanks, Jeroen @ Mobile Tidings
206+
// Thanks, Jeroen @ Mobile Tidings.
208207
var gsmTable = runeTable{
209208
/* 0x00 */ 0x0040, /* COMMERCIAL AT */
210209
/* 0x01 */ 0x00A3, /* POUND SIGN */

pdu/7bit_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
)
1010

1111
func TestEncode7Bit(t *testing.T) {
12-
data := []struct {
12+
t.Parallel()
13+
14+
testcases := []struct {
1315
str string
1416
exp []byte
1517
}{
@@ -18,13 +20,15 @@ func TestEncode7Bit(t *testing.T) {
1820
{"AAAAAAAAAAAAAAB", util.MustBytes("C16030180C0683C16030180C0A1B")},
1921
{"height of eifel", util.MustBytes("E872FA8CA683DE6650396D2EB31B")},
2022
}
21-
for _, d := range data {
22-
assert.Equal(t, d.exp, Encode7Bit(d.str))
23+
for _, tc := range testcases {
24+
assert.Equal(t, tc.exp, Encode7Bit(tc.str))
2325
}
2426
}
2527

2628
func TestDecode7Bit(t *testing.T) {
27-
data := []struct {
29+
t.Parallel()
30+
31+
testcases := []struct {
2832
exp string
2933
pack7 []byte
3034
}{
@@ -34,21 +38,25 @@ func TestDecode7Bit(t *testing.T) {
3438
{"AAAAAAAAAAAAAAB", util.MustBytes("C16030180C0683C16030180C0A1B")},
3539
{"height of eifel", util.MustBytes("E872FA8CA683DE6650396D2EB31B")},
3640
}
37-
for _, d := range data {
38-
log.Println(displayPack(d.pack7))
39-
out, err := Decode7Bit(d.pack7)
41+
for _, tc := range testcases {
42+
log.Println(displayPack(tc.pack7))
43+
out, err := Decode7Bit(tc.pack7)
4044
assert.NoError(t, err)
41-
assert.Equal(t, d.exp, out)
45+
assert.Equal(t, tc.exp, out)
4246
}
4347
}
4448

4549
func TestPack7Bit(t *testing.T) {
50+
t.Parallel()
51+
4652
raw7 := []byte{Esc, 0x3c, Esc, 0x3e}
4753
exp := []byte{0x1b, 0xde, 0xc6, 0x7}
4854
assert.Equal(t, exp, pack7Bit(raw7))
4955
}
5056

5157
func TestUnpack7Bit(t *testing.T) {
58+
t.Parallel()
59+
5260
pack7 := []byte{0x1b, 0xde, 0xc6, 0x7}
5361
exp := []byte{Esc, 0x3c, Esc, 0x3e}
5462
assert.Equal(t, exp, unpack7Bit(pack7))

pdu/doc.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
// Package pdu implementes dataencoding schemes described in 3GPP TS 23.040. Such schemes include: GSM 7-Bit text encoding,
2-
// UCS2 (UTF-16) text encoding, semi-octet encoding of integers.
1+
// Package pdu implements data encoding schemes described in 3GPP TS 23.040.
2+
//
3+
// Such schemes include:
4+
// - GSM 7-Bit text encoding,
5+
// - UCS2 (UTF-16) text encoding, and
6+
// - semi-octet encoding of integers.
37
package pdu

pdu/semi_octet.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ package pdu
22

33
import "fmt"
44

5-
// Swap semi-octets in octet
5+
// Swap semi-octets in octet.
66
func Swap(octet byte) byte {
77
return (octet << 4) | (octet >> 4 & 0x0F)
88
}
99

10-
// Encode to semi-octets
10+
// Encode to semi-octets.
1111
func Encode(value int) byte {
1212
lo := byte(value % 10)
1313
hi := byte((value % 100) / 10)
1414
return hi<<4 | lo
1515
}
1616

17-
// Decode form semi-octets
17+
// Decode form semi-octets.
1818
func Decode(octet byte) int {
1919
lo := octet & 0x0F
2020
hi := octet >> 4 & 0x0F

pdu/semi_octet_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ import (
77
)
88

99
func TestEncodeSemi(t *testing.T) {
10-
out := EncodeSemi(14, 06, 26, 21, 36, 30, 16)
10+
t.Parallel()
11+
12+
out := EncodeSemi(14, 6, 26, 21, 36, 30, 16)
1113
exp := []byte{0x41, 0x60, 0x62, 0x12, 0x63, 0x03, 0x61}
1214
assert.Equal(t, exp, out)
1315
}
1416

1517
func TestDecodeSemi(t *testing.T) {
18+
t.Parallel()
19+
1620
oct := []byte{0x41, 0x60, 0x62, 0x12, 0x63, 0x03, 0x61}
1721
out := DecodeSemi(oct)
18-
exp := []int{14, 06, 26, 21, 36, 30, 16}
22+
exp := []int{14, 6, 26, 21, 36, 30, 16}
1923
assert.Equal(t, exp, out)
2024
}

0 commit comments

Comments
 (0)