diff --git a/cmd/makedocs/main.go b/cmd/makedocs/main.go index 671e48a55..318d370b2 100644 --- a/cmd/makedocs/main.go +++ b/cmd/makedocs/main.go @@ -16,9 +16,12 @@ const ( ) func main() { - tmpl := template.Must(template.ParseFiles(templatesPath + "overview.md.tmpl")) + tmpl := parseTemplate( + "overview.md.tmpl", + "checker_tr.partial.tmpl") + buf := bytes.Buffer{} - err := tmpl.Execute(&buf, struct { + err := tmpl.ExecuteTemplate(&buf, "overview", struct { Checkers []*lintpack.CheckerInfo }{ Checkers: lintpack.GetCheckersInfo(), @@ -30,3 +33,11 @@ func main() { log.Fatalf("write output file: %v", err) } } + +func parseTemplate(names ...string) *template.Template { + paths := make([]string, len(names)) + for i := range names { + paths[i] = templatesPath + names[i] + } + return template.Must(template.ParseFiles(paths...)) +} diff --git a/docs/overview.md b/docs/overview.md index 7efadfd44..fb8302f99 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -4,253 +4,356 @@ This page describes checks supported by [go-critic](https://github.com/go-critic [//]: # (This is generated file, please don't edit it yourself.) -## Checkers: +## Checkers + +* :heavy_check_mark: checker is enabled by default. +* :white_check_mark: checker is disabled by default. + +### Checkers from the "diagnostic" group + +Diagnostics try to find programming errors in the code. +They also detect code that may be correct, but looks suspicious. + +> All diagnostics are enabled by default (unless it has "experimental" tag). - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name Short description
appendAssignDetects suspicious append result assignments
appendCombineDetects `append` chains to the same slice that can be done in a single `append` call
argOrderDetects suspicious arguments order
assignOpDetects assignments that can be simplified by using assignment operators
badCondDetects suspicious condition expressions
boolExprSimplifyDetects bool expressions that can be simplified
builtinShadowDetects when predeclared identifiers shadowed in assignments
captLocalDetects capitalized names for local variables
caseOrderDetects erroneous case order inside switch statements
codegenCommentDetects malformed 'code generated' file comments
commentFormattingDetects comments with non-idiomatic formatting
commentedOutCodeDetects commented-out code inside function bodies
commentedOutImportDetects commented-out imports
defaultCaseOrderDetects when default case in switch isn't on 1st or last position
deprecatedCommentDetects malformed 'deprecated' doc-comments
docStubDetects comments that silence go lint complaints about doc-comment
dupArgDetects suspicious duplicated arguments
dupBranchBodyDetects duplicated branch bodies inside conditional statements
dupCaseDetects duplicated case clauses inside switch statements
dupSubExprDetects suspicious duplicated sub-expressions
elseifDetects else with nested if statement that can be replaced with else-if
emptyFallthroughDetects fallthrough that can be avoided by using multi case values
emptyStringTestDetects empty string checks that can be written more idiomatically
equalFoldDetects unoptimal strings/bytes case-insensitive comparison
exitAfterDeferDetects calls to exit/fatal inside functions that use defer
flagDerefDetects immediate dereferencing of `flag` package pointers
flagNameDetects flag names with whitespace
hexLiteralDetects hex literals that have mixed case letter digits
hugeParamDetects params that incur excessive amount of copying
ifElseChainDetects repeated if-else statements and suggests to replace them with switch statement
importShadowDetects when imported package names shadowed in the assignments
indexAllocDetects strings.Index calls that may cause unwanted allocs
initClauseDetects non-assignment statements inside if/switch init clause
methodExprCallDetects method expression call that can be replaced with a method call
nestingReduceFinds where nesting level could be reduced
nilValReturnDetects return statements those results evaluate to nil
offBy1Detects various off-by-one kind of errors
paramTypeCombineDetects if function parameters could be combined by type and suggest the way to do it
ptrToRefParamDetects input and output parameters that have a type of pointer to referential type
rangeExprCopyDetects expensive copies of `for` loop range expressions
rangeValCopyDetects loops that copy big objects during each iteration
regexpMustDetects `regexp.Compile*` that can be replaced with `regexp.MustCompile*`
singleCaseSwitchDetects switch statements that could be better written as if statement
sloppyLenDetects usage of `len` when result is obvious or doesn't make sense
sloppyReassignDetects suspicious/confusing re-assignments
stringXbytesDetects redundant conversions between string and []byte
switchTrueDetects switch-over-bool statements that use explicit `true` tag value
typeAssertChainDetects repeated type assertions and suggests to replace them with type switch statement
typeSwitchVarDetects type switches that can benefit from type guard clause with variable
typeUnparenDetects unneded parenthesis inside type expressions and suggests to remove them
underefDetects dereference expressions that can be omitted
unlabelStmtDetects redundant statement labels
unlambdaDetects function literals that can be simplified
unnamedResultDetects unnamed results that may benefit from names
unnecessaryBlockDetects unnecessary braced statement blocks
unsliceDetects slice expressions that can be simplified to sliced expression itself
valSwapDetects value swapping code that are not using parallel assignment
weakCondDetects conditions that are unsafe due to not being exhaustive
wrapperFuncDetects function calls that can be replaced with convenience wrappers
yodaStyleExprDetects Yoda style expressions and suggests to replace them
:heavy_check_mark: + appendAssign + Detects suspicious append result assignments
:white_check_mark: + argOrder + Detects suspicious arguments order
:white_check_mark: + badCond + Detects suspicious condition expressions
:heavy_check_mark: + caseOrder + Detects erroneous case order inside switch statements
:white_check_mark: + codegenComment + Detects malformed 'code generated' file comments
:white_check_mark: + commentedOutCode + Detects commented-out code inside function bodies
:white_check_mark: + deprecatedComment + Detects malformed 'deprecated' doc-comments
:heavy_check_mark: + dupArg + Detects suspicious duplicated arguments
:white_check_mark: + dupAssign + Detects suspicious re-assignments
:heavy_check_mark: + dupBranchBody + Detects duplicated branch bodies inside conditional statements
:heavy_check_mark: + dupCase + Detects duplicated case clauses inside switch statements
:heavy_check_mark: + dupSubExpr + Detects suspicious duplicated sub-expressions
:white_check_mark: + exitAfterDefer + Detects calls to exit/fatal inside functions that use defer
:heavy_check_mark: + flagDeref + Detects immediate dereferencing of `flag` package pointers
:white_check_mark: + flagName + Detects flag names with whitespace
:white_check_mark: + nilValReturn + Detects return statements those results evaluate to nil
:white_check_mark: + offBy1 + Detects various off-by-one kind of errors
:white_check_mark: + sloppyReassign + Detects suspicious/confusing re-assignments
:white_check_mark: + weakCond + Detects conditions that are unsafe due to not being exhaustive
+ +### Checkers from the "style" group + +Style checks suggest replacing some form of expression/statement +with another one that is considered more idiomatic or simple. + +> Only non-opinionated style checks are enabled by default. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameShort description
:heavy_check_mark: + assignOp + Detects assignments that can be simplified by using assignment operators
:white_check_mark: + boolExprSimplify + Detects bool expressions that can be simplified
:white_check_mark: + builtinShadow + Detects when predeclared identifiers shadowed in assignments
:heavy_check_mark: + captLocal + Detects capitalized names for local variables
:white_check_mark: + commentFormatting + Detects comments with non-idiomatic formatting
:white_check_mark: + commentedOutImport + Detects commented-out imports
:heavy_check_mark: + defaultCaseOrder + Detects when default case in switch isn't on 1st or last position
:white_check_mark: + docStub + Detects comments that silence go lint complaints about doc-comment
:heavy_check_mark: + elseif + Detects else with nested if statement that can be replaced with else-if
:white_check_mark: + emptyFallthrough + Detects fallthrough that can be avoided by using multi case values
:white_check_mark: + emptyStringTest + Detects empty string checks that can be written more idiomatically
:white_check_mark: + hexLiteral + Detects hex literals that have mixed case letter digits
:heavy_check_mark: + ifElseChain + Detects repeated if-else statements and suggests to replace them with switch statement
:white_check_mark: + importShadow + Detects when imported package names shadowed in the assignments
:white_check_mark: + initClause + Detects non-assignment statements inside if/switch init clause
:white_check_mark: + methodExprCall + Detects method expression call that can be replaced with a method call
:white_check_mark: + nestingReduce + Finds where nesting level could be reduced
:white_check_mark: + paramTypeCombine + Detects if function parameters could be combined by type and suggest the way to do it
:white_check_mark: + ptrToRefParam + Detects input and output parameters that have a type of pointer to referential type
:heavy_check_mark: + regexpMust + Detects `regexp.Compile*` that can be replaced with `regexp.MustCompile*`
:heavy_check_mark: + singleCaseSwitch + Detects switch statements that could be better written as if statement
:heavy_check_mark: + sloppyLen + Detects usage of `len` when result is obvious or doesn't make sense
:white_check_mark: + stringXbytes + Detects redundant conversions between string and []byte
:heavy_check_mark: + switchTrue + Detects switch-over-bool statements that use explicit `true` tag value
:white_check_mark: + typeAssertChain + Detects repeated type assertions and suggests to replace them with type switch statement
:heavy_check_mark: + typeSwitchVar + Detects type switches that can benefit from type guard clause with variable
:white_check_mark: + typeUnparen + Detects unneded parenthesis inside type expressions and suggests to remove them
:heavy_check_mark: + underef + Detects dereference expressions that can be omitted
:white_check_mark: + unlabelStmt + Detects redundant statement labels
:heavy_check_mark: + unlambda + Detects function literals that can be simplified
:white_check_mark: + unnamedResult + Detects unnamed results that may benefit from names
:white_check_mark: + unnecessaryBlock + Detects unnecessary braced statement blocks
:heavy_check_mark: + unslice + Detects slice expressions that can be simplified to sliced expression itself
:white_check_mark: + valSwap + Detects value swapping code that are not using parallel assignment
:white_check_mark: + wrapperFunc + Detects function calls that can be replaced with convenience wrappers
:white_check_mark: + yodaStyleExpr + Detects Yoda style expressions and suggests to replace them
+ +### Checkers from the "performance" group + +Performance checks tell you about potential issues that +can make your code run slower than it could be. + +> All performance checks are disabled by default. + + + + + + + + + + + + + + + + + + + + + + + +
NameShort description
:white_check_mark: + appendCombine + Detects `append` chains to the same slice that can be done in a single `append` call
:white_check_mark: + equalFold + Detects unoptimal strings/bytes case-insensitive comparison
:white_check_mark: + hugeParam + Detects params that incur excessive amount of copying
:white_check_mark: + indexAlloc + Detects strings.Index calls that may cause unwanted allocs
:white_check_mark: + rangeExprCopy + Detects expensive copies of `for` loop range expressions
:white_check_mark: + rangeValCopy + Detects loops that copy big objects during each iteration
@@ -685,6 +788,33 @@ copy(dst, src) ``` + +## dupAssign + +[ + **diagnostic** + **experimental** ] + +Detects suspicious re-assignments. + + + + +**Before:** +```go +xs[0] = i+0 +xs[1] = i+1 +xs[0] = i+2 +``` + +**After:** +```go +xs[0] = i+0 +xs[1] = i+1 +xs[2] = i+2 +``` + + ## dupBranchBody @@ -1824,4 +1954,3 @@ return nil != ptr return ptr != nil ``` - diff --git a/docs/templates/checker_tr.partial.tmpl b/docs/templates/checker_tr.partial.tmpl new file mode 100644 index 000000000..f406b31d5 --- /dev/null +++ b/docs/templates/checker_tr.partial.tmpl @@ -0,0 +1,15 @@ +{{ define "checker_tr" -}} + + + + {{- if not (or (.HasTag "experimental") (.HasTag "opinionated") (.HasTag "performance")) -}} + :heavy_check_mark: + {{- else -}} + :white_check_mark: + {{- end }} + {{.Name}} + + {{.Summary}} + + +{{- end }} \ No newline at end of file diff --git a/docs/templates/overview.md.tmpl b/docs/templates/overview.md.tmpl index efb7269f1..1f85159d4 100644 --- a/docs/templates/overview.md.tmpl +++ b/docs/templates/overview.md.tmpl @@ -1,10 +1,41 @@ +{{ define "overview" -}} + ## Checks overview This page describes checks supported by [go-critic](https://github.com/go-critic/go-critic) linter. [//]: # (This is generated file, please don't edit it yourself.) -## Checkers: +## Checkers + +* :heavy_check_mark: checker is enabled by default. +* :white_check_mark: checker is disabled by default. + +### Checkers from the "diagnostic" group + +Diagnostics try to find programming errors in the code. +They also detect code that may be correct, but looks suspicious. + +> All diagnostics are enabled by default (unless it has "experimental" tag). + + + + + + + {{- range .Checkers }} + {{- if .HasTag "diagnostic" -}} + {{ template "checker_tr" . }} + {{- end -}} + {{- end }} +
NameShort description
+ +### Checkers from the "style" group + +Style checks suggest replacing some form of expression/statement +with another one that is considered more idiomatic or simple. + +> Only non-opinionated style checks are enabled by default. @@ -12,10 +43,28 @@ This page describes checks supported by [go-critic](https://github.com/go-critic {{- range .Checkers }} - - - - + {{- if .HasTag "style" -}} + {{ template "checker_tr" . }} + {{- end -}} + {{- end }} +
Short description
{{.Name}}{{.Summary}}
+ +### Checkers from the "performance" group + +Performance checks tell you about potential issues that +can make your code run slower than it could be. + +> All performance checks are disabled by default. + + + + + + + {{- range .Checkers }} + {{- if .HasTag "performance" -}} + {{ template "checker_tr" . }} + {{- end -}} {{- end }}
NameShort description
@@ -24,7 +73,7 @@ This page describes checks supported by [go-critic](https://github.com/go-critic ## {{ .Name }} [{{ range $tag := .Tags }} - **{{ $tag }}** + **{{ $tag }}** {{- end }} ] {{ .Summary -}}. @@ -47,3 +96,5 @@ This page describes checks supported by [go-critic](https://github.com/go-critic {{ .Note }} {{- end }} {{- end }} + +{{- end }} \ No newline at end of file