go-ruleguard

Define and run pattern-based custom linting rules.

Github stars Tracking Chart

go-ruleguard

Build Status
GoDoc
Go Report Card

Logo

Overview

analysis-based Go linter that runs dynamically loaded rules.

You write the rules, ruleguard checks whether they are satisfied.

ruleguard has some similarities with GitHub CodeQL, but only focuses on Go code queries.

Features:

  • Custom linting rules without re-compilation and Go plugins.
  • Diagnostics are written in a declarative way.
  • Quickfix actions support.
  • Powerful match filtering features, like expression type pattern matching.

ruleguard comes with rules.go file that can be used as a foundation to write your own rules file.

It can also be easily embedded into other static analyzers. go-critic can be used as an example.

Quick start

To install ruleguard binary under your $(go env GOPATH)/bin:

$ go get -v -u github.com/quasilyte/go-ruleguard/...

If $GOPATH/bin is under your system $PATH, ruleguard command should be available after that.

$ ruleguard -help
ruleguard: execute dynamic gogrep-based rules

Usage: ruleguard [-flag] [package]

Flags:
  -rules string
    	path to a rules.go file
  -e string
    	execute a single rule from a given string
  -fix
    	apply all suggested fixes
  -c int
    	display offending line with this many lines of context (default -1)
  -json
    	emit JSON output

Create a test example.rules.go file:

// +build ignore

package gorules

import "github.com/quasilyte/go-ruleguard/dsl/fluent"

func _(m fluent.Matcher) {
	m.Match(`$x

Main metrics

Overview
Name With Ownerquasilyte/go-ruleguard
Primary LanguageGo
Program languageGo (Language Count: 4)
PlatformLinux, Mac, Windows
License:BSD 3-Clause "New" or "Revised" License
所有者活动
Created At2019-12-11 21:42:32
Pushed At2025-02-20 07:19:11
Last Commit At2025-02-20 08:19:11
Release Count57
Last Release Namev0.4.4 (Posted on )
First Release Namev0.1.1 (Posted on )
用户参与
Stargazers Count822
Watchers Count12
Fork Count42
Commits Count453
Has Issues Enabled
Issues Count164
Issue Open Count59
Pull Requests Count270
Pull Requests Open Count9
Pull Requests Close Count41
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private