Skip to content
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

Add .editorconfig and rustfmt.toml for Consistent Code Formatting #1508

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tal7aouy
Copy link

@tal7aouy tal7aouy commented Apr 21, 2024

This PR introduces two configuration files, .editorconfig and rustfmt.toml, to enforce consistent code formatting across the project. These additions aim to standardize indentation, line endings, maximum line length, and other formatting rules for Rust and Python files, ensuring the codebase is uniform and easier to maintain.

Key Changes

  • .editorconfig:

    • Specifies global formatting rules, including indentation style, end-of-line characters, and character encoding.
    • Defines specific configurations for Python and Rust files, such as maximum line length.
  • rustfmt.toml:

    • Sets Rust-specific formatting rules, focusing on indentation, tab spaces, maximum line width, and newline style.
    • Promotes code readability and consistency across Rust files.

.editorconfig Configuration

The .editorconfig file includes the following rules:

  • Global Settings:

    • indent_style = space: Use spaces for indentation.
    • indent_size = 2: Use 2 spaces per indentation level.
    • insert_final_newline = true: Ensure every file ends with a newline.
    • end_of_line = lf: Use Unix-style line endings.
    • charset = utf-8: Set UTF-8 as the default encoding.
  • Python Settings:

    • max_line_length = 88: Follows PEP 8 guidelines for Python files.
  • Rust Settings:

    • max_line_length = 100: Maximum line length for Rust files.

rustfmt.toml Configuration

The rustfmt.toml file includes the following rules:

  • max_width = 100: Maximum line width for Rust code.
  • hard_tabs = false: Use spaces, not tabs, for indentation.
  • tab_spaces = 2: Each tab equals 2 spaces.
  • newline_style = "Unix": Unix-style line endings.

Rationale

These configurations promote consistent code formatting, reducing inconsistencies across the codebase. By following these standards, the team can ensure that code reviews and merges proceed smoothly, minimizing formatting-related issues.

Instructions for Team Members

  • Editor Integration:
    Ensure your IDE or code editor supports .editorconfig and rustfmt.toml.

  • Use cargo fmt:
    After merging this PR, run cargo fmt to apply the Rust-specific formatting rules.

  • Automated Checks:
    If using a continuous integration (CI) system, add a step to verify that Rust code is formatted with cargo fmt -- --check.

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.

None yet

1 participant