-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrule_ignore.go
More file actions
52 lines (42 loc) · 1.65 KB
/
Copy pathrule_ignore.go
File metadata and controls
52 lines (42 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package goago
import (
"go/ast"
"go/token"
)
// RuleNoInvalidIgnore keeps suppression directives honest.
var RuleNoInvalidIgnore = register(Rule{
Name: "no-invalid-ignore",
Summary: "every //goago:ignore must name a known rule and give a reason",
Default: true,
Severity: Error,
Rationale: `A suppression that names no rule silences everything on the line, and a
suppression that names a misspelled rule silences nothing at all. Both fail
quietly, which is how a lint configuration rots.
This rule requires the full form:
//goago:ignore no-goto -- hand-written state machine, see docs/parser.md
The reason is not decoration. It is the only record of why goago granted the
exception. A reviewer or a coding agent reads it before deciding whether the
exception still applies.
Turning this rule off is possible but self-defeating. It is the rule that
makes every other rule's escape hatch auditable.`,
Analyzer: newAnalyzer("no-invalid-ignore",
"reject //goago:ignore directives that name no known rule or give no reason",
checkInvalidIgnore),
})
func checkInvalidIgnore(c *checkPass) {
if c.ignores == nil {
return
}
for _, d := range c.ignores.all {
if d.Problem != "" {
c.reportf(directivePos{d.Pos}, "//goago:ignore %s", d.Problem)
}
}
}
// directivePos adapts a comment position to the [ast.Node] interface, so
// reportf can report a directive through the same path as a syntax node. The
// helper reports a directive at a single point rather than over a range.
type directivePos struct{ pos token.Pos }
func (d directivePos) Pos() token.Pos { return d.pos }
func (d directivePos) End() token.Pos { return d.pos }
var _ ast.Node = directivePos{}