Merge pull request #1026 from gavin-ts/lint

lint for go 1.20
This commit is contained in:
gavin-ts 2023-03-14 18:21:38 -07:00 committed by GitHub
commit 6614000fe5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 100 additions and 92 deletions

View file

@ -355,13 +355,13 @@ func (sd *sequenceDiagram) placeActors() {
} }
// addLifelineEdges adds a new edge for each actor in the graph that represents the its lifeline // addLifelineEdges adds a new edge for each actor in the graph that represents the its lifeline
// ┌──────────────┐ // . ┌──────────────┐
// │ actor │ // . │ actor │
// └──────┬───────┘ // . └──────┬───────┘
// // .
// │ lifeline // . │ lifeline
// // .
// // .
func (sd *sequenceDiagram) addLifelineEdges() { func (sd *sequenceDiagram) addLifelineEdges() {
endY := 0. endY := 0.
if len(sd.messages) > 0 { if len(sd.messages) > 0 {
@ -433,17 +433,17 @@ func (sd *sequenceDiagram) placeNotes() {
} }
// placeSpans places spans over the object lifeline // placeSpans places spans over the object lifeline
// ┌──────────┐ // . ┌──────────┐
// │ actor │ // . │ actor │
// └────┬─────┘ // . └────┬─────┘
// ┌─┴──┐ // . ┌─┴──┐
// │ │ // . │ │
// |span| // . |span|
// │ │ // . │ │
// └─┬──┘ // . └─┬──┘
// // .
// lifeline // . lifeline
// // .
func (sd *sequenceDiagram) placeSpans() { func (sd *sequenceDiagram) placeSpans() {
// quickly find the span center X // quickly find the span center X
rankToX := make(map[int]float64) rankToX := make(map[int]float64)

View file

@ -97,11 +97,12 @@ func ParseValue(value string) (d2ast.Value, error) {
} }
// TODO: refactor parser to keep entire file in memory as []rune // TODO: refactor parser to keep entire file in memory as []rune
// - trivial to then convert positions // - trivial to then convert positions
// - lookahead is gone, just forward back as much as you want :) // - lookahead is gone, just forward back as much as you want :)
// - streaming parser isn't really helpful. // - streaming parser isn't really helpful.
// - just read into a string even and decode runes forward/back as needed // - just read into a string even and decode runes forward/back as needed
// - the whole file essentially exists within the parser as the AST anyway... // - the whole file essentially exists within the parser as the AST anyway...
//
// TODO: ast struct that combines map & errors and pass that around // TODO: ast struct that combines map & errors and pass that around
type parser struct { type parser struct {
path string path string
@ -315,13 +316,15 @@ func (p *parser) commit() {
// //
// TODO: make each parse function read its delimiter and return nil if not as expected // TODO: make each parse function read its delimiter and return nil if not as expected
// TODO: lookahead *must* always be empty in between parse calls. you either commit or // TODO: lookahead *must* always be empty in between parse calls. you either commit or
// rewind in each function. if you don't, you pass a hint. //
// rewind in each function. if you don't, you pass a hint.
// //
// TODO: omg we don't need two buffers, just a single lookahead and an index... // TODO: omg we don't need two buffers, just a single lookahead and an index...
// TODO: get rid of lookaheadPos or at least never use directly. maybe rename to beforePeekPos? // TODO: get rid of lookaheadPos or at least never use directly. maybe rename to beforePeekPos?
// or better yet keep positions in the lookahead buffer. //
// ok so plan here is to get rid of lookaheadPos and add a rewindPos that stores // or better yet keep positions in the lookahead buffer.
// the pos to rewind to. // ok so plan here is to get rid of lookaheadPos and add a rewindPos that stores
// the pos to rewind to.
func (p *parser) rewind() { func (p *parser) rewind() {
if len(p.lookahead) == 0 { if len(p.lookahead) == 0 {
return return

View file

@ -22,18 +22,18 @@ import (
// The layout plugin protocol works as follows. // The layout plugin protocol works as follows.
// //
// Info // Info
// 1. The binary is invoked with info as the first argument. // 1. The binary is invoked with info as the first argument.
// 2. The stdout of the binary is unmarshalled into PluginInfo. // 2. The stdout of the binary is unmarshalled into PluginInfo.
// //
// Layout // Layout
// 1. The binary is invoked with layout as the first argument and the json marshalled // 1. The binary is invoked with layout as the first argument and the json marshalled
// d2graph.Graph on stdin. // d2graph.Graph on stdin.
// 2. The stdout of the binary is unmarshalled into a d2graph.Graph // 2. The stdout of the binary is unmarshalled into a d2graph.Graph
// //
// PostProcess // PostProcess
// 1. The binary is invoked with postprocess as the first argument and the // 1. The binary is invoked with postprocess as the first argument and the
// bytes of the SVG render on stdin. // bytes of the SVG render on stdin.
// 2. The stdout of the binary is bytes of SVG with any post-processing. // 2. The stdout of the binary is bytes of SVG with any post-processing.
// //
// If any errors occur the binary will exit with a non zero status code and write // If any errors occur the binary will exit with a non zero status code and write
// the error to stderr. // the error to stderr.

View file

@ -132,12 +132,12 @@ func ListPluginInfos(ctx context.Context, ps []Plugin) ([]*PluginInfo, error) {
} }
// FindPlugin finds the plugin with the given name. // FindPlugin finds the plugin with the given name.
// 1. It first searches the bundled plugins in the global plugins slice. // 1. It first searches the bundled plugins in the global plugins slice.
// 2. If not found, it then searches each directory in $PATH for a binary with the name // 2. If not found, it then searches each directory in $PATH for a binary with the name
// d2plugin-<name>. // d2plugin-<name>.
// **NOTE** When D2 upgrades to go 1.19, remember to ignore exec.ErrDot // **NOTE** When D2 upgrades to go 1.19, remember to ignore exec.ErrDot
// 3. If such a binary is found, it builds an execPlugin in exec.go // 3. If such a binary is found, it builds an execPlugin in exec.go
// to get a plugin implementation around the binary and returns it. // to get a plugin implementation around the binary and returns it.
func FindPlugin(ctx context.Context, ps []Plugin, name string) (Plugin, error) { func FindPlugin(ctx context.Context, ps []Plugin, name string) (Plugin, error) {
for _, p := range ps { for _, p := range ps {
info, err := p.Info(ctx) info, err := p.Info(ctx)

View file

@ -65,7 +65,7 @@ func (bc BezierCurve) At(point float64) *Point {
return NewPoint(float64(curvePoint.X), float64(curvePoint.Y)) return NewPoint(float64(curvePoint.X), float64(curvePoint.Y))
} }
//nolint // nolint
func ComputeIntersections(px, py, lx, ly []float64) []*Point { func ComputeIntersections(px, py, lx, ly []float64) []*Point {
out := make([]*Point, 0) out := make([]*Point, 0)
@ -111,7 +111,7 @@ func ComputeIntersections(px, py, lx, ly []float64) []*Point {
return out return out
} }
//nolint // nolint
func cubicRoots(P []float64) []float64 { func cubicRoots(P []float64) []float64 {
if PrecisionCompare(P[0], 0, PRECISION) == 0 { if PrecisionCompare(P[0], 0, PRECISION) == 0 {
if PrecisionCompare(P[1], 0, PRECISION) == 0 { if PrecisionCompare(P[1], 0, PRECISION) == 0 {
@ -209,7 +209,7 @@ func cubicRoots(P []float64) []float64 {
return t return t
} }
//nolint // nolint
func sortSpecial(a []float64) []float64 { func sortSpecial(a []float64) []float64 {
var flip bool var flip bool
var temp float64 var temp float64
@ -235,7 +235,7 @@ func sortSpecial(a []float64) []float64 {
return a return a
} }
//nolint // nolint
func sgn(x float64) float64 { func sgn(x float64) float64 {
if x < 0.0 { if x < 0.0 {
return -1 return -1
@ -243,7 +243,7 @@ func sgn(x float64) float64 {
return 1 return 1
} }
//nolint // nolint
func bezierCoeffs(P0, P1, P2, P3 float64) []float64 { func bezierCoeffs(P0, P1, P2, P3 float64) []float64 {
Z := make([]float64, 4) Z := make([]float64, 4)
Z[0] = -P0 + 3*P1 + -3*P2 + P3 Z[0] = -P0 + 3*P1 + -3*P2 + P3

View file

@ -55,24 +55,24 @@ func (segment Segment) Intersections(otherSegment Segment) []*Point {
// If there is no floor or ceiling, negative or positive infinity is used, respectively // If there is no floor or ceiling, negative or positive infinity is used, respectively
// The direction is inferred, e.g. b/c the passed in segment is vertical, it's inferred we want horizontal bounds // The direction is inferred, e.g. b/c the passed in segment is vertical, it's inferred we want horizontal bounds
// buffer says how close the segment can be, on both axes, to other segments given // buffer says how close the segment can be, on both axes, to other segments given
// │ │ // . │ │
// │ │ // . │ │
// │ │ // . │ │
// │ │ // . │ │
// │ non-overlap // . │ non-overlap
// // .
// // .
// // .
// │ segment // . │ segment
// │ │ // . │ │
// │ │ ceil // . │ │ ceil
// │ │ │ // . │ │ │
// │ │ // . │ │
// floor │ │ // . floor │ │
// // .
// // .
// // .
// // .
// NOTE: the assumption is that all segments given are orthogonal // NOTE: the assumption is that all segments given are orthogonal
func (segment *Segment) GetBounds(segments []*Segment, buffer float64) (float64, float64) { func (segment *Segment) GetBounds(segments []*Segment, buffer float64) (float64, float64) {
ceil := math.Inf(1) ceil := math.Inf(1)

View file

@ -175,22 +175,22 @@ func NewShape(shapeType string, box *geo.Box) Shape {
// p is the prev point (used to calculate slope) // p is the prev point (used to calculate slope)
// s is the point on the actual shape border that'll be returned // s is the point on the actual shape border that'll be returned
// //
// p // . p
// // .
// // .
// // .
// ┌────r─────────────────────────┐ // . ┌────r─────────────────────────┐
// │ │ // . │ │
// │ │ │ // . │ │ │
// │ │ xxxxxxxx │ // . │ │ xxxxxxxx │
// │ ▼ xxxxx xxxx │ // . │ ▼ xxxxx xxxx │
// │ sxxx xx │ // . │ sxxx xx │
// │ x xx │ // . │ x xx │
// │ xx xx │ // . │ xx xx │
// │ x xx │ // . │ x xx │
// │ xx xxx │ // . │ xx xxx │
// │ xxxx xxxx │ // . │ xxxx xxxx │
// └──────xxxxxxxxxxxxxx──────────┘ // . └──────xxxxxxxxxxxxxx──────────┘
func TraceToShapeBorder(shape Shape, rectBorderPoint, prevPoint *geo.Point) *geo.Point { func TraceToShapeBorder(shape Shape, rectBorderPoint, prevPoint *geo.Point) *geo.Point {
if shape.Is("") || shape.IsRectangular() { if shape.Is("") || shape.IsRectangular() {
return rectBorderPoint return rectBorderPoint

View file

@ -32,23 +32,27 @@ func init() {
// Ruler allows for effiecient and convenient text drawing. // Ruler allows for effiecient and convenient text drawing.
// //
// To create a Ruler object, use the New constructor: // To create a Ruler object, use the New constructor:
// txt := text.New(pixel.ZV, text.NewAtlas(face, text.ASCII)) //
// txt := text.New(pixel.ZV, text.NewAtlas(face, text.ASCII))
// //
// As suggested by the constructor, a Ruler object is always associated with one font face and a // As suggested by the constructor, a Ruler object is always associated with one font face and a
// fixed set of runes. For example, the Ruler we created above can draw text using the font face // fixed set of runes. For example, the Ruler we created above can draw text using the font face
// contained in the face variable and is capable of drawing ASCII characters. // contained in the face variable and is capable of drawing ASCII characters.
// //
// Here we create a Ruler object which can draw ASCII and Katakana characters: // Here we create a Ruler object which can draw ASCII and Katakana characters:
// txt := text.New(0, text.NewAtlas(face, text.ASCII, text.RangeTable(unicode.Katakana))) //
// txt := text.New(0, text.NewAtlas(face, text.ASCII, text.RangeTable(unicode.Katakana)))
// //
// Similarly to IMDraw, Ruler functions as a buffer. It implements io.Writer interface, so writing // Similarly to IMDraw, Ruler functions as a buffer. It implements io.Writer interface, so writing
// text to it is really simple: // text to it is really simple:
// fmt.Print(txt, "Hello, world!") //
// fmt.Print(txt, "Hello, world!")
// //
// Newlines, tabs and carriage returns are supported. // Newlines, tabs and carriage returns are supported.
// //
// Finally, if we want the written text to show up on some other Target, we can draw it: // Finally, if we want the written text to show up on some other Target, we can draw it:
// txt.Draw(target) //
// txt.Draw(target)
// //
// Ruler exports two important fields: Orig and Dot. Dot is the position where the next character // Ruler exports two important fields: Orig and Dot. Dot is the position where the next character
// will be written. Dot is automatically moved when writing to a Ruler object, but you can also // will be written. Dot is automatically moved when writing to a Ruler object, but you can also
@ -93,14 +97,15 @@ type Ruler struct {
// will be initially set to orig. // will be initially set to orig.
// //
// Here we create a Ruler capable of drawing ASCII characters using the Go Regular font. // Here we create a Ruler capable of drawing ASCII characters using the Go Regular font.
// ttf, err := truetype.Parse(goregular.TTF) //
// if err != nil { // ttf, err := truetype.Parse(goregular.TTF)
// panic(err) // if err != nil {
// } // panic(err)
// face := truetype.NewFace(ttf, &truetype.Options{ // }
// Size: 14, // face := truetype.NewFace(ttf, &truetype.Options{
// }) // Size: 14,
// txt := text.New(orig, text.NewAtlas(face, text.ASCII)) // })
// txt := text.New(orig, text.NewAtlas(face, text.ASCII))
func NewRuler() (*Ruler, error) { func NewRuler() (*Ruler, error) {
origin := geo.NewPoint(0, 0) origin := geo.NewPoint(0, 0)
r := &Ruler{ r := &Ruler{