Skip to content

Commit 8fd3485

Browse files
committed
formatter: improve description of require-f-funcs flag
1 parent efd6e0e commit 8fd3485

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

README.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -465,19 +465,29 @@ disable this feature, use `--formatter.check-format-string=false` flag.
465465

466466
#### 3)
467467

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

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

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

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

480-
#### Historical Reference
479+
<br>
480+
481+
> [!CAUTION]
482+
> `--formatter.require-f-funcs` requires f-assertions **even if there are no variable-length variables**, i.e. it
483+
> requires `require.NoErrorf` for both these cases:
484+
> ```
485+
> require.NoErrorf(t, err, "unexpected error")
486+
> require.NoErrorf(t, err, "unexpected error for sid: %v", sid)
487+
> ```
488+
> To understand this behavior, please read the reference below.
489+
490+
#### Historical reference of formatter
481491
482492
<details>
483493

internal/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func BindToFlags(cfg *Config, fs *flag.FlagSet) {
133133
"to enable go vet's printf checks")
134134
fs.BoolVar(&cfg.Formatter.RequireFFuncs,
135135
"formatter.require-f-funcs", false,
136-
"to require f-assertions if format string is used")
136+
"to require f-assertions if format string is used (even if there are no variable-length variables)")
137137

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

0 commit comments

Comments
 (0)