8000 fmt docstring by bobzhang · Pull Request #2348 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fmt docstring #2348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2025
Merged

fmt docstring #2348

merged 3 commits into from
Jun 26, 2025

Conversation

bobzhang
Copy link
Contributor
  • fmt
  • impl ToJson for @priority_queue.T

@bobzhang bobzhang requested a review from Copilot June 25, 2025 13:57
Copy link
peter-jerry-ye-code-review bot commented Jun 25, 2025
Example code formatting inconsistency in test case

Category
Maintainability
Code Snippet
json/README.mbt.md:23-33
Recommendation
Simplify the content formatting to be more direct by removing the unnecessary let binding:

inspect(
  json.stringify(indent=2),
  content=#|{
  #|  "key": 42
  #|}
)

Reasoning
The current implementation uses an unnecessary let binding inside the content block. The heredoc syntax (#|) can be used directly as the content value, making the code more concise and easier to read.

Documentation examples use assert_eq instead of inspect for consistency

Category
Maintainability
Code Snippet
priority_queue/priority_queue.mbt:203
queue.push(1)
assert_eq(queue.length(), 1)
Recommendation
Use inspect for documentation examples consistently:

queue.push(1)
inspect(queue.length(), content="1")

Reasoning
The codebase shows a pattern of using inspect() for examples to show output. Using assert_eq() in some places and inspect() in others makes the documentation style inconsistent. inspect() better demonstrates the expected output to users.

ToJson implementation could handle null values more explicitly

Category
Correctness
Code Snippet
priority_queue/priority_queue.mbt:107-112
Recommendation
Add null check before converting items:

pub impl[A: ToJson + Compare] ToJson for T[A] with to_json(self) {
  let arr = []
  for x in self {
    let json = x.to_json()
    arr.push(if json == null { Json::null() } else { json })
  }
  Json::array(arr)
}

Reasoning
The current implementation assumes all items will successfully convert to JSON. Adding explicit null handling makes the implementation more robust for edge cases.

@bobzhang bobzhang changed the title hongbo/clean18 fmt docstring Jun 25, 2025
Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR cleans up the priority queue code by updating formatting and extending its functionality with a new JSON serialization implementation. It also updates test examples to use inspect statements and adds a JSON dependency to support the new functionality.

  • Added implementation of ToJson for T[A] in both mbti and mbt files.
  • Updated tests from assert_eq to inspect for clearer output in examples.
  • Updated package configuration to include the JSON module.

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
priority_queue/priority_queue.mbti Declares a new ToJson implementation for T[A].
priority_queue/priority_queue.mbt Implements the ToJson trait and updates test examples.
priority_queue/moon.pkg.json Adds the JSON dependency required for the new implementation.
priority_queue/README.mbt.md Adjusts test examples and variable names for clarity.
json/README.mbt.md Revises the JSON pretty printing example formatting.

@coveralls
Copy link
Collaborator
coveralls commented Jun 25, 2025

Pull Request Test Coverage Report for Build 81

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 89.003%

Totals Coverage Status
Change from base Build 79: 0.0%
Covered Lines: 3464
Relevant Lines: 3892

💛 - Coveralls

@bobzhang bobzhang enabled auto-merge (rebase) June 26, 2025 23:31
@bobzhang bobzhang merged commit adb5c92 into main Jun 26, 2025
10 checks passed
@bobzhang bobzhang deleted the hongbo/clean18 branch June 26, 2025 23:35
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
0