Chromium Code Reviews| Index: Tools/Scripts/webkitpy/formatter/fix_single_quote_strings.py |
| diff --git a/Tools/Scripts/webkitpy/formatter/fix_single_quote_strings.py b/Tools/Scripts/webkitpy/formatter/fix_single_quote_strings.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..996c0cd0b639d2319e0083e93018d77fa14d2b34 |
| --- /dev/null |
| +++ b/Tools/Scripts/webkitpy/formatter/fix_single_quote_strings.py |
| @@ -0,0 +1,29 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +""" |
| +A 2to3 fixer that converts all string literals to use single quotes. |
| + |
| +Strings that contain single quotes will not be modified. Prefixed string |
| +literals will also not be modified. This affect double-quoted strings but |
| +not triple-double-quote strings. |
| + |
| +""" |
| + |
| +from lib2to3.fixer_base import BaseFix |
| +from lib2to3.pgen2 import token |
| + |
| + |
| +class FixSingleQuoteStrings(BaseFix): |
|
eseidel
2014/09/09 23:10:55
I might have just put these both in the same file
Dirk Pranke
2014/09/09 23:32:22
Unfortunately, the way lib2to3 works each of these
|
| + |
| + explicit = True |
| + _accept_type = token.STRING |
| + |
| + def match(self, node): |
| + res = node.value.startswith('"') and not node.value.startswith('"""') and "'" not in node.value[1:-1] |
| + return res |
| + |
| + def transform(self, node, results): |
| + node.value = node.value.replace('"', "'") |
| + node.changed() |