Skip to content

chore: code-style fixes per STYLEGUIDE#392

Merged
bidzyyys merged 9 commits into
mainfrom
chore/code-style-fixes
Jun 19, 2026
Merged

chore: code-style fixes per STYLEGUIDE#392
bidzyyys merged 9 commits into
mainfrom
chore/code-style-fixes

Conversation

@bidzyyys

@bidzyyys bidzyyys commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

General code-style cleanup against STYLEGUIDE.md. Does not close any issue.

Changes

  • STYLEGUIDE.md — codify doc-comments as the API source of truth (rendered by sui move build --doc, consumed by AI-integrator tooling):
    • #### Aborts lists every error a function can raise, including errors propagated from internal calls;
    • state caller preconditions and map each to its error;
    • #### Parameters / #### Returns only where they add detail beyond the one-line summary (a trivial getter needs neither);
    • pin-exact exception: approximation tests that check an on-chain result against an off-chain mathematical reference within a tolerance (e.g. assert!(diff < epsilon)) stay bound-based — do not convert to assert_eq!.
  • Struct field docs — document the hot-potato struct fields in access (delayed/two_step Borrow, two_step RequestBorrow) and fixed_point Components.
  • Test naming — drop the test_ prefix from access_control_tests functions (descriptive names per STYLEGUIDE Testing), matching the sibling test modules.

Verification

sui move test --build-env testnet --lint --warnings-are-errors and sui move build --doc --build-env testnet, all green:

  • contracts/access — 137 tests
  • math/core — 753 tests
  • math/fixed_point — 426 tests

Out of scope (follow-up)

access_control_tests still carries #[allow(lint(...))] (4) and abort 999 sentinels (43); removing them requires restructuring the expected-failure tests (and resolving share_owned) and is left to a separate focused PR.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Expanded public documentation standards to require complete #### Parameters, #### Returns, and detailed #### Aborts listings.
    • Updated API docs across math and access components with explicit abort/error codes and clearer explanations.
    • Added field-level documentation for public structs and refreshed the project’s introductory wording.
  • Tests
    • Expanded and renamed AccessControl tests, adding more negative and boundary coverage plus a regression for correct pending-state cleanup.

- STYLEGUIDE: codify doc-comments as the API source of truth — Aborts lists every error (including propagated), preconditions map to their error, and Parameters/Returns are included only where they add detail beyond the summary; add a pin-exact exception for tolerance/approximation assertions (e.g. fixed-point log/sqrt vs an off-chain reference).
- Document struct fields on the access hot-potato structs (delayed/two_step Borrow, two_step RequestBorrow) and fixed_point Components.
- Drop the test_ prefix from access_control_tests functions (descriptive names per STYLEGUIDE Testing).

Verified with sui move test --lint --warnings-are-errors and build --doc (testnet): access 137, math/core 753, math/fixed_point 426 — all green.
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.88%. Comparing base (1ab78d8) to head (7b5b407).

Files with missing lines Patch % Lines
math/core/sources/u128.move 0.00% 1 Missing ⚠️
math/core/sources/u16.move 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #392      +/-   ##
==========================================
- Coverage   78.90%   78.88%   -0.02%     
==========================================
  Files          23       23              
  Lines        1782     1781       -1     
  Branches      640      642       +2     
==========================================
- Hits         1406     1405       -1     
  Misses        341      341              
  Partials       35       35              
Flag Coverage Δ
contracts/access 65.46% <0.00%> (+0.05%) ⬆️
contracts/utils 44.09% <0.00%> (ø)
math/fixed_point 56.51% <0.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bidzyyys

Copy link
Copy Markdown
Collaborator Author

Comment thread STYLEGUIDE.md
Comment thread contracts/access/tests/access_control_tests.move
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Expands STYLEGUIDE.md with a bound-based assertion exception for #[random_test] and stronger doc-comment #### Aborts requirements. Adds field-level doc comments to the Borrow, RequestBorrow, and Components public structs. Updates math module abort documentation to specify error codes. Updates llms.txt intro wording. Renames access-control test functions and adds cancel-state regression and exact-delay boundary coverage.

Changes

Style Guide, Documentation, and Test Updates

