Skip to content

Improve build pipelines and code quality - #132

Open
sansmoraxz wants to merge 12 commits into
grid-x:masterfrom
sansmoraxz:fix/improve-buildpipelines
Open

Improve build pipelines and code quality#132
sansmoraxz wants to merge 12 commits into
grid-x:masterfrom
sansmoraxz:fix/improve-buildpipelines

Conversation

@sansmoraxz

Copy link
Copy Markdown
Contributor

Fixes: #131

Added golangci-lint with a couple of rules that made sense.

And their related fixes.

  • revive: the defacto golint replacement
  • govet: just simplified go vet
  • gosec: Scan for potential security issues. Did catch a couple of casting related bugs in code.
  • gocritic: highly configurable. did catch the exit and defer skip in cli for err case and some comment spacing.
  • staticcheck: https://staticcheck.dev/
  • errcheck: catch where you forgot to handle err returned
  • dupl: Code deduplication scanner.

You can check other rules here: https://golangci-lint.run/docs/linters/configuration.

Updated makefile to use golangci-lint instead of golint.

Also CI pipeline has really old versions of golangci-lint.

docker run --rm public.ecr.aws/gridx/base-images:modbus-dev-1.21.latest golangci-lint --version
golangci-lint has version 1.56.1 built with go1.22.0 from a25592b5 on 2024-02-08T18:03:33Z

The provided .golangci.yml would not be accepted by that version. Ensure to update before merging.

Maintainers already granted write access to this branch.

Comment thread crc.go

@leonklingele leonklingele left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @sansmoraxz! 😊 Always very happy to see your contributions to the repo!

Left some smaller nits but also changes which, imo, are blockers. Definitely open to discuss things though! 😃

Comment thread cmd/modbus-cli/main.go Outdated
Comment thread rtuclient.go

adu[length-1] = byte(checksum >> 8)
adu[length-2] = byte(checksum)
adu[length-2] = byte(checksum & 0x00ff)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To other reviewers wondering why this change was made:

Why: To make the developer's intent explicitly clear and visually symmetrical.

In Modbus RTU, the 16-bit CRC (Cyclic Redundancy Check) is appended to the end of the packet, sending the lower byte first, followed by the upper byte.

In Go, converting a 16-bit integer to a byte using byte(checksum) automatically drops the higher 8 bits and keeps the lower 8 bits. It works perfectly fine on its own.

However, by adding the bitwise AND mask (& 0x00ff), the code explicitly states: "I am intentionally extracting the lower 8 bits here."

It also provides nice visual symmetry with the line immediately above it (byte(checksum >> 8)), showing exactly how the 16 bits are being split into two 8-bit chunks. Additionally, explicit masking like this often pacifies strict static analysis tools (linters) that might warn about implicit data truncation.

Thanks @sansmoraxz! 😊

Comment thread crc.go

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO @leonklingele: Review this.

Comment thread tcpclient.go Outdated
Comment thread tcpclient.go Outdated
Comment thread cmd/modbus-cli/main.go

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO @leonklingele: Lots of changes, still open for review.

Comment thread client.go Outdated
Comment thread client.go Outdated
Comment thread client.go

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All read funcs (and some of the write funcs) still use common / duplicate code. For consistency, I'd prefer to either duplicate code everywhere (as before), or unify it for all read + write funcs.

sansmoraxz and others added 5 commits July 20, 2026 23:00
Co-authored-by: leonklingele <git@leonklingele.de>
Co-authored-by: leonklingele <git@leonklingele.de>
Co-authored-by: leonklingele <git@leonklingele.de>
@sansmoraxz
sansmoraxz requested a review from leonklingele July 29, 2026 17:16
@sansmoraxz

Copy link
Copy Markdown
Contributor Author

I was thinking, perhaps it would be better to have typed errors instead of string builders scattered across codebase. WDYT?

Anyway might be better to keep it out of this PR, as that's a large behaviour change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tooling] Replace golint with modern alternative

2 participants