Skip to content

fix-lint#603

Merged
yaacov merged 1 commit intomasterfrom
fix-lint
Mar 20, 2026
Merged

fix-lint#603
yaacov merged 1 commit intomasterfrom
fix-lint

Conversation

@yaacov
Copy link
Copy Markdown
Owner

@yaacov yaacov commented Mar 20, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved response parsing robustness and byte/length handling; added validation to reject invalid register counts and mismatched write payloads.
  • Chores

    • Added lint scripts and new ESLint flat config; removed legacy config. Updated CI (Node matrix, caching, lint step), refreshed devDependencies, modernized build tasks, removed old helper scripts, updated .gitignore/.vscode, and added a Development section to README.
  • Style

    • Minor whitespace, indentation, and comment formatting cleanups across examples and networking code.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 20, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ff849a8-d37d-48f6-ac07-5705143616b5

📥 Commits

Reviewing files that changed from the base of the PR and between b2c4299 and 2a67456.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (41)
  • .eslintrc.json
  • .github/workflows/ci.yml
  • .gitignore
  • .vscode/launch.json
  • README.md
  • eslint.config.mjs
  • examples/async_server.js
  • examples/buffer.js
  • examples/buffered_server.js
  • examples/buffertcp.js
  • examples/debug.js
  • examples/device-identification.js
  • examples/logger.js
  • examples/logger_complete.js
  • examples/polling_RTU.js
  • examples/polling_TCP.js
  • examples/polling_UDP.js
  • examples/server.js
  • examples/server_enron.js
  • examples/server_enron_serial.js
  • examples/simple.js
  • examples/simple_ble.js
  • examples/simple_enron.js
  • examples/simple_enron_serial.js
  • examples/tcp_client_abort_signal.js
  • examples/write.js
  • examples/write_complete.js
  • gulpfile.js
  • index.js
  • npm-update.sh
  • npm-upgrade.sh
  • package.json
  • ports/bleport.js
  • ports/tcpport.js
  • test/Lint/test.js
  • test/servers/serverserial.test.js
  • test/servers/servertcp.enron.test.js
  • test/servers/servertcp.test.js
  • test/servers/servertcpCallback.test.js
  • test/servers/servertcpPromise.test.js
  • test/test.js

📝 Walkthrough

Walkthrough

Adjusted Modbus response parsing (radix and unsigned/signed fixes), added FC23 write input validation, improved port lifecycle listener handling, introduced ESLint flat config and lint scripts, updated CI/Gulp/tooling, removed legacy lint artifacts, and applied small formatting/whitespace tweaks across examples/tests and tcp port buffering line.

Changes

