Skip to content

Commit a25ee37

Browse files
authored
Update interface{} to any (#202)
1 parent 3543e41 commit a25ee37

File tree

9 files changed

+14
-15
lines changed

9 files changed

+14
-15
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,3 @@ fmt: ./bin/gci
8383

8484
./bin/gci:
8585
GOBIN=$(shell pwd)/bin go install github.com/daixiang0/[email protected]
86-

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ A table is defined by a list of `Column` values that define the columns in the
7676
table. Each `Column` is associated with a unique string key.
7777

7878
A table contains a list of `Row`s. Each `Row` contains a `RowData` object which
79-
is simply a map of string column IDs to arbitrary `interface{}` data values.
79+
is simply a map of string column IDs to arbitrary `any` data values.
8080
When the table is rendered, each `Row` is checked for each `Column` key. If the
8181
key exists in the `Row`'s `RowData`, it is rendered with `fmt.Sprintf("%v")`.
8282
If it does not exist, nothing is rendered.

table/cell.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import "github.com/charmbracelet/lipgloss"
88
// limited to colors, font style, and alignments - spacing style such as margin
99
// will break the table format.
1010
type StyledCell struct {
11-
Data interface{}
11+
Data any
1212
Style lipgloss.Style
1313
}
1414

1515
// NewStyledCell creates an entry that can be set in the row data and show as
1616
// styled with the given style.
17-
func NewStyledCell(data interface{}, style lipgloss.Style) StyledCell {
17+
func NewStyledCell(data any, style lipgloss.Style) StyledCell {
1818
return StyledCell{data, style}
1919
}

table/column.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (c Column) WithFiltered(filterable bool) Column {
6464
// If not set, the default is "%v" for all data types. Intended mainly for
6565
// numeric formatting.
6666
//
67-
// Since data is of the interface{} type, make sure that all data in the column
67+
// Since data is of the any type, make sure that all data in the column
6868
// is of the expected type or the format may fail. For example, hardcoding '3'
6969
// instead of '3.0' and using '%.2f' will fail because '3' is an integer.
7070
func (c Column) WithFormatString(fmtString string) Column {

table/data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "time"
55
// This is just a bunch of data type checks, so... no linting here
66
//
77
//nolint:cyclop
8-
func asInt(data interface{}) (int64, bool) {
8+
func asInt(data any) (int64, bool) {
99
switch val := data.(type) {
1010
case int:
1111
return int64(val), true
@@ -49,7 +49,7 @@ func asInt(data interface{}) (int64, bool) {
4949
return 0, false
5050
}
5151

52-
func asNumber(data interface{}) (float64, bool) {
52+
func asNumber(data any) (float64, bool) {
5353
switch val := data.(type) {
5454
case float32:
5555
return float64(val), true

table/data_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestAsInt(t *testing.T) {
11-
check := func(data interface{}, isInt bool, expectedValue int64) {
11+
check := func(data any, isInt bool, expectedValue int64) {
1212
val, ok := asInt(data)
1313
assert.Equal(t, isInt, ok)
1414
assert.Equal(t, expectedValue, val)
@@ -30,7 +30,7 @@ func TestAsInt(t *testing.T) {
3030
}
3131

3232
func TestAsNumber(t *testing.T) {
33-
check := func(data interface{}, isFloat bool, expectedValue float64) {
33+
check := func(data any, isFloat bool, expectedValue float64) {
3434
val, ok := asNumber(data)
3535
assert.Equal(t, isFloat, ok)
3636
assert.InDelta(t, expectedValue, val, 0.001)

table/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package table
33
// UserEvent is some state change that has occurred due to user input. These will
44
// ONLY be generated when a user has interacted directly with the table. These
55
// will NOT be generated when code programmatically changes values in the table.
6-
type UserEvent interface{}
6+
type UserEvent any
77

88
func (m *Model) appendUserEvent(e UserEvent) {
99
m.lastUpdateUserEvents = append(m.lastUpdateUserEvents, e)

table/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Model struct {
2626
visibleRowCache []Row
2727

2828
// Shown when data is missing from a row
29-
missingDataIndicator interface{}
29+
missingDataIndicator any
3030

3131
// Interaction
3232
focused bool

table/row.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
"github.com/muesli/reflow/wordwrap"
99
)
1010

11-
// RowData is a map of string column keys to interface{} data. Data with a key
11+
// RowData is a map of string column keys to arbitrary data. Data with a key
1212
// that matches a column key will be displayed. Data with a key that does not
1313
// match a column key will not be displayed, but will remain attached to the Row.
1414
// This can be useful for attaching hidden metadata for future reference when
1515
// retrieving rows.
16-
type RowData map[string]interface{}
16+
type RowData map[string]any
1717

1818
// Row represents a row in the table with some data keyed to the table columns>
1919
// Can have a style applied to it such as color/bold. Create using NewRow().
@@ -32,7 +32,7 @@ var lastRowID uint32 = 1
3232
// NewRow creates a new row and copies the given row data.
3333
func NewRow(data RowData) Row {
3434
row := Row{
35-
Data: make(map[string]interface{}),
35+
Data: make(map[string]any),
3636
id: lastRowID,
3737
}
3838

@@ -74,7 +74,7 @@ func (m Model) renderRowColumnData(row Row, column Column, rowStyle lipgloss.Sty
7474
default:
7575
fmtString := "%v"
7676

77-
var data interface{}
77+
var data any
7878

7979
if entry, exists := row.Data[column.key]; exists {
8080
data = entry

0 commit comments

Comments
 (0)