Skip to content

Commit

Permalink
feat: add unused linter (gnolang#1294)
Browse files Browse the repository at this point in the history
## Description

This PR adds the `unused` linter to the linter configuration, and
removes unused code segments

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
  • Loading branch information
zivkovicmilos authored and moul committed Nov 14, 2023
1 parent da1c349 commit c3774a9
Show file tree
Hide file tree
Showing 52 changed files with 89 additions and 787 deletions.
27 changes: 24 additions & 3 deletions .github/golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
run:
timeout: 5m
concurrency: 8
timeout: 10m
issue-exit-code: 1
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly
allow-parallel-runners: false
go: ""

output:
uniq-by-line: false
path-prefix: ""
sort-results: true

linters:
fast: false
disable-all: true
enable:
- whitespace # Tool for detection of leading and trailing whitespace
Expand All @@ -21,12 +32,11 @@ linters:
- gofmt # Whether the code was gofmt-ed
- goimports # Unused imports
- goconst # Repeated strings that could be replaced by a constant
#- forcetypeassert # Finds forced type assertions
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
#- dupl # Code clone detection
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13
- gofumpt # Stricter gofmt
- unused # Checks Go code for unused constants, variables, functions and types

linters-settings:
gofmt:
Expand All @@ -42,9 +52,20 @@ linters-settings:
checks: [ "all", "-ST1022", "-ST1003" ]
errorlint:
asserts: false
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style

issues:
whole-files: true
max-issues-per-linter: 0
max-same-issues: 0
new: false
fix: false
exclude-rules:
- path: _test\.go
linters:
Expand Down
12 changes: 0 additions & 12 deletions gnovm/pkg/gnolang/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,6 @@ var (
precs = [][]string{prec1, prec2, prec3, prec4, prec5}
)

// 0 for prec1... -1 if no match.
func lowestMatch(op string) int {
for i, prec := range precs {
for _, op2 := range prec {
if op == op2 {
return i
}
}
}
return -1
}

func Ss(b ...Stmt) []Stmt {
return b
}
Expand Down
24 changes: 0 additions & 24 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -3338,23 +3338,6 @@ func elideCompositeExpr(vx *Expr, vt Type) {
}
}

// returns true of x is exactly `nil`.
func isNilExpr(x Expr) bool {
if nx, ok := x.(*NameExpr); ok {
return nx.Name == nilStr
}
return false
}

func isNilComparableKind(k Kind) bool {
switch k {
case SliceKind, MapKind, FuncKind:
return true
default:
return false
}
}

// returns number of args, or if arg is a call result,
// the number of results of the return tuple type.
func countNumArgs(store Store, last BlockNode, n *CallExpr) (numArgs int) {
Expand All @@ -3374,13 +3357,6 @@ func countNumArgs(store Store, last BlockNode, n *CallExpr) (numArgs int) {
}
}

func mergeNames(a, b []Name) []Name {
c := make([]Name, len(a)+len(b))
copy(c, a)
copy(c[len(a):], b)
return c
}

// This is to be run *after* preprocessing is done,
// to determine the order of var decl execution
// (which may include functions which may refer to package vars).
Expand Down
18 changes: 0 additions & 18 deletions gnovm/pkg/gnolang/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,3 @@ func (ss *scanner) advanceEscapeSequence() bool {
return ss.done()
}
}

// pops the next monoid term.
// The result is a string enclosed in balanced parentheses,
// brackets, or quotes; or what comes before such things.
// scanner doesn't understand operators, so a polynomial
// expression could be a single monoid as far as this scanner
// is concerned. TODO Chop functions should maybe use this.
func (ss *scanner) popMonoid() string {
startOut := ss.out()
start := ss.idx
for !ss.advance() {
if ss.out() != startOut {
end := ss.idx
return string(ss.rnz[start:end])
}
}
panic("no monoid")
}
8 changes: 3 additions & 5 deletions gnovm/pkg/gnolang/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/gnolang/gno/tm2/pkg/store"
)

const iavlCacheSize = 1024 * 1024 // TODO increase and parameterize.

// return nil if package doesn't exist.
type PackageGetter func(pkgPath string) (*PackageNode, *PackageValue)

Expand Down Expand Up @@ -626,7 +624,7 @@ func (ds *defaultStore) Flush() {
// XXX
}

//----------------------------------------
// ----------------------------------------
// StoreOp

type StoreOpType uint8
Expand Down Expand Up @@ -723,7 +721,7 @@ func (ds *defaultStore) Print() {
}
}

//----------------------------------------
// ----------------------------------------
// backend keys

