Skip to content

Commit

Permalink
chore: update linters and enable some linters (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre authored May 13, 2024
1 parent 34f0b99 commit 1a49150
Show file tree
Hide file tree
Showing 159 changed files with 585 additions and 552 deletions.
79 changes: 71 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,83 @@ linters:
- whitespace
# - wrapcheck
- zerologlint
- nonamedreturns

linters-settings:
gosimple:
checks: ["all"]

revive:
enable-all-rules: true
rules:
- name: "exported"
# TODO: Enable me
# all exported function should have comment.
disabled: true

# TODO: Enable me
- name: package-comments
disabled: true

- name: "add-constant"
disabled: true

- name: "line-length-limit"
disabled: true

- name: "cognitive-complexity"
disabled: true

- name: "function-length"
disabled: true

- name: "cyclomatic"
disabled: true

- name: "unchecked-type-assertion"
disabled: true

- name: max-public-structs
disabled: true

- name: "flag-parameter"
disabled: true

- name: "deep-exit"
disabled: true

- name: "get-return"
disabled: true

- name: "function-result-limit"
disabled: true

- name: unhandled-error
arguments:
- "fmt.Printf"
- "fmt.Println"
- "fmt.Fprintf"
- "strings.Builder.WriteString"
- "strings.Builder.WriteRune"
- "strings.Builder.WriteByte"
- "bytes.Buffer.Write"
- "bytes.Buffer.WriteString"

gosec:
excludes:
- G304
- G204
- G103 # TODO: enable me

stylecheck:
# TODO: enable ST1000 (at least one file in a package should have a package comment)
checks: ["all", "-ST1000"]

govet:
enable-all: true
disable: fieldalignment
shadow:
disable: ["fieldalignment"]

settings:
shadow:
strict: true

predeclared:
Expand All @@ -104,11 +171,6 @@ linters-settings:
json: snake
yaml: snake

nonamedreturns:
# Report named error if it is assigned inside defer.
# Default: false
report-error-in-defer: false

gocritic:
disabled-checks:
- ifElseChain
Expand All @@ -124,6 +186,7 @@ linters-settings:
min-complexity: 6

issues:
exclude-use-default: false
exclude-rules:
- path: _test.go
linters:
Expand Down
18 changes: 12 additions & 6 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func FatalErrorCheck(err error) {
}
}

