nomainreturn

package module
v0.0.0-...-2e22db9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: MIT Imports: 4 Imported by: 0

README

nomainreturn

A Go linter that checks for return statements in the main.

Install

go get github.com/bedakb/nomainreturn

Usage

nomainreturn ./...

Example

The purpose of this linter is to prevent accidental exits with 0 status code by using return.

package main

import (
    "fmt"

    log "github.com/sirupsen/logrus"
)

func main() {
    fmt.Println("running the program")

    if err := errnousFunc(); err != nil {
        log.WithError(err).Error("error occurred")
        return // exits with code 0
    }

    fmt.Println("done")
}

Documentation

Overview

Package nomainreturn defines an Analyzer that reports use of return keyword in the main.

Index

Constants

This section is empty.

Variables

View Source
var DefaultAllowPackages = []string{"main"}

DefaultAllowPackages is an allow-list of packages to include when running the linter.

View Source
var DefaultConfig = Config{
	AllowPackages: DefaultAllowPackages,
}

DefaultConfig is a default linter config.

Functions

func NewAnalyzer

func NewAnalyzer(cfg Config) *analysis.Analyzer

NewAnalyzer creates new nomainreturn analyzer.

Types

type Config

type Config struct {
	// AllowPackages defines a list of packages that linter should check.
	//
	// Generally, package main will be only allowed package, but for testing cases
	// you may include other packages.
	AllowPackages []string `mapstructure:"allowPackages" yaml:"allowPackages"`
}

Config is a set of configuration values which configure the linter behavior.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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