Format UnaryExpr

<!--
Thank you for contributing to Ruff! To help us out with reviewing, please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

This PR adds basic formatting for unary expressions.

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

I added a new `unary.py` with custom test cases
This commit is contained in:
Micha Reiser 2023-06-21 10:09:47 +02:00 committed by GitHub
parent 3973836420
commit 1336ca601b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 623 additions and 115 deletions

View file

@ -42,7 +42,7 @@ pub(super) fn default_expression_needs_parentheses(
}
/// Configures if the expression should be parenthesized.
#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub enum Parenthesize {
/// Parenthesize the expression if it has parenthesis in the source.
#[default]
@ -56,11 +56,11 @@ pub enum Parenthesize {
}
impl Parenthesize {
const fn is_if_breaks(self) -> bool {
pub(crate) const fn is_if_breaks(self) -> bool {
matches!(self, Parenthesize::IfBreaks)
}
const fn is_preserve(self) -> bool {
pub(crate) const fn is_preserve(self) -> bool {
matches!(self, Parenthesize::Preserve)
}
}