goblint: A Linter for GObject C Code
Over the past week, Iβve been building goblint, a linter specifically designed for GObject-based C codebases.
If you know Rustβs clippy or Goβs go vet, think of goblint as the same thing for GObject/GLib.
Why this existsπ
A large part of the Linux desktop stack (GTK, Mutter, Pango, NetworkManager) is built on GObject. These projects have evolved over decades and carry a lot of patterns that predate newer GLib helpers, are easy to misuse, or encode subtle lifecycle invariants that nothing verifies.
This leads to issues like missing dispose/finalize/constructed chain-ups (memory leaks or undefined behavior), incorrect property definitions, uninitialized GError* variables, or function declarations with no implementation.
These arenβt theoretical. This GTK merge request recently fixed several missing chain-ups in example code.
Despite this, the C ecosystem lacks a linter that understands GObject semantics. goblint exists to close that gap.
What goblint checksπ
goblint ships with 35 rules across different categories:
- Correctness: Real bugs like non-canonical property names, uninitialized
GError*, missingPROP_0 - Suspicious: Likely mistakes like missing implementations or redundant NULL checks
- Style: Idiomatic GLib usage (
g_strcmp0,g_str_equal()) - Complexity: Suggests modern helpers (
g_autoptr,g_clear_*,g_set_str()) - Performance: Optimizations like
G_PARAM_STATIC_STRINGSorg_object_notify_by_pspec() - Pedantic: Consistency checks (macro semicolons, matching declare/define pairs)
23 out of 35 rules are auto-fixable. You should apply fixes one rule at a time to review the changes:
CI/CD Integrationπ
goblint fits into existing pipelines.
GitHub Actionsπ
- name: Run goblint
run: goblint --format sarif > goblint.sarif
- name: Upload SARIF results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: goblint.sarif
Results show up in the Security tab under "Code scanning" and inline on pull requests.
GitLab CIπ
goblint:
image: ghcr.io/bilelmoussaoui/goblint:latest
script:
- goblint --format sarif > goblint.sarif
artifacts:
reports:
sast: goblint.sarif
Results appear inline in merge requests.
Configurationπ
Rules default to warn, and can be tuned via goblint.toml:
= "2.40" # Auto-disable rules for newer versions
[]
= "error" # Make critical
= "warn" # Keep as warning
= "ignore" # Disable
# Per-rule ignore patterns
= { = "error", = ["src/backends/**"] }
You can adopt it gradually without fixing everything at once.
Try itπ
# Run via container
# Install locally
# Usage
The project is early, so feedback is especially valuable (false positives, missing checks, workflow issues, etc.).
Note: The project was originally named "goblin" but was renamed to "goblint" to avoid conflicts with the existing goblin crate for parsing binary formats.