doc.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Package quickfix contains analyzes that implement code refactorings.
  2. // None of these analyzers produce diagnostics that have to be followed.
  3. // Most of the time, they only provide alternative ways of doing things,
  4. // requiring users to make informed decisions.
  5. //
  6. // None of these analyzes should fail a build, and they are likely useless in CI as a whole.
  7. package quickfix
  8. import "honnef.co/go/tools/analysis/lint"
  9. var Docs = lint.Markdownify(map[string]*lint.RawDocumentation{
  10. "QF1001": {
  11. Title: "Apply De Morgan's law",
  12. Since: "2021.1",
  13. Severity: lint.SeverityHint,
  14. },
  15. "QF1002": {
  16. Title: "Convert untagged switch to tagged switch",
  17. Text: `
  18. An untagged switch that compares a single variable against a series of
  19. values can be replaced with a tagged switch.`,
  20. Before: `
  21. switch {
  22. case x == 1 || x == 2, x == 3:
  23. ...
  24. case x == 4:
  25. ...
  26. default:
  27. ...
  28. }`,
  29. After: `
  30. switch x {
  31. case 1, 2, 3:
  32. ...
  33. case 4:
  34. ...
  35. default:
  36. ...
  37. }`,
  38. Since: "2021.1",
  39. Severity: lint.SeverityHint,
  40. },
  41. "QF1003": {
  42. Title: "Convert if/else-if chain to tagged switch",
  43. Text: `
  44. A series of if/else-if checks comparing the same variable against
  45. values can be replaced with a tagged switch.`,
  46. Before: `
  47. if x == 1 || x == 2 {
  48. ...
  49. } else if x == 3 {
  50. ...
  51. } else {
  52. ...
  53. }`,
  54. After: `
  55. switch x {
  56. case 1, 2:
  57. ...
  58. case 3:
  59. ...
  60. default:
  61. ...
  62. }`,
  63. Since: "2021.1",
  64. Severity: lint.SeverityInfo,
  65. },
  66. "QF1004": {
  67. Title: `Use \'strings.ReplaceAll\' instead of \'strings.Replace\' with \'n == -1\'`,
  68. Since: "2021.1",
  69. Severity: lint.SeverityHint,
  70. },
  71. "QF1005": {
  72. Title: `Expand call to \'math.Pow\'`,
  73. Text: `Some uses of \'math.Pow\' can be simplified to basic multiplication.`,
  74. Before: `math.Pow(x, 2)`,
  75. After: `x * x`,
  76. Since: "2021.1",
  77. Severity: lint.SeverityHint,
  78. },
  79. "QF1006": {
  80. Title: `Lift \'if\'+\'break\' into loop condition`,
  81. Before: `
  82. for {
  83. if done {
  84. break
  85. }
  86. ...
  87. }`,
  88. After: `
  89. for !done {
  90. ...
  91. }`,
  92. Since: "2021.1",
  93. Severity: lint.SeverityHint,
  94. },
  95. "QF1007": {
  96. Title: "Merge conditional assignment into variable declaration",
  97. Before: `
  98. x := false
  99. if someCondition {
  100. x = true
  101. }`,
  102. After: `x := someCondition`,
  103. Since: "2021.1",
  104. Severity: lint.SeverityHint,
  105. },
  106. "QF1008": {
  107. Title: "Omit embedded fields from selector expression",
  108. Since: "2021.1",
  109. Severity: lint.SeverityHint,
  110. },
  111. "QF1009": {
  112. Title: `Use \'time.Time.Equal\' instead of \'==\' operator`,
  113. Since: "2021.1",
  114. Severity: lint.SeverityInfo,
  115. },
  116. "QF1010": {
  117. Title: "Convert slice of bytes to string when printing it",
  118. Since: "2021.1",
  119. Severity: lint.SeverityHint,
  120. },
  121. "QF1011": {
  122. Title: "Omit redundant type from variable declaration",
  123. Since: "2021.1",
  124. Severity: lint.SeverityHint,
  125. },
  126. "QF1012": {
  127. Title: `Use \'fmt.Fprintf(x, ...)\' instead of \'x.Write(fmt.Sprintf(...))\'`,
  128. Since: "2022.1",
  129. Severity: lint.SeverityHint,
  130. },
  131. })