-
Notifications
You must be signed in to change notification settings - Fork 7
ADR: add rust linting & formatting ADR proposal #80
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
Draft
theswiftfox
wants to merge
2
commits into
main
Choose a base branch
from
theswiftfox/adr_rust_style
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <!-- | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2025 Contributors to Eclipse OpenSOVD | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
| --> | ||
|
|
||
| --- | ||
| # Configuration for the Jekyll template "Just the Docs" | ||
|
|
||
| parent: Decisions | ||
| nav_order: 100 | ||
| title: Define common linting and formating rules for Rust in OpenSOVD | ||
|
|
||
| status: "proposed" | ||
| date: 2026-02-6 | ||
| --- | ||
|
|
||
| # Define common linting and formating rules for Rust in OpenSOVD | ||
|
|
||
| ## Context and Problem Statement | ||
|
|
||
| The goal is to formalize the usage of linting rules for rust using clippy and | ||
| set common codestyle rules applied through rustfmt. | ||
| This will help having a single style across the different components which | ||
| improves understandability and readability across the project context and hence | ||
| facilitates easier maintainability long-term. | ||
|
|
||
| ## Considered Options | ||
|
|
||
| - Adopting the existing ruleset used in OpenSOVD CDA | ||
| [[1]](https://github.com/eclipse-opensovd/classic-diagnostic-adapter/blob/main/CODESTYLE.md) | ||
| [[2]](https://github.com/eclipse-opensovd/classic-diagnostic-adapter/blob/main/Cargo.toml#L124) | ||
| - Defining a new set of common rules | ||
|
|
||
| ## Decision Outcome | ||
|
|
||
| TBD | ||
|
|
||
| ## Pros and Cons of the Options | ||
|
|
||
| ### Adopting the existing ruleset used in OpenSOVD CDA | ||
|
|
||
| The ruleset in the CDA is based on the [clippy::pedantic](https://doc.rust-lang.org/stable/clippy/lints.html#pedantic) | ||
| set of lints with additional formatting rules related to import grouping and | ||
| ordering. | ||
| In addition to the pedantic ruleset following lints are explicitly enabled with | ||
| the reasoning attached: | ||
|
|
||
| ```toml | ||
| ## lints related to runtime panic behavior | ||
| # enforce only checked access to slices to avoid runtime panics | ||
| indexing_slicing = "deny" | ||
| # disallow any unwraps in the production code | ||
| # (unwrap in test code is explicitly allowed) | ||
| unwrap_used = "deny" | ||
| # enforce that arithmetic operations that can produce side effects always use | ||
| # either checked or explicit versions of the operations. eg. `.checked_add(...)` | ||
| # or `.saturating_sub(...)` to avoid unexpected runtime behavior or panics. | ||
| arithmetic_side_effects = "deny" | ||
| ## lints related to readability of code | ||
| # enforce that references are cloned via eg. `Arc::clone` instead of `.clone()` | ||
| # making it explit that a reference is cloned here and not the underlying data. | ||
| clone_on_ref_ptr = "warn" | ||
| # enforce that the type suffix of a literal is always appended directly | ||
| # eg. 12u8 instead of 12_u8 | ||
| separated_literal_suffix = "deny" | ||
| ``` | ||
|
|
||
| - Good: the relatively high restrictions enforce via tooling that contributions | ||
| need to have a specific codestyle and coding standard, which makes it easier on | ||
| the reviews | ||
|
|
||
| ### Defining a new set of common rules | ||
|
|
||
| With this option the idea is to take a look at what the CDA currently does and | ||
| mark things that people deem too restrictive as optional with appropriate | ||
| recommendations attached. | ||
|
|
||
| - Good: potentially easier for new projects built upon existing codebases to | ||
| adapt to | ||
| - Negative: Could potentially lead to more fragmentation with regards to codestyle | ||
| across the project | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the advantage of enforcing this? maybe add a short rationale here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making it explicit that a reference is cloned, not the data that is referenced to (1:1 the reasoning clippy gives for the lint)
I can add this a short oneline reason though, thanks :)