Skip to content

Commit 3577a4a

Browse files
committed
all: modernize Go usage
This commit modernizes Go usage. This was done with: ``` $> go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... ``` Signed-off-by: Sebastien Binet <[email protected]>
1 parent 9515ee8 commit 3577a4a

28 files changed

+72
-69
lines changed

align.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ func Align(plots [][]*Plot, t draw.Tiles, dc draw.Canvas) [][]draw.Canvas {
2525
}
2626

2727
// Create the initial tiles.
28-
for j := 0; j < t.Rows; j++ {
28+
for j := range t.Rows {
2929
if len(plots[j]) != t.Cols {
3030
panic(fmt.Errorf("plot: plots row %d columns (%d) != tiles columns (%d)", j, len(plots[j]), t.Rows))
3131
}
3232

3333
o[j] = make([]draw.Canvas, len(plots[j]))
34-
for i := 0; i < t.Cols; i++ {
34+
for i := range t.Cols {
3535
o[j][i] = t.At(dc, i, j)
3636
}
3737
}

align_example_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
func ExampleAlign() {
1919
const rows, cols = 4, 3
2020
plots := make([][]*plot.Plot, rows)
21-
for j := 0; j < rows; j++ {
21+
for j := range rows {
2222
plots[j] = make([]*plot.Plot, cols)
23-
for i := 0; i < cols; i++ {
23+
for i := range cols {
2424
if i == 0 && j == 2 {
2525
// This shows what happens when there are nil plots.
2626
continue
@@ -70,8 +70,8 @@ func ExampleAlign() {
7070
}
7171

7272
canvases := plot.Align(plots, t, dc)
73-
for j := 0; j < rows; j++ {
74-
for i := 0; i < cols; i++ {
73+
for j := range rows {
74+
for i := range cols {
7575
if plots[j][i] != nil {
7676
plots[j][i].Draw(canvases[j][i])
7777
}

palette/brewer/brewer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func GetPalette(typ PaletteType, name string, colors int) (palette.Palette, erro
125125
)
126126
switch typ {
127127
case TypeAny:
128-
var pt interface{}
128+
var pt any
129129
pt, nameOk = all[name]
130130
if !nameOk {
131131
break

palette/brewer/palettes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4752,7 +4752,7 @@ var (
47524752
"YlOrBr": YlOrBr,
47534753
"YlOrRd": YlOrRd,
47544754
}
4755-
all = map[string]interface{}{
4755+
all = map[string]any{
47564756
"BrBG": BrBG,
47574757
"PiYG": PiYG,
47584758
"PRGn": PRGn,

palette/moreland/example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func Example() {
5353
YOffset: -50,
5454
Data: mat.NewDense(100, 100, nil),
5555
}
56-
for i := 0; i < 100; i++ {
57-
for j := 0; j < 100; j++ {
56+
for i := range 100 {
57+
for j := range 100 {
5858
x := float64(i-50) / 10
5959
y := float64(j-50) / 10
6060
v := math.Sin(x*x+y*y) / (x*x + y*y)

palette/moreland/luminance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (l luminance) Palette(n int) palette.Palette {
178178
delta := (l.max - l.min) / float64(n-1)
179179
var v float64
180180
c := make([]color.Color, n)
181-
for i := 0; i < n; i++ {
181+
for i := range n {
182182
v = l.min + float64(delta*float64(i))
183183
var err error
184184
c[i], err = l.At(v)

plotter/barchart_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func ExampleBarChart_positiveNegative() {
165165
data1 := make(plotter.Values, n)
166166
data2 := make(plotter.Values, n)
167167
net := make(plotter.XYs, n) // net = data1 + data2
168-
for i := 0; i < n; i++ {
168+
for i := range n {
169169
data1[i] = rnd.Float64()*2 - 1
170170
data2[i] = rnd.Float64()*2 - 1
171171
net[i].X = data1[i] + data2[i]

plotter/boxplot_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func ExampleBoxPlot() {
2424
uniform := make(plotter.ValueLabels, n)
2525
normal := make(plotter.ValueLabels, n)
2626
expon := make(plotter.ValueLabels, n)
27-
for i := 0; i < n; i++ {
27+
for i := range n {
2828
uniform[i].Value = rnd.Float64()
2929
uniform[i].Label = fmt.Sprintf("%4.4f", uniform[i].Value)
3030
normal[i].Value = rnd.NormFloat64()

plotter/colorbar.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (l *ColorBar) Plot(c draw.Canvas, p *plot.Plot) {
6262
Min: image.Point{X: 0, Y: 0},
6363
Max: image.Point{X: 1, Y: colors},
6464
})
65-
for i := 0; i < colors; i++ {
65+
for i := range colors {
6666
color, err := l.ColorMap.At(l.ColorMap.Min() + delta*float64(i))
6767
if err != nil {
6868
panic(err)
@@ -75,7 +75,7 @@ func (l *ColorBar) Plot(c draw.Canvas, p *plot.Plot) {
7575
Min: image.Point{X: 0, Y: 0},
7676
Max: image.Point{X: colors, Y: 1},
7777
})
78-
for i := 0; i < colors; i++ {
78+
for i := range colors {
7979
color, err := l.ColorMap.At(l.ColorMap.Min() + delta*float64(i))
8080
if err != nil {
8181
panic(err)

plotter/conrec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ func conrec(g GridXYZ, heights []float64, fn conrecLine) {
7676
)
7777

7878
c, r := g.Dims()
79-
for i := 0; i < c-1; i++ {
80-
for j := 0; j < r-1; j++ {
79+
for i := range c - 1 {
80+
for j := range r - 1 {
8181
dmin := math.Min(
8282
math.Min(g.Z(i, j), g.Z(i, j+1)),
8383
math.Min(g.Z(i+1, j), g.Z(i+1, j+1)),
@@ -92,7 +92,7 @@ func conrec(g GridXYZ, heights []float64, fn conrecLine) {
9292
continue
9393
}
9494

95-
for k := 0; k < len(heights); k++ {
95+
for k := range heights {
9696
if heights[k] < dmin || dmax < heights[k] {
9797
continue
9898
}

0 commit comments

Comments
 (0)