Skip to content

Commit

Permalink
formatter: improve description of require-f-funcs flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonboom committed Nov 13, 2024
1 parent efd6e0e commit 8fd3485
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,19 +465,29 @@ disable this feature, use `--formatter.check-format-string=false` flag.

#### 3)

Requirement of the f-assertions if format string is used. Disabled by default, use `--formatter.require-f-funcs` flag
to enable. This helps follow Go's implicit convention
Requirement of the f-assertions (e.g. assert.Equal**f**) if format string is used. Disabled by default, use
`--formatter.require-f-funcs` flag to enable. <br>

> Printf-like functions must end with `f`
This helps follow Go's implicit convention _"Printf-like functions must end with `f`"_ and sets the stage for moving to
`v2` of `testify`. In this way the checker resembles the [goprintffuncname](https://github.com/jirfag/go-printf-func-name)
linter (included in [golangci-lint](https://golangci-lint.run/usage/linters/)). <br>

and sets the stage for moving to `v2` of `testify`. In this way the checker resembles the
[goprintffuncname](https://github.com/jirfag/go-printf-func-name) linter (included in
[golangci-lint](https://golangci-lint.run/usage/linters/)). Also format string in f-assertions is highlighted by IDE
, e.g. GoLand:
Also, verbs in the format string of f-assertions are highlighted by an IDE, e.g. GoLand:

<img width="600" alt="F-assertion IDE highlighting" src="https://github.com/Antonboom/testifylint/assets/17127404/9bdab802-d6eb-477d-a411-6cba043d33a5">

#### Historical Reference
<br>

> [!CAUTION]
> `--formatter.require-f-funcs` requires f-assertions **even if there are no variable-length variables**, i.e. it
> requires `require.NoErrorf` for both these cases:
> ```
> require.NoErrorf(t, err, "unexpected error")
> require.NoErrorf(t, err, "unexpected error for sid: %v", sid)
> ```
> To understand this behavior, please read the reference below.
#### Historical reference of formatter

<details>

Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func BindToFlags(cfg *Config, fs *flag.FlagSet) {
"to enable go vet's printf checks")
fs.BoolVar(&cfg.Formatter.RequireFFuncs,
"formatter.require-f-funcs", false,
"to require f-assertions if format string is used")
"to require f-assertions if format string is used (even if there are no variable-length variables)")

fs.BoolVar(&cfg.GoRequire.IgnoreHTTPHandlers,
"go-require.ignore-http-handlers", false,
Expand Down

0 comments on commit 8fd3485

Please sign in to comment.