Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
A
add-trailing-comma
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
add-trailing-comma
Commits
7c203d43
Kaydet (Commit)
7c203d43
authored
Tem 14, 2017
tarafından
Anthony Sottile
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Adjust trailing brace indentation to match opening brace
üst
07422afc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
6 deletions
+69
-6
README.md
README.md
+1
-3
add_trailing_comma.py
add_trailing_comma.py
+30
-0
add_trailing_comma_test.py
tests/add_trailing_comma_test.py
+38
-3
No files found.
README.md
Dosyayı görüntüle @
7c203d43
...
...
@@ -146,9 +146,7 @@ being a syntax error.
+)
```
## Planned features
### Match closing brace indentation
### match closing brace indentation
```
diff
x = [
...
...
add_trailing_comma.py
Dosyayı görüntüle @
7c203d43
...
...
@@ -310,6 +310,21 @@ def _fix_comma_and_unhug(fix_data, add_comma, tokens):
tokens
.
insert
(
i
+
1
,
Token
(
'OP'
,
','
))
def
_fix_trailing_brace
(
fix_data
,
tokens
):
_
,
last_brace
=
fix_data
.
braces
back_1
=
tokens
[
last_brace
-
1
]
back_2
=
tokens
[
last_brace
-
2
]
if
(
back_1
.
name
==
UNIMPORTANT_WS
and
back_2
.
name
==
'NL'
and
len
(
back_1
.
src
)
!=
fix_data
.
initial_indent
):
new_indent
=
fix_data
.
initial_indent
*
' '
tokens
[
last_brace
-
1
]
=
back_1
.
_replace
(
src
=
new_indent
)
def
_fix_src
(
contents_text
,
py35_plus
):
try
:
ast_obj
=
ast_parse
(
contents_text
)
...
...
@@ -343,6 +358,21 @@ def _fix_src(contents_text, py35_plus):
if
fix_data
is
not
None
:
_fix_comma_and_unhug
(
fix_data
,
add_comma
,
tokens
)
# Need a second pass to fix trailing braces after indentation is fixed
for
i
,
token
in
reversed
(
tuple
(
enumerate
(
tokens
))):
key
=
Offset
(
token
.
line
,
token
.
utf8_byte_offset
)
fix_data
=
None
if
key
in
visitor
.
calls
:
fix_data
=
_find_call
(
visitor
.
calls
[
key
],
i
,
tokens
)
elif
key
in
visitor
.
funcs
:
fix_data
=
_find_call
(
visitor
.
funcs
[
key
],
i
,
tokens
)
elif
key
in
visitor
.
literals
:
fix_data
=
_find_literal
(
visitor
.
literals
[
key
],
i
,
tokens
)
if
fix_data
is
not
None
:
_fix_trailing_brace
(
fix_data
,
tokens
)
return
tokens_to_src
(
tokens
)
...
...
tests/add_trailing_comma_test.py
Dosyayı görüntüle @
7c203d43
...
...
@@ -393,14 +393,13 @@ def test_noop_unhugs(src):
' },
\n
'
' }'
,
# TODO: need to adjust trailing braces
'{
\n
'
" 'foo': 'bar',
\n
"
" 'baz':
\n
"
' {
\n
'
" 'id': 1,
\n
"
' },
\n
'
'
}'
,
'
},
\n
'
'}'
,
),
(
'f(g(
\n
'
...
...
@@ -466,6 +465,42 @@ def test_fix_unhugs_py3_only(src, expected):
assert
_fix_src
(
src
,
py35_plus
=
False
)
==
expected
@pytest.mark.parametrize
(
'src'
,
(
'[]'
,
'x = [
\n
'
' 1, 2, 3,
\n
'
']'
,
'y = [
\n
'
' [
\n
'
' 1, 2, 3, 4,
\n
'
' ],
\n
'
']'
,
),
)
def
test_noop_trailing_brace
(
src
):
assert
_fix_src
(
src
,
py35_plus
=
False
)
==
src
@pytest.mark.parametrize
(
(
'src'
,
'expected'
),
(
(
'x = [
\n
'
' 1,
\n
'
' ]'
,
'x = [
\n
'
' 1,
\n
'
']'
,
),
),
)
def
test_fix_trailing_brace
(
src
,
expected
):
assert
_fix_src
(
src
,
py35_plus
=
False
)
==
expected
def
test_main_trivial
():
assert
main
(())
==
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment