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

Provide some code style for rust #499

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

Provide some code style for rust #499

wants to merge 1 commit into from

Conversation

Hinton
Copy link
Member

@Hinton Hinton commented Dec 20, 2024

📔 Objective

Write some code style guidelines for writing rust.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@Hinton Hinton requested a review from a team as a code owner December 20, 2024 13:32
@Hinton Hinton requested review from dani-garcia and coroiu December 20, 2024 13:32
Copy link

Deploying contributing-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 860c757
Status: ✅  Deploy successful!
Preview URL: https://0a28b182.contributing-docs.pages.dev
Branch Preview URL: https://rust-style.contributing-docs.pages.dev

View logs

Copy link

Logo
Checkmarx One – Scan Summary & Detailsfbccaf4e-52d1-4c8c-9eda-06c4adc72694

New Issues

Severity Issue Source File / Package Checkmarx Insight
HIGH Cxdca8e59f-8bfe Npm-inflight-1.0.6 Vulnerable Package
MEDIUM Cx14b19a02-387a Npm-body-parser-1.20.3 Vulnerable Package
LOW Cx8bc4df28-fcf5 Npm-debug-2.6.9 Vulnerable Package
LOW Cx8bc4df28-fcf5 Npm-debug-4.3.7 Vulnerable Package


## Discourage match

Rust often provide good alternatives to doing match on `Option`s and `Result`s.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit(non-blocking): looks weird and works without the "s"

Suggested change
Rust often provide good alternatives to doing match on `Option`s and `Result`s.
Rust often provide good alternatives to doing match on `Option` and `Result`.


Some scenarios where `expect` are allowed are:

- Calling libraries that guarantee that the allowed inputs never results in Err or None.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Calling libraries that guarantee that the allowed inputs never results in Err or None.
- Calling libraries that guarantee that the allowed inputs never results in `Err` or `None`.


## Avoid panics

Panics are forbidden in the Bitwarden codebase outside of tests. Errors should be handled gracefully
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically expect results in a panic, therefore panics are not forbidden, only unwrap is forbidden.

suggestion:

Suggested change
Panics are forbidden in the Bitwarden codebase outside of tests. Errors should be handled gracefully
Panics are highly discouraged in the Bitwarden codebase outside of tests. Errors should be handled gracefully

### Options

We use `clippy` to enforce general guidelines for working with
[`Option`](https://doc.rust-lang.org/std/option/enum.Option.html)s. Generally reach for methods
Copy link
Contributor

Choose a reason for hiding this comment

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

nit(non-blocking): same here, works without the "s"

Suggested change
[`Option`](https://doc.rust-lang.org/std/option/enum.Option.html)s. Generally reach for methods
[`Option`](https://doc.rust-lang.org/std/option/enum.Option.html). Generally reach for methods


### Results

When working on [`Result`](https://doc.rust-lang.org/std/result/enum.Result.html)s it might be
Copy link
Contributor

Choose a reason for hiding this comment

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

nit(non-blocking):

Suggested change
When working on [`Result`](https://doc.rust-lang.org/std/result/enum.Result.html)s it might be
When working with [`Result`](https://doc.rust-lang.org/std/result/enum.Result.html) it might be

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