Skip to main content

drep/languages/definitions/
go.rs

1//! The Go ecosystem: gofmt and go vet over `.go`.
2
3use crate::languages::spec::{
4    DEFAULT_TOOL_TIMEOUT_SECS, DiagnosticsStream, LanguageSupport, OutputFormat, ToolSpec,
5};
6
7/// Go formatting checker - lists files whose formatting drifts from `gofmt`'s.
8///
9/// `go.mod` is the marker that this is a Go module at all; gofmt has no
10/// config of its own because its formatting is not configurable.
11pub static GOFMT: ToolSpec = ToolSpec {
12    name: "gofmt",
13    command: &["gofmt", "-l"],
14    local_paths: &[],
15    config_files: &["go.mod"],
16    config_flag: None,
17    output_format: OutputFormat::Lines,
18    diagnostics_stream: DiagnosticsStream::Stdout,
19    timeout_secs: DEFAULT_TOOL_TIMEOUT_SECS,
20    timeout_context: None,
21    establishes_compilation: false,
22    serial_in_repository: false,
23    accepts_files: true,
24};
25
26/// `go vet`. Streams diagnostics to stderr.
27///
28/// Not -json: that only emits JSON once the package compiles, and a package
29/// that does not compile is exactly when vet has the most to say.
30pub static GO_VET: ToolSpec = ToolSpec {
31    name: "go vet",
32    command: &["go", "vet"],
33    local_paths: &[],
34    config_files: &["go.mod"],
35    config_flag: None,
36    output_format: OutputFormat::Position,
37    diagnostics_stream: DiagnosticsStream::Stderr,
38    timeout_secs: DEFAULT_TOOL_TIMEOUT_SECS,
39    timeout_context: None,
40    establishes_compilation: true,
41    serial_in_repository: false,
42    accepts_files: true,
43};
44
45/// Go language entry.
46pub static GO: LanguageSupport = LanguageSupport {
47    name: "go",
48    display_name: "Go",
49    extensions: &[".go"],
50    filenames: &[],
51    filename_prefixes: &[],
52    tools: &[&GOFMT, &GO_VET],
53    conventions: &[
54        "Errors ignored rather than checked and wrapped",
55        "Goroutine leaks, and writes to a channel nobody reads",
56        "defer inside a loop, and defer that never runs",
57        "Data races on shared state without synchronisation",
58    ],
59    vendored_dirs: &["vendor"],
60};
61
62/// The family's entries in registration order. See `ALL_LANGUAGES`.
63pub(crate) static FAMILY: &[&LanguageSupport] = &[&GO];