Cohort / File(s) Summary
Modbus core
index.js
Multiple FC parsers updated to use parseInt(..., 10) and switched FC23 byte-count to readUInt8; FC2/FC17/FC43 length/address parsing fixed; _onPortClose handler added; close()/destroy() remove specific listeners; writeFC23 validates numReadRegisters, numWriteRegisters, and valuesToWrite length and errors early.
Package & lint config
package.json, eslint.config.mjs, .eslintrc.json (removed)
Added scripts.lint/lint:fix; removed legacy .eslintrc.json; added flat config eslint.config.mjs that maps legacy rules and registers @stylistic plugin; updated devDependencies and removed mocha-eslint.
CI & workflow
.github/workflows/ci.yml, gulpfile.js
CI Node matrix bumped to 22.x/24.x, actions upgraded and npm ci + lint step added; Gulp tasks converted to Gulp 4 series/parallel.
Ports
ports/tcpport.js, ports/bleport.js
tcpport.js: removed trailing whitespace/extra blank line in "data" handler concat assignment only; bleport.js: removed top-level JSDoc global comment.
Examples & tests (format/lint changes)
examples/*, test/*, .vscode/launch.json (deleted)
Removed many file-level ESLint-disable directives, normalized comment/whitespace formatting in examples and tests, deleted VS Code launch config.
Tooling scripts removed
npm-update.sh (deleted), npm-upgrade.sh (deleted)
Removed two npm helper shell scripts.
Repo metadata
.gitignore, README.md
.gitignore now ignores .vscode/ and no longer excludes package-lock.json; README: added Development section describing npm ci, lint, tests, and lockfile guidance.

Sequence Diagram(s)

(Skipped — changes are parsing/validation, lint/config, CI, and minor formatting edits; no new multi-component sequential feature introduced.)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

  • fix-lint #603 — appears to make the same index.js fixes (radix additions, FC23 byte-count change, writeFC23 validation, listener handling) and overlapping package.json/eslint changes.

Poem

🐇 I counted bytes with careful eye,

Swapped signed for unsigned — no surprise.
I guarded writes and fixed the test,
Tuned lint and CI, then took a rest.
A little hop made the repo fly.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix-lint' accurately describes the primary focus: adding/configuring ESLint, updating linting infrastructure across the codebase, and removing legacy lint configurations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-lint
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@index.js`:
- Around line 275-277: The byte-count for FC23 is being read as a signed integer
in _readFC23 (data.readInt8(2)), which yields negative values for counts >127;
change the parser to read an unsigned byte (use data.readUInt8(2)) and ensure
the subsequent loop that builds values[] uses that unsigned length to iterate
the correct number of bytes when decoding registers in _readFC23.
- Around line 1269-1307: The code currently checks only types for valuesToWrite;
add a length validation before allocating the request buffer: if
Buffer.isBuffer(valuesToWrite) ensure valuesToWrite.length >= writeByteCount,
and if Array.isArray(valuesToWrite) ensure valuesToWrite.length >=
numWriteRegisters; if the check fails call next(new Error("valuesToWrite length
does not match numWriteRegisters")) (or return the same callback pattern used
earlier) and return. Place this validation just after computing
writeByteCount/numWriteRegisters (before using valuesToWrite in the Buffer.copy
or writeUInt16BE loop) and keep existing symbols (writeByteCount,
numWriteRegisters, valuesToWrite, next) to locate where to add the check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a0abf21d-1467-4ac8-a7e8-64e827242429

📥 Commits

Reviewing files that changed from the base of the PR and between 834fa62 and 91a1028.

📒 Files selected for processing (3)
  • index.js
  • package.json
  • ports/tcpport.js

Comment thread index.js
Comment thread index.js
@yaacov yaacov force-pushed the fix-lint branch 2 times, most recently from e4f3513 to a17feae Compare March 20, 2026 07:31
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@index.js`:
- Around line 1264-1291: The code currently uses numReadRegisters and
numWriteRegisters without validation which can cause synchronous throws; add
validation before any buffer/size calculations (before computing writeByteCount
and responseLength) to ensure both numReadRegisters and numWriteRegisters are
defined, are numbers, are integers, and are within acceptable ranges (e.g., >0
and <= max registers you support—use the same protocol limit you enforce
elsewhere, such as 125); if validation fails call next(new Error(...)) or
next(new BadAddressError()) as appropriate and return. Reference the variables
numReadRegisters and numWriteRegisters and the logic around computing
writeByteCount and responseLength so the checks run prior to Buffer.alloc(),
writeUInt8(), writeUInt16BE(), or any size math.
- Around line 1421-1423: Replace the optional catch binding with a traditional
catch parameter to retain compatibility with older Node versions: change the two
try/catch blocks that load optional native deps (the one requiring
"./ports/rtubufferedport" which assigns module.exports.RTUBufferedPort and the
other similar optional require) from "catch { }" to "catch (err) { }" (you can
ignore or log err inside the block); do not change README in this PR so runtime
syntax remains Node 4/6/8 compatible.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a3199f3e-993e-4bc0-bbf5-6951c1ed7722

📥 Commits

Reviewing files that changed from the base of the PR and between e4f3513 and a17feae.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (40)
  • .eslintrc.json
  • .github/workflows/ci.yml
  • .gitignore
  • .vscode/launch.json
  • README.md
  • eslint.config.mjs
  • examples/async_server.js
  • examples/buffer.js
  • examples/buffered_server.js
  • examples/buffertcp.js
  • examples/debug.js
  • examples/device-identification.js
  • examples/logger.js
  • examples/logger_complete.js
  • examples/polling_RTU.js
  • examples/polling_TCP.js
  • examples/polling_UDP.js
  • examples/server.js
  • examples/server_enron.js
  • examples/server_enron_serial.js
  • examples/simple.js
  • examples/simple_ble.js
  • examples/simple_enron.js
  • examples/simple_enron_serial.js
  • examples/tcp_client_abort_signal.js
  • examples/write.js
  • examples/write_complete.js
  • gulpfile.js
  • index.js
  • npm-update.sh
  • npm-upgrade.sh
  • package.json
  • ports/bleport.js
  • ports/tcpport.js
  • test/Lint/test.js
  • test/servers/serverserial.test.js
  • test/servers/servertcp.enron.test.js
  • test/servers/servertcp.test.js
  • test/servers/servertcpCallback.test.js
  • test/servers/servertcpPromise.test.js
💤 Files with no reviewable changes (6)
  • npm-update.sh
  • .vscode/launch.json
  • npm-upgrade.sh
  • test/Lint/test.js
  • .eslintrc.json
  • ports/bleport.js
✅ Files skipped from review due to trivial changes (27)
  • examples/async_server.js
  • examples/simple_enron_serial.js
  • examples/buffertcp.js
  • examples/write_complete.js
  • examples/server_enron_serial.js
  • examples/simple_enron.js
  • examples/simple_ble.js
  • test/servers/servertcpCallback.test.js
  • .gitignore
  • examples/tcp_client_abort_signal.js
  • examples/buffer.js
  • ports/tcpport.js
  • test/servers/servertcp.test.js
  • README.md
  • examples/buffered_server.js
  • examples/polling_UDP.js
  • examples/server_enron.js
  • test/servers/servertcpPromise.test.js
  • examples/simple.js
  • test/servers/serverserial.test.js
  • examples/server.js
  • examples/device-identification.js
  • examples/write.js
  • test/servers/servertcp.enron.test.js
  • examples/polling_TCP.js
  • examples/polling_RTU.js
  • examples/logger.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/ci.yml
  • package.json

Comment thread index.js
Comment thread index.js Outdated
Signed-off-by: yaacov <kobi.zamir@gmail.com>
@yaacov yaacov merged commit f408cd5 into master Mar 20, 2026
3 checks passed
This was referenced Mar 20, 2026
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.

1 participant