Repository: asottile/add-trailing-comma

Issue:
escaped newlines are throwing off indent detection
This should be a noop:

```python
x = y.\
    foo(
        bar,
    )
```

However, this is the current behaviour:

```diff
 x = y.\
     foo(
         bar,
-    )
+)
```

Might need help from https://github.com/asottile/tokenize-rt/issues/1

Discussion:

Patch:
diff --git a/add_trailing_comma.py b/add_trailing_comma.py
index 7a571a7..882cb9d 100644
--- a/add_trailing_comma.py
+++ b/add_trailing_comma.py
@@ -7,6 +7,7 @@ import collections
 import io
 import sys
 
+from tokenize_rt import ESCAPED_NL
 from tokenize_rt import src_to_tokens
 from tokenize_rt import Token
 from tokenize_rt import tokens_to_src
@@ -20,8 +21,8 @@ Literal = collections.namedtuple('Literal', ('node', 'backtrack'))
 Literal.__new__.__defaults__ = (False,)
 Fix = collections.namedtuple('Fix', ('braces', 'multi_arg', 'initial_indent'))
 
-NEWLINES = frozenset(('NEWLINE', 'NL'))
-NON_CODING_TOKENS = frozenset(('COMMENT', 'NL', UNIMPORTANT_WS))
+NEWLINES = frozenset((ESCAPED_NL, 'NEWLINE', 'NL'))
+NON_CODING_TOKENS = frozenset(('COMMENT', ESCAPED_NL, 'NL', UNIMPORTANT_WS))
 INDENT_TOKENS = frozenset(('INDENT', UNIMPORTANT_WS))
 START_BRACES = frozenset(('(', '{', '['))
 END_BRACES = frozenset((')', '}', ']'))
diff --git a/setup.py b/setup.py
index 39c86ff..828d6a9 100644
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@ setup(
         'Programming Language :: Python :: Implementation :: CPython',
         'Programming Language :: Python :: Implementation :: PyPy',
     ],
-    install_requires=['tokenize-rt'],
+    install_requires=['tokenize-rt>=2'],
     py_modules=['add_trailing_comma'],
     entry_points={
         'console_scripts': ['add-trailing-comma = add_trailing_comma:main'],


Test patch:
diff --git a/tests/add_trailing_comma_test.py b/tests/add_trailing_comma_test.py
index 9f67fb3..d41af5c 100644
--- a/tests/add_trailing_comma_test.py
+++ b/tests/add_trailing_comma_test.py
@@ -501,6 +501,11 @@ def test_fix_unhugs_py3_only(src, expected):
         '        1, 2, 3, 4,\n'
         '    ],\n'
         ']',
+        # Regression test for #11
+        'foo.\\\n'
+        '    bar(\n'
+        '        5,\n'
+        '    )',
     ),
 )
 def test_noop_trailing_brace(src):