mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:56 +00:00
Prefer the configured quote style
<!-- 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 extends the string formatting to respect the configured quote style. <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan Extended the string test with new cases and set it up to run twice: Once with the `quote_style: Doube`, and once with `quote_style: Single` single and double quotes. <!-- How was it tested? -->
This commit is contained in:
parent
f18a1f70de
commit
313711aaf9
5 changed files with 165 additions and 24 deletions
|
@ -18,7 +18,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
|||
|
||||
# Prefer double quotes for string with equal amount of single and double quotes
|
||||
'" \' " " \'\''
|
||||
"' \" '' \" \" '"
|
||||
"' \" '' \" \""
|
||||
|
||||
"\\' \"\""
|
||||
'\\\' ""'
|
||||
|
@ -53,12 +53,30 @@ String ""
|
|||
String """
|
||||
'''
|
||||
|
||||
'''Multiline
|
||||
String "'''
|
||||
|
||||
"""Multiline
|
||||
String '''
|
||||
"""
|
||||
|
||||
"""Multiline
|
||||
String '"""
|
||||
|
||||
'''Multiline
|
||||
String \"\"\"
|
||||
'''
|
||||
```
|
||||
|
||||
## Output
|
||||
## Outputs
|
||||
### Output 1
|
||||
```
|
||||
indent-style = Spaces, size: 4
|
||||
line-width = 88
|
||||
quote-style = Double
|
||||
magic-trailing-comma = Respect
|
||||
```
|
||||
|
||||
```py
|
||||
"' test"
|
||||
'" test'
|
||||
|
@ -74,7 +92,7 @@ String \"\"\"
|
|||
|
||||
# Prefer double quotes for string with equal amount of single and double quotes
|
||||
"\" ' \" \" ''"
|
||||
"' \" '' \" \" '"
|
||||
"' \" '' \" \""
|
||||
|
||||
'\\\' ""'
|
||||
'\\\' ""'
|
||||
|
@ -109,10 +127,94 @@ String ""
|
|||
String """
|
||||
'''
|
||||
|
||||
'''Multiline
|
||||
String "'''
|
||||
|
||||
"""Multiline
|
||||
String '''
|
||||
"""
|
||||
|
||||
"""Multiline
|
||||
String '"""
|
||||
|
||||
"""Multiline
|
||||
String \"\"\"
|
||||
"""
|
||||
```
|
||||
|
||||
|
||||
### Output 2
|
||||
```
|
||||
indent-style = Spaces, size: 4
|
||||
line-width = 88
|
||||
quote-style = Single
|
||||
magic-trailing-comma = Respect
|
||||
```
|
||||
|
||||
```py
|
||||
"' test"
|
||||
'" test'
|
||||
|
||||
'" test'
|
||||
"' test"
|
||||
|
||||
# Prefer single quotes for string with more double quotes
|
||||
'\' " " \'\' " " \''
|
||||
|
||||
# Prefer double quotes for string with more single quotes
|
||||
'\' " " \'\' " " \''
|
||||
|
||||
# Prefer double quotes for string with equal amount of single and double quotes
|
||||
'" \' " " \'\''
|
||||
'\' " \'\' " "'
|
||||
|
||||
'\\\' ""'
|
||||
'\\\' ""'
|
||||
|
||||
|
||||
'Test'
|
||||
'Test'
|
||||
|
||||
r'Test'
|
||||
R'Test'
|
||||
|
||||
'This string will not include \
|
||||
backslashes or newline characters.'
|
||||
|
||||
if True:
|
||||
'This string will not include \
|
||||
backslashes or newline characters.'
|
||||
|
||||
'''Multiline
|
||||
String \"
|
||||
'''
|
||||
|
||||
'''Multiline
|
||||
String \'
|
||||
'''
|
||||
|
||||
'''Multiline
|
||||
String ""
|
||||
'''
|
||||
|
||||
'''Multiline
|
||||
String """
|
||||
'''
|
||||
|
||||
'''Multiline
|
||||
String "'''
|
||||
|
||||
"""Multiline
|
||||
String '''
|
||||
"""
|
||||
|
||||
"""Multiline
|
||||
String '"""
|
||||
|
||||
'''Multiline
|
||||
String \"\"\"
|
||||
'''
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue