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

Implement B903 and B907 flake8-bugbear rules #13600

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

agpt8
Copy link

@agpt8 agpt8 commented Oct 2, 2024

Fixes #3758

Implement B903 and B907 flake8-bugbear rules in Ruff.

  • Add crates/ruff_linter/src/rules/flake8_bugbear/rules/b903.rs to implement B903 rule for data classes that only set attributes in an __init__ method.
  • Add crates/ruff_linter/src/rules/flake8_bugbear/rules/b907.rs to implement B907 rule to replace f"'{foo}'" with f"{foo!r}".
  • Update crates/ruff_linter/src/rules/flake8_bugbear/mod.rs to include B903 and B907 rules.
  • Add test cases for B903 and B907 rules in crates/ruff_linter/src/rules/flake8_bugbear/tests.rs.

Fixes astral-sh#3758

Implement B903 and B907 flake8-bugbear rules in Ruff.

* Add `crates/ruff_linter/src/rules/flake8_bugbear/rules/b903.rs` to implement B903 rule for data classes that only set attributes in an `__init__` method.
* Add `crates/ruff_linter/src/rules/flake8_bugbear/rules/b907.rs` to implement B907 rule to replace f"'{foo}'" with f"{foo!r}".
* Update `crates/ruff_linter/src/rules/flake8_bugbear/mod.rs` to include B903 and B907 rules.
* Add test cases for B903 and B907 rules in `crates/ruff_linter/src/rules/flake8_bugbear/tests.rs`.
* **New Rules**
  - Add `UseDataclassesForDataClasses` variant to `Rule` enum
  - Add `FStringSingleQuotes` variant to `Rule` enum
* **Update `Rule` enum**
  - Add `UseDataclassesForDataClasses` for B903
  - Add `FStringSingleQuotes` for B907

* **Update imports in `mod.rs`**
  - Add `use_dataclasses_for_data_classes::*`
  - Add `f_string_single_quotes::*`
@dhruvmanila
Copy link
Member

FYI, there's another implementation of B903 at #12259

@agpt8
Copy link
Author

agpt8 commented Oct 4, 2024

Thanks @dhruvmanila. I'll remove the B903 implementation and instead create a PR for B907

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.

Implement more flake8-bugbear opinionated rules
2 participants