qual

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

README

Build Status codecov Maintainability

qual - Go package for quality assessment at source code level

Quick start

go get github.com/gregoryv/qual

Add a unit test to your project

func Test_CodeQuality(t *testing.T) {
    qual.Standard(t)
}

or if you are really brave, do

func Test_CodeQuality(t *testing.T) {
    qual.High(t)
}

The predefined tests measure

  • code complexity
  • line width

where the qual.Standard test only checks your package and qual.High also includes vendored code.

Scope

This package helps to improve code readability. Note, it's not measuring the quality of features in your solution. Those are better measured with benchmarks and user experience. The quality of the source code helps developers pass on their intent of their solution to other developers. We do this in various ways

  • documenting
  • tests and examples and most importantly
  • writing readable code

If we can write readable code, documentation can be minimized and that is always good, since developers tend to prefer writing code over documentation.

Assert

For a period this package came with an Assert func that parsed code to create presentable error messages. This proved to be less readable than intended(available in 0.2.1). However minimizing complexity by removing one pathway is still provided in asserter package.

Documentation

Overview

Package qual implements tests and helpers for writing highly readable code.

Index

Constants

This section is empty.

Variables

View Source
var DefaultWeight = 20 * 60 * time.Second

DefaultWeight is the duration it takes to fix overloaded complexity level. E.g. if complexity is 6 and you've set max to 5 this is the duration it takes to fix the code from 6 to 5.

Functions

func CyclomaticComplexity

func CyclomaticComplexity(max int, includeVendor bool, t T)

CyclomaticComplexity fails if max is exceeded in any go files of this project.

func FixDuration added in v0.2.1

func FixDuration(complexity, max int) (exp time.Duration)

FixDuration calculates the duration to fix all overloaded complexity. Everything more complex than 14+max is timed as if 14.

func FuncHeight added in v0.4.0

func FuncHeight(maxLines int, includeVendor bool, t T)

FuncHeight fails if any func body exceeds maxLines. All lines are considered, source and comments.

func High

func High(t T)

High is the same as Standard, only it includes all vendor source as well.

func LineLength

func LineLength(maxChars, tabSize int, includeVendor bool, t T)

LineLength fails if any go file contains lines exceeding maxChars. All lines are considered, source and comments.

func Standard

func Standard(t T)

Standard tests a set of metrics which might be considered necessary for production code. This is very opinionated, but the values are based on community insights from various sources.

Types

type T

type T interface {
	Helper()
	Error(...interface{})
	Errorf(string, ...interface{})
}

Directories

Path Synopsis
internal
find
Package find implements search funcs for finding files by name or content
Package find implements search funcs for finding files by name or content

Jump to

Keyboard shortcuts

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