keepsorted

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Finding

type Finding struct {
	// The name of the file that this finding is for.
	Path string `json:"path"`
	// The lines that this finding applies to.
	Lines LineRange `json:"lines"`
	// A human-readable message about what the finding is.
	Message string `json:"message"`
	// Possible fixes that could be applied to resolve the problem.
	// Each fix in this slice would independently fix the problem, they do not
	// and should not all be applied.
	Fixes []Fix `json:"fixes"`
}

Finding is something that keep-sorted thinks is wrong with a particular file.

type Fix

type Fix struct {
	// The changes that should be made to the file to resolve the Finding.
	// All of these changes need to be made.
	Replacements []Replacement `json:"replacements"`
}

Fix is a set of changes that could be made to resolve a Finding.

type Fixer

type Fixer struct {
	ID string
	// contains filtered or unexported fields
}

Fixer runs the business logic of keep-sorted.

func New

func New(id string) *Fixer

New creates a new fixer with the given string as its identifier. By default, id is "keep-sorted"

func (*Fixer) Findings

func (f *Fixer) Findings(filename, contents string, modifiedLines []LineRange) []*Finding

Findings returns a slice of things that need to be addressed in the file to make keep-sorted happy.

If modifiedLines is non-nil, we only report findings for issues within the modified lines. Otherwise, we report all findings.

func (*Fixer) Fix

func (f *Fixer) Fix(contents string, modifiedLines []LineRange) (fixed string, alreadyCorrect bool)

Fix all of the findings on contents to make keep-sorted happy.

type LineRange

type LineRange struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

LineRange is a 1-based range of continuous lines within a file. Both start and end are inclusive. You can designate a single line by setting start and end to the same line number.

func (LineRange) HighAtDimension

func (lr LineRange) HighAtDimension(uint64) int64

func (LineRange) ID

func (lr LineRange) ID() uint64

func (LineRange) LowAtDimension

func (lr LineRange) LowAtDimension(uint64) int64

func (LineRange) OverlapsAtDimension

func (lr LineRange) OverlapsAtDimension(i augmentedtree.Interval, d uint64) bool

type Replacement

type Replacement struct {
	// The lines that should be replaced with NewContent.
	Lines      LineRange `json:"lines"`
	NewContent string    `json:"new_content"`
}

Replacement is a single substitution to apply to a file.

Jump to

Keyboard shortcuts

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