Pass FormatContext to NeedsParentheses

<!--
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

I started working on this because I assumed that I would need access to options inside of `NeedsParantheses` but it then turned out that I won't. 
Anyway, it kind of felt nice to pass fewer arguments. So I'm gonna put this out here to get your feedback if you prefer this over passing individual fiels. 

Oh, I sneeked in another change. I renamed `context.contents` to `source`. `contents` is too generic and doesn't tell you anything. 

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

## Test Plan

It compiles
This commit is contained in:
Micha Reiser 2023-07-11 14:28:50 +02:00 committed by GitHub
parent 9a8ba58b4c
commit 8665a1a19d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 138 additions and 174 deletions

View file

@ -36,7 +36,7 @@ impl FormatNodeRule<Arguments> for FormatArguments {
let comments = f.context().comments().clone();
let dangling = comments.dangling_comments(item);
let (slash, star) = find_argument_separators(f.context().contents(), item);
let (slash, star) = find_argument_separators(f.context().source(), item);
let format_inner = format_with(|f: &mut PyFormatter| {
let separator = format_with(|f| write!(f, [text(","), soft_line_break_or_space()]));
@ -142,7 +142,7 @@ impl FormatNodeRule<Arguments> for FormatArguments {
let maybe_comma_token = if ends_with_pos_only_argument_separator {
// `def a(b, c, /): ... `
let mut tokens =
SimpleTokenizer::starts_at(last_node.end(), f.context().contents())
SimpleTokenizer::starts_at(last_node.end(), f.context().source())
.skip_trivia();
let comma = tokens.next();
@ -153,7 +153,7 @@ impl FormatNodeRule<Arguments> for FormatArguments {
tokens.next()
} else {
first_non_trivia_token(last_node.end(), f.context().contents())
first_non_trivia_token(last_node.end(), f.context().source())
};
if maybe_comma_token.map_or(false, |token| token.kind() == TokenKind::Comma) {