Repository navigation
Conversation
|
[Low impact] The changes affect the repository's CI lint results, not runtime behavior. The PR is not ready to merge because the new error-level checks still reject existing code. FindingsFix with agent prompt### Issue 1
linter.nim:85-89
The new error-level checks reject unchanged calls, including `sleepAsync(checkResponse.retryAfter)` in `libp2p/autotls/acme/api.nim`, `echo PBCapParserHeader` in `tools/pbcap_parser.nim`, and `readFut.withTimeout(100.milliseconds)` in the tests. None is excluded, and CI runs this configuration. Keep existing calls advisory, or migrate them before making these checks errors.
### Issue 2
linter.nim:undefined-93
The `echo` patterns reject ordinary comments and strings, not just calls. For example, `echo message without change` in a comment in `libp2p/protocols/kademlia/put.nim` matches the first pattern. Contributors would have to rewrite harmless prose to pass lint. Check parsed calls instead of raw text.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (3) · Last reviewed commit: "Fix typo." · Reviewed by Greptile |
|
@moigagoo let's implement this one with regexp linter seems like really nice usecase for it |
More checks will land in this step later.
|
/review |
| step "Forbidden patterns accross project": | ||
| check patterns: | ||
| severity = error | ||
| settings: | ||
| forbidden = [r"\bsleepAsync\s+\S+\b", r"\bsleepAsync\(\S+\)"] |
There was a problem hiding this comment.
The new error-level checks reject unchanged calls, including sleepAsync(checkResponse.retryAfter) in libp2p/autotls/acme/api.nim, echo PBCapParserHeader in tools/pbcap_parser.nim, and readFut.withTimeout(100.milliseconds) in the tests. None is excluded, and CI runs this configuration. Keep existing calls advisory, or migrate them before making these checks errors.
Prompt To Fix With AI
This is a comment left during a code review.
Path: linter.nim
Line: 85-89
Comment:
**Existing calls now fail CI**
The new error-level checks reject unchanged calls, including `sleepAsync(checkResponse.retryAfter)` in `libp2p/autotls/acme/api.nim`, `echo PBCapParserHeader` in `tools/pbcap_parser.nim`, and `readFut.withTimeout(100.milliseconds)` in the tests. None is excluded, and CI runs this configuration. Keep existing calls advisory, or migrate them before making these checks errors.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| check patterns: | ||
| severity = error | ||
| settings: | ||
| forbidden = [r"\becho\s+\S+\b", r"\becho\(\S+\)"] |
There was a problem hiding this comment.
The echo patterns reject ordinary comments and strings, not just calls. For example, echo message without change in a comment in libp2p/protocols/kademlia/put.nim matches the first pattern. Contributors would have to rewrite harmless prose to pass lint. Check parsed calls instead of raw text.
Prompt To Fix With AI
This is a comment left during a code review.
Path: linter.nim
Line: 93
Comment:
**Comments become lint errors**
The `echo` patterns reject ordinary comments and strings, not just calls. For example, `echo message without change` in a comment in `libp2p/protocols/kademlia/put.nim` matches the first pattern. Contributors would have to rewrite harmless prose to pass lint. Check parsed calls instead of raw text.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
OpenCodeReview · Complete review: 1 of 1 selected files covered 6 findings.
Review infoReviewed commits:
Model: |
| check patterns: | ||
| severity = error | ||
| settings: | ||
| forbidden = [r"\bsleepAsync\s+\S+\b", r"\bsleepAsync\(\S+\)"] |
There was a problem hiding this comment.
This project-wide ban on sleepAsync (severity = error, no ignoredPatterns) matches dozens of existing, legitimate uses: e.g. libp2p/utils/heartbeat.nim (await sleepAsync(interval)), libp2p/connmanager.nim, libp2p/transports/tcptransport.nim (accept backoff), plus interop/, simulation/, examples/ and many tests. None of these carry #nolint, so the lint job will fail as soon as this step is enabled. Retry backoffs and heartbeat timers are valid sleeps (the project convention allows a sleep with an adjacent explanatory comment), which a blanket regex cannot distinguish. Scope this check to tests (or add ignores/an allow mechanism for justified sleeps) and land the corresponding code cleanups together with the rule.
There was a problem hiding this comment.
That's a valid concern. A better pattern would be to ban hardcoded literal sleeps, e.g. sleepAsync(10.second).
There was a problem hiding this comment.
we can have it as a hint, just o hint developer with message that it is not advised to use sleepAsync, especailly when it is used to fix race conditions.
we can promote it later to error - maybe error in tests, hint in library.
| check patterns: | ||
| severity = error | ||
| settings: | ||
| forbidden = [r"\becho\s+\S+\b", r"\becho\(\S+\)"] |
There was a problem hiding this comment.
The project-wide echo ban flags examples/ and tools/, where console output is the intended behavior: e.g. examples/directchat.nim, examples/tutorial_6_peerscoring.nim, tools/pbcap_parser.nim, tools/markdown_builder.nim, tools/gen_multicodec.nim. If the patterns check scans comments/strings, it also hits doc comments such as echo value in libp2p/utils/opt.nim. Add ignoredPatterns = ["./examples/**/*", "./tools/**/*", ...] (consistent with the other steps) or the lint run will fail on existing code.
| forbidden = [r"\becho\s+\S+\b", r"\becho\(\S+\)"] | ||
|
|
||
| step "Forbidden patterns in tests": | ||
| ignoredPatterns = ["./libp2p/**/*", "./examples/**/*", "./linter.nim"] |
There was a problem hiding this comment.
This step is named "in tests" but its ignore list only excludes libp2p/, examples/ and linter.nim, so it also applies to non-test code in tools/, interop/, and simulation/. If the intent is tests-only, restrict sources/ignores accordingly (e.g. also ignore ./tools/**/*, ./interop/**/*, ./simulation/**/*); otherwise rename the step to reflect its actual scope.
There was a problem hiding this comment.
Some of the paths you listed do not contain .nim files and the checks only apply to .nim files.
But you're right about tools and examples.
| check patterns: | ||
| severity = error | ||
| settings: | ||
| forbidden = [r"\bwait\s+\S+\b", r"\bwait\(\S+\)"] |
There was a problem hiding this comment.
This error-severity ban on wait flags legitimate, condition-aware chronos synchronization APIs that are the recommended alternative to sleepAsync: AsyncEvent.wait() (note \S+ matches the closing )), Future.wait(timeout), and wait(fut, timeout). These are used in 60+ existing test files (e.g. tests/libp2p/discovery/test_mdns.nim, tests/libp2p/muxers/test_yamux.nim, tests/libp2p/protocols/waggle/test_waggle.nim) and in interop/ (e.g. interop/unified_testing.nim). The \bwait\s+\S+\b variant also matches non-call code such as the wait = 10.milliseconds parameter of the shared tryPublish helper (tests/libp2p/pubsub/utils.nim:446) and English prose like "wait for …" in comments/test names if the check scans raw text. As written, this rule fails CI on correct code and discourages the very event-driven waiting the project conventions require. If the intent is to ban a specific blocking/polling helper, target its exact qualified name instead of the generic word wait.
There was a problem hiding this comment.
so this pattern needs to match .wait( {argument timeout} ) for example .wait(1.second) but it should ignore .wait() without argument, these are falls positives, such as AsyncEvent.wait() calls
| check patterns: | ||
| severity = error | ||
| settings: | ||
| forbidden = [r"\bwithTimeout\s+\S+\b", r"\bwithTimeout\(\S+\)"] |
There was a problem hiding this comment.
Despite the step name, ignoredPatterns = ["./libp2p/**/*", ...] does not exclude ./tests/libp2p/**/*, and ~20 existing test files use withTimeout(...) (e.g. tests/libp2p/muxers/test_mplex.nim, tests/libp2p/stream/test_bufferstream.nim, tests/libp2p/test_conn_manager.nim, tests/tools/test_sync.nim), all matching \bwithTimeout\(\S+\) at error severity — the lint job will fail with no accompanying code changes in this PR. Also, the wait regex \bwait\s+\S+\b matches ordinary prose like "wait for ..." in comments/strings if the check is text-based. Either migrate the existing tests to the preferred helper in the same PR or narrow the patterns/scope.
There was a problem hiding this comment.
20 existing test files use withTimeout(...)
most of those cases seem to use it unnecessary.
there could be some specific cases could be #nolint, for example
check not (await connMngr.getIncomingSlot().withTimeout(10.millis))^ because awaiting on this feature will never complete, so we need to cancel it.
but it might be nicer if there us utility that is used in tests:
check (await connMngr.getIncomingSlot()).isBlockedAfter(10.millis)
which can do something like this:
proc isBlockedAfter(fut: Future, timeout: Duration): bool =
await asyncSleep(timeout) #nolint
return not fut.completed # or something better i am not sure from top of my headthe idea is to hide forbidden pattern in utility which will be only once ignored with #nolint and expos utility as nicer more deliberate way for asserting invariant we actually want to assert - in named utility.
Add error-level checks for forbidden patterns:
Uses: https://iftech.github.io/nim-lint/stock_checks.html#patterns