All Projects → quasilyte → Go Consistent

quasilyte / Go Consistent

Licence: mit
Source code analyzer that helps you to make your Go programs more consistent.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Go Consistent

Validator
Nu Html Checker – Helps you catch problems in your HTML/CSS/SVG
Stars: ✭ 1,024 (+249.49%)
Mutual labels:  linter, best-practices
Clusterlint
A best practices checker for Kubernetes clusters. 🤠
Stars: ✭ 409 (+39.59%)
Mutual labels:  linter, best-practices
Xo
❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults
Stars: ✭ 6,277 (+2042.32%)
Mutual labels:  linter, best-practices
Pre Commit Hooks
A set of useful (and documented!) git pre-commit hooks.
Stars: ✭ 95 (-67.58%)
Mutual labels:  linter, best-practices
mllint
`mllint` is a command-line utility to evaluate the technical quality of Python Machine Learning (ML) projects by means of static analysis of the project's repository.
Stars: ✭ 67 (-77.13%)
Mutual labels:  best-practices, linter
Swift-Coding-Guidelines
A repository to collect best practices when programming with Swift
Stars: ✭ 17 (-94.2%)
Mutual labels:  best-practices, linter
rubocop-graphql
Rubocop extension for enforcing graphql-ruby best practices
Stars: ✭ 143 (-51.19%)
Mutual labels:  best-practices, linter
Wotan
Pluggable TypeScript and JavaScript linter
Stars: ✭ 271 (-7.51%)
Mutual labels:  linter, best-practices
Goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 2,943 (+904.44%)
Mutual labels:  linter
Vim Terraform Completion
A (Neo)Vim Autocompletion and linter for Terraform, a HashiCorp tool
Stars: ✭ 280 (-4.44%)
Mutual labels:  linter
Rwdtow
Ruby Web Dev: The Other Way. Personal best practices guide.
Stars: ✭ 267 (-8.87%)
Mutual labels:  best-practices
Typescript Tslint Plugin
TypeScript TSLint language service plugin
Stars: ✭ 270 (-7.85%)
Mutual labels:  linter
Guides
A set of rules we use at @icalialabs to build better software
Stars: ✭ 280 (-4.44%)
Mutual labels:  best-practices
Accessibility
A repo to organize the guidelines and best practices for accessibility at 18f.
Stars: ✭ 269 (-8.19%)
Mutual labels:  best-practices
Python Best Practices Cookiecutter
Python best practices project cookiecutter 🍪
Stars: ✭ 286 (-2.39%)
Mutual labels:  best-practices
Solidity Idiosyncrasies
Solidity gotchas, pitfalls, limitations, and idiosyncrasies.
Stars: ✭ 267 (-8.87%)
Mutual labels:  best-practices
Server Configs Apache
Apache HTTP server boilerplate configs
Stars: ✭ 2,916 (+895.22%)
Mutual labels:  best-practices
Eclint
Validate or fix code that doesn't adhere to EditorConfig settings or infer settings from existing code.
Stars: ✭ 288 (-1.71%)
Mutual labels:  linter
Darglint
A python documentation linter which checks that the docstring description matches the definition.
Stars: ✭ 285 (-2.73%)
Mutual labels:  linter
Coala Bears
Bears for coala
Stars: ✭ 276 (-5.8%)
Mutual labels:  linter

go-consistent

Build Status Go Report Card

Source code analyzer that helps you to make your Go programs more consistent.

Quick start / Installation

This install go-consistent binary under your $GOPATH/bin:

go get github.com/quasilyte/go-consistent

If $GOPATH/bin is under your system $PATH, go-consistent command should be available after that.
This should print the help message:

go-consistent --help

You can pass package names and separate Go filenames to the go-consistent tool:

go-consistent foo.go bar.go mypkg

You can also use std, ./... and other conventional targets that are normally understood by Go tools.

  • If you want to check consistency of a single file or package, just provide their name
  • If you want to check the whole project, you should pass all its packages as an arguments

Suppose your project occupies separate $GOPATH, then you can check the entire project by doing:

cd $(go env GOPATH)/src
go-consistent -v ./...

Overview

To understand what go-consistent does, take a look at these 3 lines of code:

lit1 := map[K]V{}
lit2 := map[K]V{}
m := make(map[K]V)

lit1, lit2 and m are initialized to an empty, non-nil map. The problem is that you have at least 2 ways to do it:

  1. lit1 and lit2 use the first option, the map literal
  2. m uses the second option, the make function

Neither of these are the "best", but on the package or project level, you might want to prefer only one of them, for consistency reasons.

go-consistent tool detects that map literal used more frequently (2 vs 1) in the example above, so it suggest you to replace m initialization expression to use map literal instead of make function.

There are many similar cases where you have 2 or more options of expressing the same thing in Go, go-consistent tries to handle as much patterns as possible.

Project traits

  • Zero-configuration. Defaults should be good enough for most users. Other configuration is performed using command line arguments.
  • Can handle projects of any size. This means that there should be no significant memory consumption growth with the increased number of packages being checked. There can be "fast, but memory-hungry" option that can work best for small-average projects, but it should be always possible to check huge projects on the developer machine.

Complete list of checks performed

  1. unit import
  2. zero val ptr alloc
  3. empty slice
  4. empty map
  5. hex lit
  6. range check
  7. and-not
  8. float lit
  9. label case
  10. untyped const coerce
  11. arg list parens
  12. non-zero length test
  13. default case order

unit import

// A: no parenthesis
import "fmt"

// B: with parenthesis
import (
	"fmt"
)

zero val ptr alloc

// A: new call
new(T)
new([]T)

// B: address of literal
&T{}
&[]T{}

empty slice

// A: make call
make([]T, 0)

// B: slice literal
[]T{}

empty map

// A: make call
make(map[K]V)

// B: map literal
map[K]V{}

hex lit

// A: lower case a-f digits
0xff

// B: upper case A-F digits
0xFF

range check

// A: left-aligned
x > low && x < high

// B: center-aligned
low < x && x < high

and-not

// A: using &^ operator (no space)
x &^ y

// B: using & and ^ (with space)
x & ^y

float lit

// A: explicit int/frac parts
0.0
1.0

// B: implicit int/frac parts
.0
1.

label case

// A: all upper case
LABEL_NAME:

// B: upper camel case
LabelName:

// C: lower camel case
labelName:

untyped const coerce

// A: LHS type
var x int32 = 10
const y float32 = 1.6

// B: RHS type
var x = int32(10)
const y = float32(1.6)

arg list parens

// A: closing parenthesis on the same line
multiLineCall(
	a,
	b,
	c)

// B: closing parenthesis on the next line
multiLineCall(
	a,
	b,
	c,
)

non-zero length test

// A: compare as "number of elems not equal to zero"
len(xs) != 0

// B: compare as "more than 0 elements"
len(xs) > 0

// C: compare as "at least 1 element"
len(xs) >= 1

default case order

// A: default case is the first one
switch {
default:
	return "?"
case x > 10:
	return "more than 10"
}

// B: default case is the last one
switch {
case x > 10:
	return "more than 10"
default:
	return "?"
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].