Skip to content

Golang linter to prevent developers from throwing unnecessary panic and promote handling them.

Notifications You must be signed in to change notification settings

ayush030/dontpanic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

I have often found it hard to explain people who are new to Golang (or maybe to coding itself) that panics and error shouldn't be treated the same way. Throwing panics on every error is not the go to way. Hence, this repository is a linter that prevents such behaviour and at same time saves a lot of debugging.

yogilang [Image credit - ChatGPT]

To compile

  1. as a standalone utility, run
    make build-standalone
  2. as a plugin to be integrated with golangci-lint, run
    make build-plugin

Beginner References

Unitchecker VS Singlechecker-

In context of Go static analysis tools, unitchecker and singlechecker are both packages within the golang.org/x/tools/go/analysis library,
but they serve slightly different purposes. unitchecker is designed for analyzing a single compilation unit (a package or file) during a build,
often used by build systems like go vet. singlechecker, on the other hand, is for creating standalone tools that run a single analysis.

unitchecker:
1. Analyzes a single compilation unit during a build process.
2. Invoked by build systems like go vet.
3. Supports a command-line protocol to interact with the build system.
4. Suitable for integration with build pipelines and tools that require analysis during compilation.

singlechecker:
1. Provides a way to create standalone tools for running a single analysis.
2. Makes it easy for analysis providers to offer a standalone tool for their analysis.
3. Can be used to create custom linters or analysis tools.
4. Ideal for creating tools that can be run independently of a build system.

Abstract Syntax Tree(AST) - representation of Golang components such as modules, packages, literals, structures, declarations, comments etc. example for basic AST traversal

Inspect - Defines an analyser for AST inspector.

Pass - A Pass describes a single unit of work: the application of a particular Analyzer to a particular package of Go code. The Pass provides information to the Analyzer’s Run function about the package being analyzed. It provides operations to the Run function for reporting diagnostics and other information back to the driver. The Fset, Files, Pkg, and TypesInfo fields provide source positions, the syntax trees, type information for a single package of Go code.

type Pass struct {
	Fset   		*token.FileSet
	Files		[]*ast.File
	OtherFiles	[]string
	Pkg		*types.Package
	TypesInfo	*types.Info
	ResultOf	map[*Analyzer]interface{}
	Report		func(Diagnostic)
	...
}

Guide - Golang linter developer guide

About

Golang linter to prevent developers from throwing unnecessary panic and promote handling them.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published