Layer / File(s) Summary
STYLEGUIDE rule expansions
STYLEGUIDE.md
Adds exception for bound-based #[random_test] assertions (must remain bound-based, not converted to assert_eq!) and expands the doc-comment mandate to require complete #### Aborts sections with all native and propagated internal-call errors, plus explicit caller preconditions mapped to error codes.
Struct field documentation
contracts/access/sources/ownership_transfer/delayed.move, contracts/access/sources/ownership_transfer/two_step.move, math/fixed_point/sources/sd29x9/sd29x9_base.move
Reformats Borrow and RequestBorrow into multi-line structs with per-field doc comments; adds doc comments to Components.neg field, implementing the expanded documentation rules.
Math module abort documentation specificity
math/core/sources/u8.move, math/core/sources/u16.move, math/core/sources/u32.move, math/core/sources/u64.move, math/core/sources/u128.move, math/core/sources/u256.move, math/core/sources/decimal_scaling.move, math/core/sources/internal/macros.move
Updates abort documentation across arithmetic helper modules to explicitly list error codes (EDivideByZero, EZeroModulus, EInvalidDecimals) instead of generic phrasing, following the strengthened STYLEGUIDE #### Aborts requirements.
Access control test renaming and extended coverage
contracts/access/tests/access_control_tests.move
Renames test functions across all lifecycle areas (constructor, grant/revoke/renounce, set_role_admin, queries, auth, transfer/renounce, delay changes) and adds regression coverage for cancel_default_admin_transfer fully clearing pending state and exact-delay boundary acceptance.
Repository prose updates
llms.txt
Rewords introduction paragraph to emphasize "Audited, composable Move building blocks" and "reviewed primitives" with updated sentence flow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • ericnordelo
  • 0xNeshi

Poem

🐇 Hop, skip, and test—the style guide grew,
Aborts now precise, documented true!
Struct fields adorned with comments bright,
Test names reframed, boundaries tight.
Math modules squared with specifics clear—
This bunny's standards shine here! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: code-style fixes implementing STYLEGUIDE guidelines across the codebase.
Description check ✅ Passed The description is comprehensive, covering all changes, verification steps, and out-of-scope work, but is missing the PR Checklist section from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/code-style-fixes

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

Comment thread STYLEGUIDE.md Outdated
Comment thread STYLEGUIDE.md Outdated
Comment thread STYLEGUIDE.md Outdated
Comment thread STYLEGUIDE.md Outdated
bidzyyys added 8 commits June 17, 2026 15:11
Drop the hardcoded primitive list (access control / math / rate limiting) from the blockquote — it drifts as the library grows. Reframe around discovery.
Bring main (incl. #388 em-dash convention, #390/#391/#394) into the branch, main-authoritative on logistics. Keep this branch's additions: doc-comment standard + pin-exact tolerance exception in STYLEGUIDE, struct-field docs, test_ rename, llms.txt discovery wording - all em-dash-free per the merged convention (the lone intentional em-dash is the rule's own example).
- STYLEGUIDE: Aborts section lists native aborts too (overflow, div-by-zero);
  precondition example follows the actual '- `Error` if ...' convention
- math/core: name the concrete error in mul_div/inv_mod/mul_mod wrappers
  (EDivideByZero / EZeroModulus) instead of generic 'Aborts if ...'
- macros: mul_div Aborts reformatted to convention; mul_shr Aborts section
  removed (it cannot abort - overflow is returned as a flag)
- decimal_scaling: normalize abort bullets to '- `Error` if ...'
- New public-facing component (package or public capability) must ship a
  runnable example in the same PR - examples are the integration-facing source
  of truth for AI agents and downstream integrators
- Restore the 'register new package in the CI matrix' rule that was dropped
  during an earlier main sync
Library-wide STYLEGUIDE review (math/core + math/fixed_point):
- fixed_point: name the concrete error in every #### Aborts bullet across both
  type families (EOverflow / EUnderflow / EDivideByZero / EInvalidShiftSize /
  ENegativeValue / EIntegerOverflow / ECannotBeConverted*), replacing generic
  'Aborts if ...'; fixes the div/mod vs div_trunc/div_away naming inconsistency
- math/core: align clz summary across widths; unify is_power_of_ten doc to the
  '10^0 to 10^N' range form for all six widths
- macros: name the native shift-overflow cause in checked_shl/checked_shr;
  fix smart quotes and a missing floor bracket in doc-comments

@0xNeshi 0xNeshi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Excellent work

@ericnordelo ericnordelo 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.

LGTM!

@bidzyyys bidzyyys merged commit a9703fe into main Jun 19, 2026
16 of 18 checks passed
@bidzyyys bidzyyys deleted the chore/code-style-fixes branch June 19, 2026 11:09
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.

3 participants