Skip to content

chore: add cyclomatic complexity lint rule#875

Open
cv wants to merge 4 commits intomainfrom
lint/cyclomatic-complexity
Open

chore: add cyclomatic complexity lint rule#875
cv wants to merge 4 commits intomainfrom
lint/cyclomatic-complexity

Conversation

@cv
Copy link
Contributor

@cv cv commented Mar 25, 2026

Summary

  • Adds ESLint complexity rule to bin/ and scripts/ as an error, threshold 20
  • 6 existing functions are suppressed with eslint-disable-next-line — these are tech debt that badly needs refactoring:
Function File Complexity
setupNim onboard.js 95
setupPolicies onboard.js 41
main IIFE nemoclaw.js 27
applyPreset policies.js 24
deploy nemoclaw.js 22
setupInference onboard.js 22

These complexity scores are terrible. setupNim at 95 is nearly unmaintainable — a single function with 95 independent code paths. These functions desperately need to be broken apart; the suppression comments are a stop-gap so we can enforce the rule on new code immediately while we plan the refactor.

Target: ratchet to 15 as the suppressed functions get refactored.

Test plan

  • npx eslint bin/ scripts/ passes clean at threshold 20
  • CI passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Enforced a cyclomatic complexity limit across build and configuration tooling to improve code quality.
    • Added targeted lint overrides for a few complex CLI/build scripts to prevent unnecessary lint failures during development and CI.

Add ESLint complexity rule to bin/ and scripts/ to prevent new
functions from accumulating excessive branching. Starting threshold
is 95 (current worst offender: setupNim in onboard.js). Ratchet
plan: 95 → 40 → 25 → 15.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8dfd03bb-d5e6-48ed-932f-231f5e41eda7

📥 Commits

Reviewing files that changed from the base of the PR and between b8dc697 and 4bfe9db.

📒 Files selected for processing (4)
  • bin/lib/onboard.js
  • bin/lib/policies.js
  • bin/nemoclaw.js
  • eslint.config.mjs
✅ Files skipped from review due to trivial changes (3)
  • bin/nemoclaw.js
  • bin/lib/onboard.js
  • bin/lib/policies.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • eslint.config.mjs

📝 Walkthrough

Walkthrough

Enabled ESLint complexity rule (max 20) for CommonJS/Node.js files matching bin/**/*.js, scripts/**/*.js, and commitlint.config.js; added // eslint-disable-next-line complexity comments in several bin/*.js files to suppress that rule for specific complex functions.

Changes

Cohort / File(s) Summary
ESLint configuration
eslint.config.mjs
Enabled complexity rule with ["error", { max: 20 }] for CommonJS/Node.js targets covering bin/**/*.js, scripts/**/*.js, and commitlint.config.js.
Bin scripts — lint suppressions
bin/lib/onboard.js, bin/lib/policies.js, bin/nemoclaw.js
Added // eslint-disable-next-line complexity before several complex functions (setupNim, setupInference, setupPolicies, applyPreset, deploy, top-level async IIFE) to bypass the new complexity rule without changing runtime logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit nudges lines with care,
A rule arrives — complexity aware,
Tiny flags hush the noisy tide,
So code hops on, both safe and spry. 🐇✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a cyclomatic complexity lint rule to the ESLint configuration. This matches the core objective of introducing the complexity rule for bin/ and scripts/ files.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

✏️ 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 lint/cyclomatic-complexity

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

Suppress 6 functions that exceed the threshold with eslint-disable
comments so we can start enforcing at 20 instead of 95:

- setupNim (95), setupPolicies (41), setupInference (22) in onboard.js
- deploy (22), main IIFE (27) in nemoclaw.js
- applyPreset (24) in policies.js

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cv cv requested a review from ericksoa March 25, 2026 06:28
Copy link
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.

🧹 Nitpick comments (1)
eslint.config.mjs (1)

42-44: LGTM! Well-structured incremental complexity enforcement.

The rule syntax is correct, and documenting the ratchet plan inline is helpful. Starting at 95 to avoid blocking existing code while preventing new high-complexity functions is a pragmatic approach.

Optional: Consider creating a GitHub issue or adding a tracking mechanism to ensure the ratchet milestones (95 → 40 → 25 → 15) are actually followed through. Inline comments can be forgotten over time.

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eslint.config.mjs` around lines 42 - 44, The inline ratchet plan for the
ESLint "complexity" rule is fine but needs a persistent tracking mechanism so
milestones (95 → 40 → 25 → 15) aren't forgotten; add a tracking artifact (e.g.,
create a GitHub Issue or project board and reference the milestones) and link it
from the eslint.config.mjs comment near the "complexity" rule so reviewers can
find the plan (refer to the "complexity" rule entry in eslint.config.mjs);
update the comment to include the issue/board URL and a brief cadence (e.g.,
quarterly reductions) to ensure the ratchet is followed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@eslint.config.mjs`:
- Around line 42-44: The inline ratchet plan for the ESLint "complexity" rule is
fine but needs a persistent tracking mechanism so milestones (95 → 40 → 25 → 15)
aren't forgotten; add a tracking artifact (e.g., create a GitHub Issue or
project board and reference the milestones) and link it from the
eslint.config.mjs comment near the "complexity" rule so reviewers can find the
plan (refer to the "complexity" rule entry in eslint.config.mjs); update the
comment to include the issue/board URL and a brief cadence (e.g., quarterly
reductions) to ensure the ratchet is followed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d1edef24-fe8c-4f56-8dac-a750e392d999

📥 Commits

Reviewing files that changed from the base of the PR and between cec1e42 and b8dc697.

📒 Files selected for processing (1)
  • eslint.config.mjs

@buddingengineers12345
Copy link

Looks good to me. Kindly review and merge

@cv cv requested a review from drobison00 March 25, 2026 16:53
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.

2 participants