doc.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package stylecheck
  2. import "honnef.co/go/tools/lint"
  3. var Docs = map[string]*lint.Documentation{
  4. "ST1000": &lint.Documentation{
  5. Title: `Incorrect or missing package comment`,
  6. Text: `Packages must have a package comment that is formatted according to
  7. the guidelines laid out in
  8. https://github.com/golang/go/wiki/CodeReviewComments#package-comments.`,
  9. Since: "2019.1",
  10. NonDefault: true,
  11. },
  12. "ST1001": &lint.Documentation{
  13. Title: `Dot imports are discouraged`,
  14. Text: `Dot imports that aren't in external test packages are discouraged.
  15. The dot_import_whitelist option can be used to whitelist certain
  16. imports.
  17. Quoting Go Code Review Comments:
  18. The import . form can be useful in tests that, due to circular
  19. dependencies, cannot be made part of the package being tested:
  20. package foo_test
  21. import (
  22. "bar/testutil" // also imports "foo"
  23. . "foo"
  24. )
  25. In this case, the test file cannot be in package foo because it
  26. uses bar/testutil, which imports foo. So we use the 'import .'
  27. form to let the file pretend to be part of package foo even though
  28. it is not. Except for this one case, do not use import . in your
  29. programs. It makes the programs much harder to read because it is
  30. unclear whether a name like Quux is a top-level identifier in the
  31. current package or in an imported package.`,
  32. Since: "2019.1",
  33. Options: []string{"dot_import_whitelist"},
  34. },
  35. "ST1003": &lint.Documentation{
  36. Title: `Poorly chosen identifier`,
  37. Text: `Identifiers, such as variable and package names, follow certain rules.
  38. See the following links for details:
  39. - https://golang.org/doc/effective_go.html#package-names
  40. - https://golang.org/doc/effective_go.html#mixed-caps
  41. - https://github.com/golang/go/wiki/CodeReviewComments#initialisms
  42. - https://github.com/golang/go/wiki/CodeReviewComments#variable-names`,
  43. Since: "2019.1",
  44. NonDefault: true,
  45. Options: []string{"initialisms"},
  46. },
  47. "ST1005": &lint.Documentation{
  48. Title: `Incorrectly formatted error string`,
  49. Text: `Error strings follow a set of guidelines to ensure uniformity and good
  50. composability.
  51. Quoting Go Code Review Comments:
  52. Error strings should not be capitalized (unless beginning with
  53. proper nouns or acronyms) or end with punctuation, since they are
  54. usually printed following other context. That is, use
  55. fmt.Errorf("something bad") not fmt.Errorf("Something bad"), so
  56. that log.Printf("Reading %s: %v", filename, err) formats without a
  57. spurious capital letter mid-message.`,
  58. Since: "2019.1",
  59. },
  60. "ST1006": &lint.Documentation{
  61. Title: `Poorly chosen receiver name`,
  62. Text: `Quoting Go Code Review Comments:
  63. The name of a method's receiver should be a reflection of its
  64. identity; often a one or two letter abbreviation of its type
  65. suffices (such as "c" or "cl" for "Client"). Don't use generic
  66. names such as "me", "this" or "self", identifiers typical of
  67. object-oriented languages that place more emphasis on methods as
  68. opposed to functions. The name need not be as descriptive as that
  69. of a method argument, as its role is obvious and serves no
  70. documentary purpose. It can be very short as it will appear on
  71. almost every line of every method of the type; familiarity admits
  72. brevity. Be consistent, too: if you call the receiver "c" in one
  73. method, don't call it "cl" in another.`,
  74. Since: "2019.1",
  75. },
  76. "ST1008": &lint.Documentation{
  77. Title: `A function's error value should be its last return value`,
  78. Text: `A function's error value should be its last return value.`,
  79. Since: `2019.1`,
  80. },
  81. "ST1011": &lint.Documentation{
  82. Title: `Poorly chosen name for variable of type time.Duration`,
  83. Text: `time.Duration values represent an amount of time, which is represented
  84. as a count of nanoseconds. An expression like 5 * time.Microsecond
  85. yields the value 5000. It is therefore not appropriate to suffix a
  86. variable of type time.Duration with any time unit, such as Msec or
  87. Milli.`,
  88. Since: `2019.1`,
  89. },
  90. "ST1012": &lint.Documentation{
  91. Title: `Poorly chosen name for error variable`,
  92. Text: `Error variables that are part of an API should be called errFoo or
  93. ErrFoo.`,
  94. Since: "2019.1",
  95. },
  96. "ST1013": &lint.Documentation{
  97. Title: `Should use constants for HTTP error codes, not magic numbers`,
  98. Text: `HTTP has a tremendous number of status codes. While some of those are
  99. well known (200, 400, 404, 500), most of them are not. The net/http
  100. package provides constants for all status codes that are part of the
  101. various specifications. It is recommended to use these constants
  102. instead of hard-coding magic numbers, to vastly improve the
  103. readability of your code.`,
  104. Since: "2019.1",
  105. Options: []string{"http_status_code_whitelist"},
  106. },
  107. "ST1015": &lint.Documentation{
  108. Title: `A switch's default case should be the first or last case`,
  109. Since: "2019.1",
  110. },
  111. "ST1016": &lint.Documentation{
  112. Title: `Use consistent method receiver names`,
  113. Since: "2019.1",
  114. NonDefault: true,
  115. },
  116. "ST1017": &lint.Documentation{
  117. Title: `Don't use Yoda conditions`,
  118. Text: `Yoda conditions are conditions of the kind 'if 42 == x', where the
  119. literal is on the left side of the comparison. These are a common
  120. idiom in languages in which assignment is an expression, to avoid bugs
  121. of the kind 'if (x = 42)'. In Go, which doesn't allow for this kind of
  122. bug, we prefer the more idiomatic 'if x == 42'.`,
  123. Since: "2019.2",
  124. },
  125. "ST1018": &lint.Documentation{
  126. Title: `Avoid zero-width and control characters in string literals`,
  127. Since: "2019.2",
  128. },
  129. }