analyzer

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

README

GoDoc Go Report Card license

alphavet

This is a simple linter which is designed to report upon functions which are not implemented in alphabetical order within files.

The motivation behind this tool was twofold:

  • I find it easier to navigate functions if they are ordered alphabetically.
    • Most IDEs offer a tree/outline view which is ordered alphabetically, and the contents and the tree should match!
  • Once I realized a linter, driven by "go vet", could be named "alphavet" I couldn't resist the temptation to hack it up.
    • Even though this could just has easily have been a portable Perl script.

Installation

If you have a working golang toolset you should be able to install by:

go install github.com/skx/alphavet/cmd/alphavet@latest

Usage

The linter is designed to be driven by go vet like so:

$ go vet -vettool=$(which alphavet) ./...

By default the two functions init and main are excluded from the alphabetical ordering requirement. If you wish to exclude additional functions you may do so, via the -exclude parameter:

$ go vet -vettool=$(which alphavet) -exclude=init,main,New ./...

Sample Output

Sample output would look something like this:

$ go vet -vettool=$(which alphavet) ./...
# github.com/skx/gobasic/builtin
./builtin.go:67:1: function Get should have been before Register
./misc_test.go:21:1: function LineEnding should have been before StdInput
./misc_test.go:29:1: function StdError should have been before StdOutput
./misc_test.go:33:1: function Data should have been before StdError

Github Setup

This repository is configured to run tests upon every commit, and when pull-requests are created/updated. The testing is carried out via .github/run-tests.sh which is used by the github-action-tester action.

Bug reports?

Please do feel free to report any issues you see with the code, or the results.

Feature requests are also welcome, although I'd prefer to avoid having excessive flags.

Steve

Documentation

Overview

Package analyzer contains the code which carries out our linting check.

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:     "alphavet",
	Doc:      "Checks that functions are ordered alphabetically within packages.",
	Run:      run,
	Requires: []*analysis.Analyzer{inspect.Analyzer},
}

Analyzer configures our function.

Functions

This section is empty.

Types

type Function

type Function struct {
	// The file containing the function.
	File string

	// The name of the function.
	Name string

	// The position within our source where this object was.
	Position token.Pos

	// The receiver, if any, for the function.
	Receiver string
}

Function represents a function definition which has been encountered when scanning the source code.

We want to differentiate between function calls that have receivers, and those that don't so we store some extra details here.

Directories

Path Synopsis
cmd
alphavet
Package main contains the main driver, which launches our linter.
Package main contains the main driver, which launches our linter.

Jump to

Keyboard shortcuts

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