func backendObjectKey(oid ObjectID) string {
Expand Down Expand Up @@ -755,7 +753,7 @@ func backendPackagePathKey(path string) string {
return fmt.Sprintf("pkg:" + path)
}

//----------------------------------------
// ----------------------------------------
// builtin types and packages

func InitStoreCaches(store Store) {
Expand Down
1 change: 0 additions & 1 deletion gnovm/pkg/gnolang/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,6 @@ type InterfaceType struct {
}

// General empty interface.
var gEmptyInterfaceType *InterfaceType = &InterfaceType{}

func (it *InterfaceType) IsEmptyInterface() bool {
return len(it.Methods) == 0
Expand Down
10 changes: 0 additions & 10 deletions gnovm/stdlibs/stdlibs.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,3 @@ func typedByteArray(ln int, bz *gno.ArrayValue) gno.TypedValue {
tv := gno.TypedValue{T: &gno.ArrayType{Len: ln, Elt: gno.Uint8Type}, V: bz}
return tv
}

func typedByteSlice(bz *gno.SliceValue) gno.TypedValue {
tv := gno.TypedValue{T: &gno.SliceType{Elt: gno.Uint8Type}, V: bz}
return tv
}

func typedNil(t gno.Type) gno.TypedValue {
tv := gno.TypedValue{T: t, V: nil}
return tv
}
12 changes: 4 additions & 8 deletions misc/logos/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/gdamore/tcell/v2"
)

//----------------------------------------
// ----------------------------------------
// Buffer

// A Buffer is a buffer area in which to draw.
Expand Down Expand Up @@ -82,7 +82,7 @@ func (bb *Buffer) DrawToScreen(s tcell.Screen) {
}
}

//----------------------------------------
// ----------------------------------------
// Cell

// A terminal character cell.
Expand Down Expand Up @@ -131,10 +131,6 @@ var gDefaultSpaceTStyle = tcell.StyleDefault.
Dim(true).
Background(tcell.ColorGray)

var gDefaultTStyle = gDefaultStyle.GetTStyle().
Foreground(gDefaultForeground).
Background(gDefaultBackground)

// This is where a bit of dynamic logic is performed,
// namely where the attr is used to derive the final style.
func (cc *Cell) GetTCellContent() (mainc rune, combc []rune, tstyle tcell.Style) {
Expand All @@ -161,7 +157,7 @@ func (cc *Cell) GetTCellContent() (mainc rune, combc []rune, tstyle tcell.Style)
return
}

//----------------------------------------
// ----------------------------------------
// View
// analogy: "Buffer:View :: array:slice".

Expand Down Expand Up @@ -205,7 +201,7 @@ func (bs View) GetCell(x, y int) *Cell {
)
}

//----------------------------------------
// ----------------------------------------
// BufferedView

// A view onto an element.
Expand Down
5 changes: 0 additions & 5 deletions misc/logos/cmd/logos.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import (
"github.com/gnolang/gno/misc/logos"
)

var (
row = 0
style = tcell.StyleDefault
)

func main() {
encoding.Register()

Expand Down
26 changes: 0 additions & 26 deletions misc/logos/debug.go

This file was deleted.

14 changes: 6 additions & 8 deletions misc/logos/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/gdamore/tcell/v2"
)

//----------------------------------------
// ----------------------------------------
// Page

// A Page has renderable Elem(ents).
Expand Down Expand Up @@ -389,7 +389,7 @@ func (pg *Page) DecCursor(isVertical bool) {
}
}

//----------------------------------------
// ----------------------------------------
// TextElem

type TextElem struct {
Expand Down Expand Up @@ -474,8 +474,6 @@ func (tel *TextElem) Render() (updated bool) {
return true
}

var ctr = 0

func (tel *TextElem) Draw(offset Coord, view View) {
minX, maxX, minY, maxY := computeIntersection(tel.Size, offset, view.Bounds)
for y := minY; y < maxY; y++ {
Expand All @@ -494,7 +492,7 @@ func (tel *TextElem) ProcessEventKey(ev *EventKey) bool {
return false // TODO: clipboard.
}

//----------------------------------------
// ----------------------------------------
// misc.

type Color = tcell.Color
Expand Down Expand Up @@ -728,7 +726,7 @@ func (tt *Attrs) Merge(ot *Attrs) {
tt.Other = ot.Other // TODO merge by key.
}

//----------------------------------------
// ----------------------------------------
// AttrFlags

// NOTE: AttrFlags are merged with a simple or-assign op.
Expand All @@ -752,7 +750,7 @@ type KVPair struct {
Value interface{}
}

//----------------------------------------
// ----------------------------------------
// computeIntersection()

// els: element size
Expand Down Expand Up @@ -812,7 +810,7 @@ func computeIntersection(els Size, elo Coord, vws Size) (minX, maxX, minY, maxY
return
}

//----------------------------------------
// ----------------------------------------
// Misc simple types

type Padding struct {
Expand Down
11 changes: 1 addition & 10 deletions misc/logos/unicode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ func isCombining(r rune) bool {
return inTable(r, combining)
}

//----------------------------------------
// ----------------------------------------
// from https://github.com/mattn/go-runewidth
// runewidth doesn't expose whether a character is combining or not.
// TODO might as well fork both runewidth and tcell.
Expand Down Expand Up @@ -62,15 +62,6 @@ type interval struct {

type table []interval

func inTables(r rune, ts ...table) bool {
for _, t := range ts {
if inTable(r, t) {
return true
}
}
return false
}

func inTable(r rune, t table) bool {
if r < t[0].first {
return false
Expand Down
8 changes: 0 additions & 8 deletions tm2/pkg/amino/binary_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ const bdOptionByte = 0x01
// ----------------------------------------
// cdc.decodeReflectBinary

var ErrOverflowInt = errors.New("encoded integer value overflows int(32)")

const (
// architecture dependent int limits:
maxInt = int(^uint(0) >> 1)
minInt = -maxInt - 1
)

// This is the main entrypoint for decoding all types from binary form. This
// function calls decodeReflectBinary*, and generally those functions should
// only call this one, for overrides all happen here.
Expand Down
3 changes: 0 additions & 3 deletions tm2/pkg/amino/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ func TestEncodeDecodeString(t *testing.T) {
}

func TestCodecSeal(t *testing.T) {
type Foo interface{}
type Bar interface{}

cdc := amino.NewCodec()
cdc.Seal()

Expand Down
Loading

0 comments on commit c3774a9

Please sign in to comment.