declspan

package
v0.22.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Mask

func Mask(src []byte, spans []Span) []byte

Mask returns a copy of src with every byte on a line inside any span replaced by a space, newlines kept, so line numbers and byte offsets stay the file's own and a masked declaration contributes nothing to a match.

func Whole

func Whole(src []byte, s Span) bool

Whole reports whether a span covers every line of src.

Types

type Span

type Span struct{ Start, End int }

Span is a 1-based, inclusive line range.

func Directives

func Directives(path string, src []byte) []Span

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.

func Extent

func Extent(path string, src []byte, line int) Span

Extent returns the lines spanned by the declaration that line (1-based) opens in the file at path with content src. A line past the end of the file yields that line alone.

func (Span) Contains

func (s Span) Contains(line int) bool

Contains reports whether line lies in the span.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL