mformat: A triple string with a ' in it cannot be simplified

The following is valid meson:
```meson
a = '''This string can't be simplified'''
```
which cannot be simplified because of the `'` in it, as
```meson
a = 'This string can't be simplified'
```
Is invalid.

Potentially we could convert that with escapes, but it seems reasonable
to me to leave this, since it may be desirable to not have lots of
escapes in a string. `'''I can't believe it's her's!'''` is much more
readable than `'I can\'t believe it\'s her\'s!'`, for example.

Closes: #13564
pull/13581/head
Dylan Baker 3 months ago
parent ab3cfc2da1
commit df70680723
  1. 2
      mesonbuild/mformat.py
  2. 1
      test cases/format/5 transform/default.expected.meson
  3. 1
      test cases/format/5 transform/muon.expected.meson
  4. 1
      test cases/format/5 transform/options.expected.meson
  5. 1
      test cases/format/5 transform/source.meson

@ -338,7 +338,7 @@ class TrimWhitespaces(FullAstVisitor):
self.enter_node(node)
if self.config.simplify_string_literals:
if node.is_multiline and '\n' not in node.value:
if node.is_multiline and not any(x in node.value for x in ['\n', "'"]):
node.is_multiline = False
node.value = node.escape()

@ -47,6 +47,7 @@ d = {'a': 1, 'b': 2, 'c': 3}
# string conversion
'This is not a multiline'
'This is not a fstring'
'''This isn't convertible'''
# group arg value
arguments = [

@ -47,6 +47,7 @@ d = {'a': 1, 'b': 2, 'c': 3}
# string conversion
'''This is not a multiline'''
f'This is not a fstring'
'''This isn't convertible'''
# group arg value
arguments = [

@ -29,6 +29,7 @@ d = {
# string conversion
'This is not a multiline'
'This is not a fstring'
'''This isn't convertible'''
# group arg value
arguments = [

@ -29,6 +29,7 @@ d = {'a': 1, 'b': 2, 'c': 3}
# string conversion
'''This is not a multiline'''
f'This is not a fstring'
'''This isn't convertible'''
# group arg value
arguments = ['a', '--opt_a', 'opt_a_value', 'b', 'c', '--opt_d', '--opt_e', 'opt_e_value',

Loading…
Cancel
Save