Skip to content

Commit

Permalink
lintcmd: don't print \' in -list-checks and -explain
Browse files Browse the repository at this point in the history
All the single quotes are written as `\'` in the descriptions. I assume
that's for a good reason, but -list-checks would print:

    % staticcheck -list-checks | grep "'"
    S1003 Replace call to \'strings.Index\' with \'strings.Contains\'
    S1004 Replace call to \'bytes.Compare\' with \'bytes.Equal\'
    S1011 Use a single \'append\' to concatenate two slices
    S1012 Replace \'time.Now().Sub(x)\' with \'time.Since(x)\'
    ...

    % staticcheck -explain S1003
    Replace call to \'strings.Index\' with \'strings.Contains\'

So fix that:

    % staticcheck -list-checks | grep "'"
    S1003 Replace call to 'strings.Index' with 'strings.Contains'
    S1004 Replace call to 'bytes.Compare' with 'bytes.Equal'
    S1011 Use a single 'append' to concatenate two slices
    S1012 Replace 'time.Now().Sub(x)' with 'time.Since(x)'
    ...

    % staticcheck -explain S1003
    Replace call to 'strings.Index' with 'strings.Contains'

As an added bonus, make `-explain s1003` (lower case) work. Seemed too
small of a change to make a new PR for.
  • Loading branch information
arp242 committed May 25, 2024
1 parent 5275b91 commit f5f7d2b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lintcmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (cmd *Command) listChecks() int {
if c.Doc != nil {
title = c.Doc.Title
}
fmt.Printf("%s %s\n", c.Analyzer.Name, title)
fmt.Printf("%s %s\n", c.Analyzer.Name, strings.ReplaceAll(title, `\'`, "'"))
}
return 0
}
Expand All @@ -366,7 +366,7 @@ func (cmd *Command) printVersion() int {

func (cmd *Command) explain() int {
explain := cmd.flags.explain
check, ok := cmd.analyzers[explain]
check, ok := cmd.analyzers[strings.ToUpper(explain)]
if !ok {
fmt.Fprintln(os.Stderr, "Couldn't find check", explain)
return 1
Expand All @@ -375,7 +375,7 @@ func (cmd *Command) explain() int {
fmt.Fprintln(os.Stderr, explain, "has no documentation")
return 1
}
fmt.Println(check.Doc)
fmt.Println(strings.ReplaceAll(check.Doc.String(), `\'`, "'"))
fmt.Println("Online documentation\n https://staticcheck.dev/docs/checks#" + check.Analyzer.Name)
return 0
}
Expand Down

0 comments on commit f5f7d2b

Please sign in to comment.