Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.0.1-2020.1.5 / simple / doc.go
1 package simple
2
3 import "honnef.co/go/tools/lint"
4
5 var Docs = map[string]*lint.Documentation{
6         "S1000": {
7                 Title: `Use plain channel send or receive instead of single-case select`,
8                 Text: `Select statements with a single case can be replaced with a simple
9 send or receive.
10
11 Before:
12
13     select {
14     case x := <-ch:
15         fmt.Println(x)
16     }
17
18 After:
19
20     x := <-ch
21     fmt.Println(x)`,
22                 Since: "2017.1",
23         },
24
25         "S1001": {
26                 Title: `Replace for loop with call to copy`,
27                 Text: `Use copy() for copying elements from one slice to another.
28
29 Before:
30
31     for i, x := range src {
32         dst[i] = x
33     }
34
35 After:
36
37     copy(dst, src)`,
38                 Since: "2017.1",
39         },
40
41         "S1002": {
42                 Title: `Omit comparison with boolean constant`,
43                 Text: `Before:
44
45     if x == true {}
46
47 After:
48
49     if x {}`,
50                 Since: "2017.1",
51         },
52
53         "S1003": {
54                 Title: `Replace call to strings.Index with strings.Contains`,
55                 Text: `Before:
56
57     if strings.Index(x, y) != -1 {}
58
59 After:
60
61     if strings.Contains(x, y) {}`,
62                 Since: "2017.1",
63         },
64
65         "S1004": {
66                 Title: `Replace call to bytes.Compare with bytes.Equal`,
67                 Text: `Before:
68
69     if bytes.Compare(x, y) == 0 {}
70
71 After:
72
73     if bytes.Equal(x, y) {}`,
74                 Since: "2017.1",
75         },
76
77         "S1005": {
78                 Title: `Drop unnecessary use of the blank identifier`,
79                 Text: `In many cases, assigning to the blank identifier is unnecessary.
80
81 Before:
82
83     for _ = range s {}
84     x, _ = someMap[key]
85     _ = <-ch
86
87 After:
88
89     for range s{}
90     x = someMap[key]
91     <-ch`,
92                 Since: "2017.1",
93         },
94
95         "S1006": {
96                 Title: `Use for { ... } for infinite loops`,
97                 Text:  `For infinite loops, using for { ... } is the most idiomatic choice.`,
98                 Since: "2017.1",
99         },
100
101         "S1007": {
102                 Title: `Simplify regular expression by using raw string literal`,
103                 Text: `Raw string literals use ` + "`" + ` instead of " and do not support
104 any escape sequences. This means that the backslash (\) can be used
105 freely, without the need of escaping.
106
107 Since regular expressions have their own escape sequences, raw strings
108 can improve their readability.
109
110 Before:
111
112     regexp.Compile("\\A(\\w+) profile: total \\d+\\n\\z")
113
114 After:
115
116     regexp.Compile(` + "`" + `\A(\w+) profile: total \d+\n\z` + "`" + `)`,
117                 Since: "2017.1",
118         },
119
120         "S1008": {
121                 Title: `Simplify returning boolean expression`,
122                 Text: `Before:
123
124     if <expr> {
125         return true
126     }
127     return false
128
129 After:
130
131     return <expr>`,
132                 Since: "2017.1",
133         },
134
135         "S1009": {
136                 Title: `Omit redundant nil check on slices`,
137                 Text: `The len function is defined for all slices, even nil ones, which have
138 a length of zero. It is not necessary to check if a slice is not nil
139 before checking that its length is not zero.
140
141 Before:
142
143     if x != nil && len(x) != 0 {}
144
145 After:
146
147     if len(x) != 0 {}`,
148                 Since: "2017.1",
149         },
150
151         "S1010": {
152                 Title: `Omit default slice index`,
153                 Text: `When slicing, the second index defaults to the length of the value,
154 making s[n:len(s)] and s[n:] equivalent.`,
155                 Since: "2017.1",
156         },
157
158         "S1011": {
159                 Title: `Use a single append to concatenate two slices`,
160                 Text: `Before:
161
162     for _, e := range y {
163         x = append(x, e)
164     }
165
166 After:
167
168     x = append(x, y...)`,
169                 Since: "2017.1",
170         },
171
172         "S1012": {
173                 Title: `Replace time.Now().Sub(x) with time.Since(x)`,
174                 Text: `The time.Since helper has the same effect as using time.Now().Sub(x)
175 but is easier to read.
176
177 Before:
178
179     time.Now().Sub(x)
180
181 After:
182
183     time.Since(x)`,
184                 Since: "2017.1",
185         },
186
187         "S1016": {
188                 Title: `Use a type conversion instead of manually copying struct fields`,
189                 Text: `Two struct types with identical fields can be converted between each
190 other. In older versions of Go, the fields had to have identical
191 struct tags. Since Go 1.8, however, struct tags are ignored during
192 conversions. It is thus not necessary to manually copy every field
193 individually.
194
195 Before:
196
197     var x T1
198     y := T2{
199         Field1: x.Field1,
200         Field2: x.Field2,
201     }
202
203 After:
204
205     var x T1
206     y := T2(x)`,
207                 Since: "2017.1",
208         },
209
210         "S1017": {
211                 Title: `Replace manual trimming with strings.TrimPrefix`,
212                 Text: `Instead of using strings.HasPrefix and manual slicing, use the
213 strings.TrimPrefix function. If the string doesn't start with the
214 prefix, the original string will be returned. Using strings.TrimPrefix
215 reduces complexity, and avoids common bugs, such as off-by-one
216 mistakes.
217
218 Before:
219
220     if strings.HasPrefix(str, prefix) {
221         str = str[len(prefix):]
222     }
223
224 After:
225
226     str = strings.TrimPrefix(str, prefix)`,
227                 Since: "2017.1",
228         },
229
230         "S1018": {
231                 Title: `Use copy for sliding elements`,
232                 Text: `copy() permits using the same source and destination slice, even with
233 overlapping ranges. This makes it ideal for sliding elements in a
234 slice.
235
236 Before:
237
238     for i := 0; i < n; i++ {
239         bs[i] = bs[offset+i]
240     }
241
242 After:
243
244     copy(bs[:n], bs[offset:])`,
245                 Since: "2017.1",
246         },
247
248         "S1019": {
249                 Title: `Simplify make call by omitting redundant arguments`,
250                 Text: `The make function has default values for the length and capacity
251 arguments. For channels and maps, the length defaults to zero.
252 Additionally, for slices the capacity defaults to the length.`,
253                 Since: "2017.1",
254         },
255
256         "S1020": {
257                 Title: `Omit redundant nil check in type assertion`,
258                 Text: `Before:
259
260     if _, ok := i.(T); ok && i != nil {}
261
262 After:
263
264     if _, ok := i.(T); ok {}`,
265                 Since: "2017.1",
266         },
267
268         "S1021": {
269                 Title: `Merge variable declaration and assignment`,
270                 Text: `Before:
271
272     var x uint
273     x = 1
274
275 After:
276
277     var x uint = 1`,
278                 Since: "2017.1",
279         },
280
281         "S1023": {
282                 Title: `Omit redundant control flow`,
283                 Text: `Functions that have no return value do not need a return statement as
284 the final statement of the function.
285
286 Switches in Go do not have automatic fallthrough, unlike languages
287 like C. It is not necessary to have a break statement as the final
288 statement in a case block.`,
289                 Since: "2017.1",
290         },
291
292         "S1024": {
293                 Title: `Replace x.Sub(time.Now()) with time.Until(x)`,
294                 Text: `The time.Until helper has the same effect as using x.Sub(time.Now())
295 but is easier to read.
296
297 Before:
298
299     x.Sub(time.Now())
300
301 After:
302
303     time.Until(x)`,
304                 Since: "2017.1",
305         },
306
307         "S1025": {
308                 Title: `Don't use fmt.Sprintf("%s", x) unnecessarily`,
309                 Text: `In many instances, there are easier and more efficient ways of getting
310 a value's string representation. Whenever a value's underlying type is
311 a string already, or the type has a String method, they should be used
312 directly.
313
314 Given the following shared definitions
315
316     type T1 string
317     type T2 int
318
319     func (T2) String() string { return "Hello, world" }
320
321     var x string
322     var y T1
323     var z T2
324
325 we can simplify the following
326
327     fmt.Sprintf("%s", x)
328     fmt.Sprintf("%s", y)
329     fmt.Sprintf("%s", z)
330
331 to
332
333     x
334     string(y)
335     z.String()`,
336                 Since: "2017.1",
337         },
338
339         "S1028": {
340                 Title: `Simplify error construction with fmt.Errorf`,
341                 Text: `Before:
342
343     errors.New(fmt.Sprintf(...))
344
345 After:
346
347     fmt.Errorf(...)`,
348                 Since: "2017.1",
349         },
350
351         "S1029": {
352                 Title: `Range over the string directly`,
353                 Text: `Ranging over a string will yield byte offsets and runes. If the offset
354 isn't used, this is functionally equivalent to converting the string
355 to a slice of runes and ranging over that. Ranging directly over the
356 string will be more performant, however, as it avoids allocating a new
357 slice, the size of which depends on the length of the string.
358
359 Before:
360
361     for _, r := range []rune(s) {}
362
363 After:
364
365     for _, r := range s {}`,
366                 Since: "2017.1",
367         },
368
369         "S1030": {
370                 Title: `Use bytes.Buffer.String or bytes.Buffer.Bytes`,
371                 Text: `bytes.Buffer has both a String and a Bytes method. It is never
372 necessary to use string(buf.Bytes()) or []byte(buf.String()) – simply
373 use the other method.`,
374                 Since: "2017.1",
375         },
376
377         "S1031": {
378                 Title: `Omit redundant nil check around loop`,
379                 Text: `You can use range on nil slices and maps, the loop will simply never
380 execute. This makes an additional nil check around the loop
381 unnecessary.
382
383 Before:
384
385     if s != nil {
386         for _, x := range s {
387             ...
388         }
389     }
390
391 After:
392
393     for _, x := range s {
394         ...
395     }`,
396                 Since: "2017.1",
397         },
398
399         "S1032": {
400                 Title: `Use sort.Ints(x), sort.Float64s(x), and sort.Strings(x)`,
401                 Text: `The sort.Ints, sort.Float64s and sort.Strings functions are easier to
402 read than sort.Sort(sort.IntSlice(x)), sort.Sort(sort.Float64Slice(x))
403 and sort.Sort(sort.StringSlice(x)).
404
405 Before:
406
407     sort.Sort(sort.StringSlice(x))
408
409 After:
410
411     sort.Strings(x)`,
412                 Since: "2019.1",
413         },
414
415         "S1033": {
416                 Title: `Unnecessary guard around call to delete`,
417                 Text:  `Calling delete on a nil map is a no-op.`,
418                 Since: "2019.2",
419         },
420
421         "S1034": {
422                 Title: `Use result of type assertion to simplify cases`,
423                 Since: "2019.2",
424         },
425
426         "S1035": {
427                 Title: `Redundant call to net/http.CanonicalHeaderKey in method call on net/http.Header`,
428                 Text: `The methods on net/http.Header, namely Add, Del, Get and Set, already
429 canonicalize the given header name.`,
430                 Since: "2020.1",
431         },
432
433         "S1036": {
434                 Title: `Unnecessary guard around map access`,
435
436                 Text: `When accessing a map key that doesn't exist yet, one
437 receives a zero value. Often, the zero value is a suitable value, for example when using append or doing integer math.
438
439 The following
440
441     if _, ok := m["foo"]; ok {
442         m["foo"] = append(m["foo"], "bar")
443     } else {
444         m["foo"] = []string{"bar"}
445     }
446
447 can be simplified to
448
449     m["foo"] = append(m["foo"], "bar")
450
451 and
452
453     if _, ok := m2["k"]; ok {
454         m2["k"] += 4
455     } else {
456         m2["k"] = 4
457     }
458
459 can be simplified to
460
461     m["k"] += 4
462 `,
463                 Since: "2020.1",
464         },
465
466         "S1037": {
467                 Title: `Elaborate way of sleeping`,
468                 Text: `Using a select statement with a single case receiving
469 from the result of time.After is a very elaborate way of sleeping that
470 can much simpler be expressed with a simple call to time.Sleep.`,
471                 Since: "2020.1",
472         },
473
474         "S1038": {
475                 Title: "Unnecessarily complex way of printing formatted string",
476                 Text:  `Instead of using fmt.Print(fmt.Sprintf(...)), one can use fmt.Printf(...).`,
477                 Since: "2020.1",
478         },
479
480         "S1039": {
481                 Title: "Unnecessary use of fmt.Sprint",
482                 Text:  `Calling fmt.Sprint with a single string argument is unnecessary and identical to using the string directly.`,
483                 Since: "2020.1",
484         },
485 }