Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lint): add lint make cmd, fix few lint issues #465

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ run:
timeout: 5m
concurrency: 4
tests: false
issues-exit-code: 2
skip-files:
- ".*\\.my\\.go$"

Expand All @@ -21,6 +20,10 @@ linters:
- exhaustive # same as exhaustivestruct and exhaustive
- testpackage # enforces test files to have _test package
- forbidigo # doesn't allow to use fmt.Println
# - inamedparam # forces to give names to interface params
- errorlint # doesn't understand wrapping correctly
- varnamelen # restricts names like wg, ok, ctx, etc
- ireturn # restricts returned interfaces
# deprecated:
- deadcode # replaced by unused
- cyclop # replaced by gocyclo
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ lsp:
tygo:
@tygo generate

# lint go code
# lint new go code
.PHONY: lint
lint:
@golangci-lint run ./... --new-from-rev=HEAD~1

# lint all go code
.PHONY: lintall
lint:
@golangci-lint run ./...
4 changes: 2 additions & 2 deletions cmd/lsp/server/general_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func (s *Server) Shutdown(context *glsp.Context) error {
return nil
}

func (srv Server) Exit(glspContext *glsp.Context) error {
func (s Server) Exit(_ *glsp.Context) error {
return nil
}

func (srv Server) SetTrace(context *glsp.Context, params *protocol.SetTraceParams) error {
func (s Server) SetTrace(_ *glsp.Context, params *protocol.SetTraceParams) error {
protocol.SetTraceValue(params.Value)
return nil
}
6 changes: 3 additions & 3 deletions cmd/lsp/server/get_file_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

type GetFileViewRequest struct {
WorkspaceUri URI `json:"workspaceUri"`
WorkspaceURI URI `json:"workspaceUri"`
Document struct {
Uri URI `json:"uri"`
URI URI `json:"uri"`
FileName string `json:"fileName"`
} `json:"document"`
}
Expand All @@ -35,7 +35,7 @@ func (s *Server) GetFileView(glspCtx *glsp.Context, req GetFileViewRequest) (Get
return GetFileViewResponce{}, nil
}

relFilePath := strings.TrimPrefix(req.Document.FileName, req.WorkspaceUri.Path)
relFilePath := strings.TrimPrefix(req.Document.FileName, req.WorkspaceURI.Path)
relFilePath = strings.TrimPrefix(relFilePath, "/")

relPathParts := strings.Split(relFilePath, "/") // relative path to file in slice
Expand Down
4 changes: 2 additions & 2 deletions cmd/lsp/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func BuildHandler(logger commonlog.Logger, serverName string, indexer indexer.In
}

// Basic
h.CancelRequest = func(context *glsp.Context, params *protocol.CancelParams) error {
h.CancelRequest = func(_ *glsp.Context, params *protocol.CancelParams) error {
return nil
}
h.Progress = func(context *glsp.Context, params *protocol.ProgressParams) error {
h.Progress = func(_ *glsp.Context, params *protocol.ProgressParams) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/neva/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newCliApp( //nolint:funlen
{
Name: "version",
Usage: "Get current Nevalang version",
Action: func(cCtx *cli.Context) error {
Action: func(_ *cli.Context) error {
fmt.Println(pkg.Version)
return nil
},
Expand Down
3 changes: 1 addition & 2 deletions cmd/neva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() { //nolint:funlen
)

// doesn't matter which compiler to use for interpreter
interp := newInterpreter(prsr, goCompiler, pkgMngr)
interp := newInterpreter(goCompiler, pkgMngr)

// command-line app that can compile and interpret neva code
app := newCliApp(
Expand All @@ -90,7 +90,6 @@ func main() { //nolint:funlen
}

func newInterpreter(
p parser.Parser,
c compiler.Compiler,
pkg pkgmanager.Manager,
) interpreter.Interpreter {
Expand Down
6 changes: 3 additions & 3 deletions internal/compiler/analyzer/main_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
ErrMainComponentNodeNotComponent = errors.New("Main component's nodes must only refer to components")
)

func (a Analyzer) analyzeMainComponent(cmp src.Component, pkg src.Package, scope src.Scope) *compiler.Error {
func (a Analyzer) analyzeMainComponent(cmp src.Component, scope src.Scope) *compiler.Error {
if len(cmp.Interface.TypeParams.Params) != 0 {
return &compiler.Error{
Err: ErrMainComponentWithTypeParams,
Expand All @@ -32,7 +32,7 @@ func (a Analyzer) analyzeMainComponent(cmp src.Component, pkg src.Package, scope
return compiler.Error{Meta: &cmp.Interface.Meta}.Merge(err)
}

if err := a.analyzeMainComponentNodes(cmp.Nodes, pkg, scope); err != nil {
if err := a.analyzeMainComponentNodes(cmp.Nodes, scope); err != nil {
return compiler.Error{Meta: &cmp.Meta}.Merge(err)
}

Expand Down Expand Up @@ -86,7 +86,7 @@ func (a Analyzer) analyzeMainComponentPort(port src.Port) error {
return nil
}

func (Analyzer) analyzeMainComponentNodes(nodes map[string]src.Node, pkg src.Package, scope src.Scope) *compiler.Error {
func (Analyzer) analyzeMainComponentNodes(nodes map[string]src.Node, scope src.Scope) *compiler.Error {
for nodeName, node := range nodes {
nodeEntity, loc, err := scope.Entity(node.EntityRef)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/compiler/analyzer/main_pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ func (a Analyzer) mainSpecificPkgValidation(mainPkgName string, mod src.Module,

scope = scope.WithLocation(*location)

if err := a.analyzeMainComponent(entityMain.Component, mainPkg, scope); err != nil {
if err := a.analyzeMainComponent(entityMain.Component, scope); err != nil {
return compiler.Error{
Location: location,
Meta: &entityMain.Component.Meta,
}.Merge(err)
}

if err := mainPkg.Entities(func(entity src.Entity, entityName, fileName string) error {
if err := mainPkg.Entities(func(entity src.Entity, entityName, _ string) error {
if entity.IsPublic {
return &compiler.Error{
Err: fmt.Errorf("%w: exported entity %v", ErrMainPkgExports, entityName),
Expand Down
5 changes: 2 additions & 3 deletions internal/compiler/desugarer/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (d Desugarer) desugarComponent( //nolint:funlen
desugaredNet := handleConnsResult.desugaredConns
maps.Copy(desugaredNodes, handleConnsResult.extraNodes)

unusedOutports := d.findUnusedOutports(component, scope, handleConnsResult.usedNodePorts, desugaredNodes, desugaredNet)
unusedOutports := d.findUnusedOutports(component, scope, handleConnsResult.usedNodePorts)
if unusedOutports.len() != 0 {
voidResult := d.getVoidNodeAndConns(unusedOutports)
desugaredNet = append(desugaredNet, voidResult.voidConns...)
Expand Down Expand Up @@ -163,7 +163,6 @@ func (d Desugarer) handleConns( //nolint:funlen
result, err := d.desugarStructSelectors(
conn,
nodes,
desugaredConns,
scope,
)
if err != nil {
Expand All @@ -188,7 +187,7 @@ func (d Desugarer) handleConns( //nolint:funlen
nodesToInsert[result.emitterNodeName] = result.emitterNode
conn = result.desugaredConn
} else if conn.SenderSide.Const.Value != nil {
result, err := d.handleLiteralSender(conn, scope)
result, err := d.handleLiteralSender(conn)
if err != nil {
return handleConnsResult{}, err
}
Expand Down
1 change: 0 additions & 1 deletion internal/compiler/desugarer/const_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var litSendersCount atomic.Uint32

func (d Desugarer) handleLiteralSender(
conn src.Connection,
scope src.Scope,
) (
handleLiteralSenderResult,
*compiler.Error,
Expand Down
2 changes: 0 additions & 2 deletions internal/compiler/desugarer/destructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ func (Desugarer) findUnusedOutports(
component src.Component,
scope src.Scope,
usedNodePorts nodePortsMap,
desugaredNodes map[string]src.Node,
desugaredNet []src.Connection,
) nodePortsMap {
unusedOutports := newNodePortsMap()
for nodeName, node := range component.Nodes {
Expand Down
8 changes: 4 additions & 4 deletions internal/compiler/desugarer/struct_selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var selectorNodeRef = src.EntityRef{
func (d Desugarer) desugarStructSelectors( //nolint:funlen
conn src.Connection,
nodes map[string]src.Node,
net []src.Connection,
scope src.Scope,
) (handleStructSelectorsResult, *compiler.Error) {
senderSide := conn.SenderSide
Expand Down Expand Up @@ -226,11 +225,12 @@ func (d Desugarer) getNodeOutportType(
}

var nodeIface src.Interface
if entity.Kind == src.InterfaceEntity {
switch entity.Kind {
case src.InterfaceEntity:
nodeIface = entity.Interface
} else if entity.Kind == src.ComponentEntity {
case src.ComponentEntity:
nodeIface = entity.Component.Interface
} else {
default:
return ts.Expr{}, &compiler.Error{
Err: fmt.Errorf("%w: %v", ErrOutportAddrNotFound, "node's entity found but it's not component or interface"),
Location: &location,
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/parser/err_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type CustomErrorListener struct {
}

func (c *CustomErrorListener) SyntaxError(
recognizer antlr.Recognizer,
_ antlr.Recognizer,
offendingSymbol any,
line, column int,
msg string,
Expand Down
3 changes: 1 addition & 2 deletions internal/compiler/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (p Parser) ParseModules(
parsedMods := make(map[src.ModuleRef]src.Module, len(rawMods))

for modRef, rawMod := range rawMods {
parsedPkgs, err := p.ParsePackages(rawMod.Packages, modRef)
parsedPkgs, err := p.ParsePackages(rawMod.Packages)
if err != nil {
return nil, compiler.Error{
Err: errors.New("Parsing error"),
Expand All @@ -48,7 +48,6 @@ func (p Parser) ParseModules(

func (p Parser) ParsePackages(
rawPkgs map[string]compiler.RawPackage,
modRef src.ModuleRef,
) (map[string]src.Package, *compiler.Error) {
packages := make(map[string]src.Package, len(rawPkgs))

Expand Down
1 change: 1 addition & 0 deletions internal/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package internal

import "embed"

//nolint:golint
//go:embed runtime
var Efs embed.FS
6 changes: 1 addition & 5 deletions internal/runtime/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func (c Connector) Connect(ctx context.Context, conns []Connection) {
}

wg.Wait()

return
}

func (c Connector) broadcast(ctx context.Context, conn Connection) {
Expand Down Expand Up @@ -78,7 +76,7 @@ func getReceiversForEvent(conn Connection) map[PortAddr]struct{} {
}

// distribute implements the "Queue-based Round-Robin Algorithm".
func (c Connector) distribute( //nolint:funlen
func (c Connector) distribute(
ctx context.Context,
msg Msg,
meta ConnectionMeta,
Expand Down Expand Up @@ -139,8 +137,6 @@ func (c Connector) distribute( //nolint:funlen
i = 0 // then start over
}
}

return
}

func NewDefaultConnector() Connector {
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/event_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "fmt"

type EmptyListener struct{}

func (l EmptyListener) Send(event Event, msg Msg) Msg {
func (l EmptyListener) Send(_ Event, msg Msg) Msg {
return msg
}

Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/funcs/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type intAdder struct{}

func (intAdder) Create(io runtime.FuncIO, _ runtime.Msg) (func(ctx context.Context), error) {
func (intAdder) Create(_ runtime.FuncIO, _ runtime.Msg) (func(ctx context.Context), error) {
// vvin, err := io.In.Port("vv")
// if err != nil {
// return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type BoolMsg struct {

func (msg BoolMsg) Type() MsgType { return BoolMsgType }
func (msg BoolMsg) Bool() bool { return msg.v }
func (msg BoolMsg) String() string { return fmt.Sprint(msg.v) }
func (msg BoolMsg) String() string { return strconv.FormatBool(msg.v) }

func NewBoolMsg(b bool) BoolMsg {
return BoolMsg{
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
ErrFuncRunner = errors.New("func runner")
)

func (r Runtime) Run(ctx context.Context, prog Program) (err error) {
func (r Runtime) Run(ctx context.Context, prog Program) error {
enter := prog.Ports[PortAddr{Path: "in", Port: "start"}]
if enter == nil {
return ErrStartPortNotFound
Expand Down
2 changes: 1 addition & 1 deletion pkg/typesystem/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (h Helper) ParamWithNoConstr(name string) Param {
}
}

func (h Helper) Param(name string, constr Expr) Param {
func (h Helper) Param(name string, _ Expr) Param {
return Param{
Name: name,
Constr: Expr{
Expand Down
Loading