Skip to content

Latest commit

 

History

History
268 lines (192 loc) · 8.14 KB

CONTRIBUTING.md

File metadata and controls

268 lines (192 loc) · 8.14 KB

Contributing to ChunkEdge

Before contributing, please first discuss the change you wish to make. For bugs and features proposals, first open an issue with a detailed description of the problem and the solution you would like to see. This makes sure that your contribution is aligned with the project and avoids wasted effort. Otherwise, you risk that your contribution will be rejected when it is submitted for review.

If there are open issues that are already planned by the maintainers, you can reply to the issue to express your interest in working on it stating that you plan to submit a pull request. This will help avoid duplicate work. If the open issue does not yet contain a proposed solution and requires significant change, please first describe your proposal in the issue before starting to work on it.

For general questions and discussions related to the project, please use GitHub discussions.

To get started with your first contribution to the project, you can check out the issues tagged with "good first issue".

Use of AI

Use of AI and LLM tools is generally allowed when contributing. However, it is the contributor's responsibility to ensure that the generated content is correct. You need to understand exactly what the generated code does, and why it does it. Submitting vibe-coded code will results in your pull request being rejected and will likely lead to a ban from contributing to the project. You should not expect the maintainers to review your AI-generated code when you do not understand it yourself.

What version of Rust should I use?

It is generally best to use the same stable version of Rust that is currently being used in the CI of the project. The stable version is pinned in the rust-toolchain file. Some features (such as miri) may require the nightly toolchain.

Playgrounds

Playgrounds are meant to provide a quick and minimal environment to test out new code or reproduce bugs. Playgrounds are also a great way test out quick ideas. This is the preferred method for providing code samples in issues and pull requests.

To get started with a new playground, copy the template to playground.rs.

cp tools/playground/src/playground.template.rs tools/playground/src/playground.rs

Make your changes to crates/playground/src/playground.rs. To run it:

cargo run -p playground # simply run the playground, or
cargo watch -c -x "run -p playground" # run the playground and watch for changes

Automatic Checks

When you submit a pull request, your code will automatically run through clippy, rustfmt, etc. to check for any errors or mistakes. If an error does occur, it must be fixed before the pull request can be merged.

Running Checks Locally

You can run the same checks locally through the provided Nix flake. If you have Nix installed, run nix develop from the repository root to enter a shell with all the required tools. Then run ci-full to run all checks, or run any of the individual commands listed below.

check-fmt-java # Check Java formatting without modifying sources
fmt-java # Format the extractor's Java sources
build-java # Build the extractor
lint-java-pmd # Run the PMD linter on the extractor's Java sources
lint-java-error-prone # Run the Error Prone linter on the extractor's Java sources
lint-java-all # Run both Java linters
ci-java-basic # Check formatting, PMD, and Error Prone
ci-java-full # Check formatting, PMD, and Error Prone, and build the extractor
check-fmt-rust # Check Rust formatting without modifying sources
fmt-rust # Format the Rust sources
lint-rust-clippy # Run clippy on the Rust sources
test-rust-basic # Run only the workspace tests with all features and targets
test-rust-full # Also run doctests, NBT feature-variant tests, and Miri
ci-rust-full # Run all Rust-related CI checks
check-typos # Check spelling across the repository
generate-depgraph # Regenerate assets/depgraph.svg
ci-full # Run all checks that the CI also runs

Code Conventions

Here are some rules you should follow for your code. Generally the goal here is to be consistent with existing code, the standard library, and the Rust ecosystem as a whole. Nonconforming code is not necessarily a blocker for accepting your contribution, but conformance is advised.

These guidelines are intended to complement the Rust API Guidelines.

Top-down Modules

Readers of the module should be able to understand your code by reading it from top to bottom. Whenever items in your module form a parent-child relationship, the parent should be written above the children. Typically this means that important pub items are placed before private implementation details.

For instance, here are three functions. Notice how the definition of foo is placed above its dependencies. The parent is foo while its children are bar and baz.

pub fn foo() {
    bar();
    baz();
}

fn bar() {}

fn baz() {}

This guideline applies to types as well.

pub struct Foo {
    bars: Vec<Bar>,
}

struct Bar {
    // ...
}

Getters and Setters

Getters should not start with a get_ prefix.

Good Bad
impl Foo {
    fn bar(&self) -> &Bar { ... }
    fn set_bar(&mut self, bar: Bar) { ... }
}
impl Foo {
    fn get_bar(&self) -> &Bar { ... }
    fn set_bar(&mut self, bar: Bar) { ... }
}

See SocketAddr for an example of a standard library type that uses this convention.

Under appropriate circumstances a different naming scheme can be used. Command is a standard type that demonstrates this.

If a bar field exists and no invariants need to be maintained by the getters and setters, it is usually better to make the bar field public.

Bevy Messages

Types intended to be used as messages in [MessageReader] and [MessageWriter] should end in the Message suffix. This is helpful for readers trying to distinguish messages from other types in the program.

Good Bad
struct CollisionMessage { ... }

fn handle_collisions(mut messages: MessageReader<CollisionMessage>) { ... }
struct Collision { ... }

fn handle_collisions(mut messages: MessageReader<Collision>) { ... }

Specifying Dependencies

When adding a new dependency to a crate, make sure you specify the full semver version.

Good Bad
[dependencies]
serde_json = "1.0.96"
[dependencies]
serde_json = "1"

Writing Unit Tests

When writing unit tests, unwrap errors instead of returning them. Panicking displays the line and column of the error, which is useful for debugging. This information is lost when the error is returned.

Good Bad
#[test]
fn my_test() {
    some_fallible_func().unwrap();
}
#[test]
fn my_test() -> anyhow::Result<()> {
    some_fallible_func()?;
    // ...
    Ok(())
}

Documentation

All public items should be documented. Documentation must be written with complete sentences and correct grammar. Consider using intra-doc links where appropriate.

Unit Tests

Unit tests help your contributions last! They ensure that your code works as expected and that it continues to work in the future.

whole-server unit tests can be found in /src/tests/.

Naming Quantities

Variables intended to hold quantities should be written with the _count suffix instead of the num_ prefix.

Good Bad
let block_count = ...;
let num_blocks = ...;