mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Create dedicated is_*_enabled
functions for each preview style (#8988)
This commit is contained in:
parent
7e390d3772
commit
0bda1913d1
7 changed files with 39 additions and 11 deletions
|
@ -9,6 +9,7 @@ use crate::expression::is_expression_huggable;
|
|||
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
|
||||
use crate::other::commas;
|
||||
use crate::prelude::*;
|
||||
use crate::preview::is_hug_parens_with_braces_and_square_brackets_enabled;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatArguments;
|
||||
|
@ -177,8 +178,7 @@ fn is_single_argument_parenthesized(argument: &Expr, call_end: TextSize, source:
|
|||
/// Hugging should only be applied to single-argument collections, like lists, or starred versions
|
||||
/// of those collections.
|
||||
fn is_argument_huggable(item: &Arguments, context: &PyFormatContext) -> bool {
|
||||
let options = context.options();
|
||||
if !options.preview().is_enabled() {
|
||||
if !is_hug_parens_with_braces_and_square_brackets_enabled(context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ fn is_argument_huggable(item: &Arguments, context: &PyFormatContext) -> bool {
|
|||
};
|
||||
|
||||
// If the expression itself isn't huggable, then we can't hug it.
|
||||
if !is_expression_huggable(arg, options) {
|
||||
if !is_expression_huggable(arg, context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -202,6 +202,8 @@ fn is_argument_huggable(item: &Arguments, context: &PyFormatContext) -> bool {
|
|||
return false;
|
||||
}
|
||||
|
||||
let options = context.options();
|
||||
|
||||
// If the expression has a trailing comma, then we can't hug it.
|
||||
if options.magic_trailing_comma().is_respect()
|
||||
&& commas::has_magic_trailing_comma(TextRange::new(arg.end(), item.end()), options, context)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue