v0.12.0
Pre-releaseUnused directives get their own rule, unused, with three modes. rules.unused: strict also reports a scope directive that restates the scope a declaration already has under the current config, and -fix deletes it.
Important
This release changes which ignore silences an unused report. Unused reports now carry the unused rule. //declscope:ignore directive no longer silences them: write //declscope:ignore unused. A leftover ignore directive is itself reported, so a run finds each one. See Migrating.
Two rules: unused and directive
| Rule | Reports | Config |
|---|---|---|
unused |
A //declscope:ignore that silenced nothing, and a //declscope:package or //declscope:private that changes no scope |
rules.unused: off | loose | strict, default loose |
directive |
Malformed, unknown, conflicting and misplaced directives | No key, always on |
rules.unused: off | loose | strict
| Mode | //declscope:ignore is reported when |
//declscope:package or //declscope:private is reported when |
-fix |
|---|---|---|---|
off |
Never | Never | None |
loose (default) |
It silenced no report | Deleting it would change no declaration's scope under any config | None |
strict |
It silenced no report | Deleting it would change no declaration's scope under the current config | Deletes the directive, unless another report depends on it |
package app
type user struct {
//declscope:private
name string
}
//declscope:package
func Helper() {}
//declscope:ignore boundary
func greet(u user) string { return u.name }| Line | off |
loose |
strict |
|---|---|---|---|
| 4 | Nothing | Nothing | unused //declscope:private on user.name: it already has private scope |
| 8 | Nothing | unused //declscope:package on Helper: nothing it reaches takes a scope |
unused //declscope:package on Helper: it already has package scope |
| 11 | Nothing | unused //declscope:ignore boundary on greet |
unused //declscope:ignore boundary on greet |
Line 4 is private only because defaults.unexported is private. loose does not rely on the current config, so it keeps the directive. strict reports it.
loose stays the default, so no new report appears without a config edit. To opt in:
rules:
unused: strictWarning
Under strict, changing defaults.unexported changes the reports. Every directive that restates the new default is reported. One -fix run deletes them.
declscope survey names the mode among the rules in force, for example unused strict, and "unused": "strict" in the JSON rules object.
Which ignore silences an unused report
| The ignore | Silences an unused report for |
|---|---|
//declscope:ignore unused on the declaration |
The scope directive and the other ignores beside it |
Bare //declscope:ignore on the declaration |
The scope directive beside it |
//declscope:ignore unused, or a bare one, above the package clause |
Every directive in the file |
//declscope:ignore unused on a block or a type |
Nothing inside it |
No ignore silences its own unused report. This now holds for a file-level ignore too, which used to silence its own report.
Fixes
- Generic structs. An unkeyed literal such as
pair[string]{1, "x"}and a conversion from an instantiation now count as uses of the struct's fields.boundarymissed a private field used that way, andsurplus: strictcould suggest narrowing it. - False unused reports under
loose. A spec's directive is now judged against the block directive it overrides. A spec's//declscope:privateunder a//declscope:packageblock was reported as unused, although deleting it widens the spec. - Accurate block and file-level messages. An unused block or file-level directive names what is true: every spec states its own scope, the named specs already have that scope, or a nearer directive decides.
- Directive on
func _. It is reported asno checked declaration carries it, as onvar _, instead of misplaced. - Config errors. An unknown key under
filterlists the keys the section takes. A filter pattern that leaves its config's directory is refused asfilter "...", notexclude "...".
Migrating
| You see | Do this |
|---|---|
unused //declscope:ignore directive on X next to another unused report on X |
Change it to //declscope:ignore unused |
unused file-level //declscope:ignore ... |
Remove the ignore. It silenced nothing, including its own report |
Full changelog: v0.11.0...v0.12.0