Documentation
¶
Overview ¶
Package declspan answers one question: which lines does the declaration that a given line opens span?
It exists so an excusal can be as narrow as the thing it names. A credential (forbidden-pattern require_absent / none_of) and a scope.not_declaring marker both name a HOME — "this declaration is the one place that may do X". Before 0.14 the engine took the whole FILE holding the home as excused, so a second violation added anywhere in that file, outside the home, was invisible to the rule. The home is now the declaration the marker's line opens, and every other line of the file is judged.
What a declaration is depends on the language:
- Go: the top-level statement the line's first token begins, read with go/scanner so strings, raw strings, runes and comments cannot fake a delimiter. It ends at the first statement terminator (an explicit or automatically inserted semicolon) at bracket depth zero: a func or method ends after its body's closing brace, a const/var/type spec after its value or type. A `package` clause is the one Go declaration whose extent is the whole file: the package is the unit Go organizes code by.
- Dart and proto: the declaration from the line's first character to the closing brace of its first depth-zero block, or a semicolon at depth zero, whichever comes first, scanned over a projection whose comment and string bytes are blank (preprocess.CodeOnlyDart for Dart, a C-style decomment for proto) so neither can fake a delimiter.
- Anything else (Markdown, YAML, SQL, plain text) has no declaration structure this package bounds, so a document's marker declares the document: the extent is the whole file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Span ¶
type Span struct{ Start, End int }
Span is a 1-based, inclusive line range.
func Directives ¶
Directives returns the file-scoped directives of the file at path: Go import declarations, and Dart import/export/part/library directives. An import serves every declaration in its file, so no declaration can enclose it; a file that holds a home owns its directives with it. Other languages have none this package bounds.