quickfix

package
v0.0.0-...-2c056e7 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package quickfix contains analyzes that implement code refactorings. None of these analyzers produce diagnostics that have to be followed. Most of the time, they only provide alternative ways of doing things, requiring users to make informed decisions.

None of these analyzes should fail a build, and they are likely useless in CI as a whole.

Index

Constants

This section is empty.

Variables

View Source
var Analyzers = lint.InitializeAnalyzers(Docs, map[string]*analysis.Analyzer{
	"QF1001": {
		Run:      CheckDeMorgan,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"QF1002": {
		Run:      CheckTaglessSwitch,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"QF1003": {
		Run:      CheckIfElseToSwitch,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"QF1004": {
		Run:      CheckStringsReplaceAll,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"QF1005": {
		Run:      CheckMathPow,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"QF1006": {
		Run:      CheckForLoopIfBreak,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"QF1007": {
		Run:      CheckConditionalAssignment,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"QF1008": {
		Run:      CheckExplicitEmbeddedSelector,
		Requires: []*analysis.Analyzer{inspect.Analyzer, tokenfile.Analyzer},
	},
	"QF1009": {
		Run:      CheckTimeEquality,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"QF1010": {
		Run:      CheckByteSlicePrinting,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"QF1011": sharedcheck.RedundantTypeInDeclarationChecker("could", true),
	"QF1012": {
		Run:      CheckWriteBytesSprintf,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
})
View Source
var Docs = lint.Markdownify(map[string]*lint.RawDocumentation{
	"QF1001": {
		Title:    "Apply De Morgan's law",
		Since:    "2021.1",
		Severity: lint.SeverityHint,
	},

	"QF1002": {
		Title: "Convert untagged switch to tagged switch",
		Text: `
An untagged switch that compares a single variable against a series of
values can be replaced with a tagged switch.`,
		Before: `
switch {
case x == 1 || x == 2, x == 3:
    ...
case x == 4:
    ...
default:
    ...
}`,

		After: `
switch x {
case 1, 2, 3:
    ...
case 4:
    ...
default:
    ...
}`,
		Since:    "2021.1",
		Severity: lint.SeverityHint,
	},

	"QF1003": {
		Title: "Convert if/else-if chain to tagged switch",
		Text: `
A series of if/else-if checks comparing the same variable against
values can be replaced with a tagged switch.`,
		Before: `
if x == 1 || x == 2 {
    ...
} else if x == 3 {
    ...
} else {
    ...
}`,

		After: `
switch x {
case 1, 2:
    ...
case 3:
    ...
default:
    ...
}`,
		Since:    "2021.1",
		Severity: lint.SeverityInfo,
	},

	"QF1004": {
		Title:    `Use \'strings.ReplaceAll\' instead of \'strings.Replace\' with \'n == -1\'`,
		Since:    "2021.1",
		Severity: lint.SeverityHint,
	},

	"QF1005": {
		Title:    `Expand call to \'math.Pow\'`,
		Text:     `Some uses of \'math.Pow\' can be simplified to basic multiplication.`,
		Before:   `math.Pow(x, 2)`,
		After:    `x * x`,
		Since:    "2021.1",
		Severity: lint.SeverityHint,
	},

	"QF1006": {
		Title: `Lift \'if\'+\'break\' into loop condition`,
		Before: `
for {
    if done {
        break
    }
    ...
}`,

		After: `
for !done {
    ...
}`,
		Since:    "2021.1",
		Severity: lint.SeverityHint,
	},

	"QF1007": {
		Title: "Merge conditional assignment into variable declaration",
		Before: `
x := false
if someCondition {
    x = true
}`,
		After:    `x := someCondition`,
		Since:    "2021.1",
		Severity: lint.SeverityHint,
	},

	"QF1008": {
		Title:    "Omit embedded fields from selector expression",
		Since:    "2021.1",
		Severity: lint.SeverityHint,
	},

	"QF1009": {
		Title:    `Use \'time.Time.Equal\' instead of \'==\' operator`,
		Since:    "2021.1",
		Severity: lint.SeverityInfo,
	},

	"QF1010": {
		Title:    "Convert slice of bytes to string when printing it",
		Since:    "2021.1",
		Severity: lint.SeverityHint,
	},

	"QF1011": {
		Title:    "Omit redundant type from variable declaration",
		Since:    "2021.1",
		Severity: lint.SeverityHint,
	},

	"QF1012": {
		Title:    `Use \'fmt.Fprintf(x, ...)\' instead of \'x.Write(fmt.Sprintf(...))\'`,
		Since:    "2022.1",
		Severity: lint.SeverityHint,
	},
})

Functions

func CheckByteSlicePrinting

func CheckByteSlicePrinting(pass *analysis.Pass) (interface{}, error)

func CheckConditionalAssignment

func CheckConditionalAssignment(pass *analysis.Pass) (interface{}, error)

func CheckDeMorgan

func CheckDeMorgan(pass *analysis.Pass) (interface{}, error)

func CheckExplicitEmbeddedSelector

func CheckExplicitEmbeddedSelector(pass *analysis.Pass) (interface{}, error)

func CheckForLoopIfBreak

func CheckForLoopIfBreak(pass *analysis.Pass) (interface{}, error)

func CheckIfElseToSwitch

func CheckIfElseToSwitch(pass *analysis.Pass) (interface{}, error)

func CheckMathPow

func CheckMathPow(pass *analysis.Pass) (interface{}, error)

func CheckStringsReplaceAll

func CheckStringsReplaceAll(pass *analysis.Pass) (interface{}, error)

func CheckTaglessSwitch

func CheckTaglessSwitch(pass *analysis.Pass) (interface{}, error)

func CheckTimeEquality

func CheckTimeEquality(pass *analysis.Pass) (interface{}, error)

func CheckWriteBytesSprintf

func CheckWriteBytesSprintf(pass *analysis.Pass) (interface{}, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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