emptycase

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2021 License: MIT Imports: 6 Imported by: 3

README

emptycase

Go Documentation Test

Analyzer: emptycase finds case statements with no body

Intall

$ go get github.com/gostaticanalysis/emptycase/cmd/emptycase

Usage

$ go vet -vettool=`which emptycase` pkgname

Motivation

It is common knowledge for gopher that there is no fall through in the switch-case statement of the Go language. However, people who are used to C or Java may inadvertently write code like the following.

func f() {
	v := 1
	switch v {
	case 1:
	case 2:
		fmt.Println("execute")
	}
}

Of course, Println() donesn't be executed. However, it takes a while to realize this when you write it.

This Analyzer detects empty cases, making it faster to notice problems.

Ignore intentional empty cases

Sometimes an empty case is written to indicate that nothing is to be processed on purpose. This Analyzer ignores empty cases that have comments.

func f() {
	v := 1
	switch v {
	case 1: // This is an intentionally empty case.
	case 2:
		// This is an intentionally empty case.
		// If you want to write a comment on a different line from the case statement, you need to put a blank line between it and the next case statement.
		
	case 3:
		fmt.Println("execute")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "emptycase",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Analyzer is ...

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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