func PrintErrorMsgf(format string, a ...interface{}) {
func PrintErrorMsgf(format string, a ...any) {
format = "[ERROR] " + format
if terminalSupported {
// Print error msg with red color
Expand All @@ -183,27 +183,27 @@ func PrintErrorMsgf(format string, a ...interface{}) {
fmt.Printf(format+"\n", a...)
}

func PrintSuccessMsgf(format string, a ...interface{}) {
func PrintSuccessMsgf(format string, a ...any) {
if terminalSupported {
// Print successful msg with green color
format = fmt.Sprintf("\033[32m%s\033[0m", format)
}
fmt.Printf(format+"\n", a...)
}

func PrintWarnMsgf(format string, a ...interface{}) {
func PrintWarnMsgf(format string, a ...any) {
if terminalSupported {
// Print warning msg with yellow color
format = fmt.Sprintf("\033[33m%s\033[0m", format)
}
fmt.Printf(format+"\n", a...)
}

func PrintInfoMsgf(format string, a ...interface{}) {
func PrintInfoMsgf(format string, a ...any) {
fmt.Printf(format+"\n", a...)
}

func PrintInfoMsgBoldf(format string, a ...interface{}) {
func PrintInfoMsgBoldf(format string, a ...any) {
if terminalSupported {
format = fmt.Sprintf("\033[1m%s\033[0m", format)
}
Expand All @@ -222,7 +222,7 @@ func PrintJSONData(data []byte) {
PrintInfoMsgf(out.String())
}

func PrintJSONObject(obj interface{}) {
func PrintJSONObject(obj any) {
data, err := json.Marshal(obj)
FatalErrorCheck(err)

Expand Down Expand Up @@ -354,6 +354,9 @@ func CreateNode(numValidators int, chain genesis.ChainType, workingDir string,
return validatorAddrs, rewardAddrs, nil
}

// StartNode starts the node from the given working directory.
// The passwordFetcher will be used to fetch the password for the default_wallet if it is encrypted.
// It returns an error if the genesis doc or default_wallet can't be found inside the working directory.
// TODO: write test for me.
func StartNode(workingDir string, passwordFetcher func(*wallet.Wallet) (string, bool)) (
*node.Node, *wallet.Wallet, error,
Expand Down Expand Up @@ -447,6 +450,9 @@ func makeLocalGenesis(w wallet.Wallet) *genesis.Genesis {
return gen
}

// MakeConfig opens the given config file and creates the appropriate configuration per chain type.
// The chain type is determined from the genesis document.
// It also updates some private configurations, like "wallets directory".
// TODO: write test for me.
func MakeConfig(genDoc *genesis.Genesis, confPath, walletsDir string) (*config.Config, error) {
var defConf *config.Config
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func captureOutput(f func()) string {
f()

// Reset stdout
w.Close()
_ = w.Close()
os.Stdout = oldStdout
out := <-outC

Expand Down
2 changes: 1 addition & 1 deletion cmd/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"time"

flock "github.com/gofrs/flock"
"github.com/gofrs/flock"
"github.com/pactus-project/pactus/cmd"
"github.com/pactus-project/pactus/wallet"
"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_address_change_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func changePassword(wlt *wallet.Wallet) {

// Map the handlers to callback functions, and connect the signals
// to the Builder.
signals := map[string]interface{}{
signals := map[string]any{
"on_ok": onOk,
"on_cancel": onCancel,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_addresss_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func showAddressDetails(wlt *wallet.Wallet, addr string) {
dlg.Close()
}

signals := map[string]interface{}{
signals := map[string]any{
"on_close": onClose,
}
builder.ConnectSignals(signals)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_addresss_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func getAddressLabel(oldLabel string) (string, bool) {

// Map the handlers to callback functions, and connect the signals
// to the Builder.
signals := map[string]interface{}{
signals := map[string]any{
"on_ok": onOk,
"on_cancel": onCancel,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_addresss_private_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func showAddressPrivateKey(wlt *wallet.Wallet, addr string) {
dlg.Close()
}

signals := map[string]interface{}{
signals := map[string]any{
"on_close": onClose,
}
builder.ConnectSignals(signals)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_transaction_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Memo: %s
dlg.Close()
}

signals := map[string]interface{}{
signals := map[string]any{
"on_sender_changed": onSenderChanged,
"on_receiver_changed": onReceiverChanged,
"on_amount_changed": onAmountChanged,
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_transaction_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Memo: %s
dlg.Close()
}

signals := map[string]interface{}{
signals := map[string]any{
"on_sender_changed": onSenderChanged,
"on_receiver_changed": onReceiverChanged,
"on_amount_changed": onAmountChanged,
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_transaction_unbond.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Memo: %s
dlg.Close()
}

signals := map[string]interface{}{
signals := map[string]any{
"on_validator_changed": onValidatorChanged,
"on_send": onSend,
"on_cancel": onClose,
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_transaction_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Fee: %s
dlg.Close()
}

signals := map[string]interface{}{
signals := map[string]any{
"on_sender_changed": onSenderChanged,
"on_receiver_changed": onReceiverChanged,
"on_amount_changed": onAmountChanged,
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_wallet_create_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func createAddress(ww *widgetWallet) {

// Map the handlers to callback functions, and connect the signals
// to the Builder.
signals := map[string]interface{}{
signals := map[string]any{
"on_ok": onOk,
"on_cancel": onCancel,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_wallet_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func getWalletPassword(wlt *wallet.Wallet) (string, bool) {

// Map the handlers to callback functions, and connect the signals
// to the Builder.
signals := map[string]interface{}{
signals := map[string]any{
"on_ok": onOk,
"on_cancel": onCancel,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_wallet_show_seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func showSeed(seed string) {
dlg.Close()
}

signals := map[string]interface{}{
signals := map[string]any{
"on_close": onClose,
}
builder.ConnectSignals(signals)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"path/filepath"

flock "github.com/gofrs/flock"
"github.com/gofrs/flock"
"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
Expand Down
12 changes: 6 additions & 6 deletions cmd/gtk/main_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func buildMainWindow(nodeModel *nodeModel, walletModel *walletModel) *mainWindow

// Map the handlers to callback functions, and connect the signals
// to the Builder.
signals := map[string]interface{}{
signals := map[string]any{
"on_about_gtk": mw.onAboutGtk,
"on_about": mw.onAbout,
"on_quit": mw.onQuit,
Expand Down Expand Up @@ -87,11 +87,11 @@ func (mw *mainWindow) onQuit() {
mw.Close()
}

func (mw *mainWindow) onAboutGtk() {
func (*mainWindow) onAboutGtk() {
showAboutGTKDialog()
}

func (mw *mainWindow) onAbout() {
func (*mainWindow) onAbout() {
dlg := aboutDialog()
dlg.ShowAll()
}
Expand All @@ -112,19 +112,19 @@ func (mw *mainWindow) OnTransactionWithdraw() {
broadcastTransactionWithdraw(mw.widgetWallet.model.wallet)
}

func (mw *mainWindow) onMenuItemActivateWebsite(_ *gtk.MenuItem) {
func (*mainWindow) onMenuItemActivateWebsite(_ *gtk.MenuItem) {
if err := openURLInBrowser("https://pactus.org/"); err != nil {
fatalErrorCheck(err)
}
}

func (mw *mainWindow) onMenuItemActivateExplorer(_ *gtk.MenuItem) {
func (*mainWindow) onMenuItemActivateExplorer(_ *gtk.MenuItem) {
if err := openURLInBrowser("https://pacviewer.com/"); err != nil {
fatalErrorCheck(err)
}
}

func (mw *mainWindow) onMenuItemActivateLearn(_ *gtk.MenuItem) {
func (*mainWindow) onMenuItemActivateLearn(_ *gtk.MenuItem) {
if err := openURLInBrowser("https://pactus.org/learn/"); err != nil {
fatalErrorCheck(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/model_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (model *walletModel) rebuildModel() {
IDAddressesColumnStake,
IDAddressesColumnAvailabilityScore,
},
[]interface{}{
[]any{
d[0],
d[1],
d[2],
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func updateMessageDialog(dlg *gtk.MessageDialog) {
area, err := dlg.GetMessageArea()
if err == nil {
children := area.GetChildren()
children.Foreach(func(item interface{}) {
children.Foreach(func(item any) {
label, err := gtk.WidgetToLabel(item.(*gtk.Widget))
if err == nil {
label.SetSelectable(true)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/widget_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func buildWidgetNode(model *nodeModel) (*widgetNode, error) {
labelReachability: getLabelObj(builder, "id_label_reachability"),
}

signals := map[string]interface{}{}
signals := map[string]any{}
builder.ConnectSignals(signals)

glib.TimeoutAdd(1000, w.timeout1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/widget_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func buildWidgetWallet(model *walletModel) (*widgetWallet, error) {
return false
})

signals := map[string]interface{}{
signals := map[string]any{
"on_new_address": w.onNewAddress,
"on_change_password": w.onChangePassword,
"on_show_seed": w.onShowSeed,
Expand Down
Loading

0 comments on commit 1a49150

Please sign in to comment.