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
3a5858c3
Kaydet (Commit)
3a5858c3
authored
Tem 12, 2017
tarafından
Anthony Sottile
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Some minor renaming
üst
cfaec3b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
15 deletions
+16
-15
add_trailing_comma.py
add_trailing_comma.py
+4
-3
add_trailing_comma_test.py
tests/add_trailing_comma_test.py
+12
-12
No files found.
add_trailing_comma.py
Dosyayı görüntüle @
3a5858c3
...
...
@@ -239,7 +239,7 @@ def _fix_literal(literal, i, tokens):
_fix_inner
(
brace_start
,
brace_end
,
i
,
tokens
)
def
_fix_
commas
(
contents_text
,
py35_plus
):
def
_fix_
src
(
contents_text
,
py35_plus
):
try
:
ast_obj
=
ast_parse
(
contents_text
)
except
SyntaxError
:
...
...
@@ -247,6 +247,7 @@ def _fix_commas(contents_text, py35_plus):
visitor
=
FindNodes
()
visitor
.
visit
(
ast_obj
)
py35_plus
=
py35_plus
or
visitor
.
has_new_syntax
tokens
=
src_to_tokens
(
contents_text
)
for
i
,
token
in
reversed
(
tuple
(
enumerate
(
tokens
))):
...
...
@@ -254,7 +255,7 @@ def _fix_commas(contents_text, py35_plus):
if
key
in
visitor
.
calls
:
call
=
visitor
.
calls
[
key
]
# Only fix stararg calls if asked to
if
not
call
.
star_args
or
py35_plus
or
visitor
.
has_new_syntax
:
if
not
call
.
star_args
or
py35_plus
:
_fix_call
(
call
,
i
,
tokens
)
elif
key
in
visitor
.
literals
:
_fix_literal
(
visitor
.
literals
[
key
],
i
,
tokens
)
...
...
@@ -275,7 +276,7 @@ def fix_file(filename, args):
print
(
'{} is non-utf-8 (not supported)'
.
format
(
filename
))
return
1
contents_text
=
_fix_
commas
(
contents_text
,
args
.
py35_plus
)
contents_text
=
_fix_
src
(
contents_text
,
args
.
py35_plus
)
if
contents_text
!=
contents_text_orig
:
print
(
'Rewriting {}'
.
format
(
filename
))
...
...
tests/add_trailing_comma_test.py
Dosyayı görüntüle @
3a5858c3
...
...
@@ -7,7 +7,7 @@ import sys
import
pytest
from
add_trailing_comma
import
_fix_
commas
from
add_trailing_comma
import
_fix_
src
from
add_trailing_comma
import
main
...
...
@@ -49,7 +49,7 @@ xfailif_lt_py35 = pytest.mark.xfail(sys.version_info < (3, 5), reason='py35+')
),
)
def
test_fix_calls_noops
(
src
):
ret
=
_fix_
commas
(
src
,
py35_plus
=
False
)
ret
=
_fix_
src
(
src
,
py35_plus
=
False
)
assert
ret
==
src
...
...
@@ -66,7 +66,7 @@ def test_ignores_invalid_ast_node():
' """
\n
'
')'
)
assert
_fix_
commas
(
src
,
py35_plus
=
False
)
==
src
assert
_fix_
src
(
src
,
py35_plus
=
False
)
==
src
def
test_py35_plus_rewrite
():
...
...
@@ -75,7 +75,7 @@ def test_py35_plus_rewrite():
' *args
\n
'
')'
)
ret
=
_fix_
commas
(
src
,
py35_plus
=
True
)
ret
=
_fix_
src
(
src
,
py35_plus
=
True
)
assert
ret
==
(
'x(
\n
'
' *args,
\n
'
...
...
@@ -98,7 +98,7 @@ def test_py35_plus_rewrite():
def
test_auto_detected_py35_plus_rewrite
(
syntax
):
src
=
syntax
+
'x(
\n
*args
\n
)'
expected
=
syntax
+
'x(
\n
*args,
\n
)'
assert
_fix_
commas
(
src
,
py35_plus
=
False
)
==
expected
assert
_fix_
src
(
src
,
py35_plus
=
False
)
==
expected
@pytest.mark.parametrize
(
...
...
@@ -134,7 +134,7 @@ def test_auto_detected_py35_plus_rewrite(syntax):
),
)
def
test_fixes_calls
(
src
,
expected
):
assert
_fix_
commas
(
src
,
py35_plus
=
False
)
==
expected
assert
_fix_
src
(
src
,
py35_plus
=
False
)
==
expected
@pytest.mark.parametrize
(
...
...
@@ -147,7 +147,7 @@ def test_fixes_calls(src, expected):
),
)
def
test_noop_one_line_literals
(
src
):
assert
_fix_
commas
(
src
,
py35_plus
=
False
)
==
src
assert
_fix_
src
(
src
,
py35_plus
=
False
)
==
src
@pytest.mark.parametrize
(
...
...
@@ -194,7 +194,7 @@ def test_noop_one_line_literals(src):
),
)
def
test_fixes_literals
(
src
,
expected
):
assert
_fix_
commas
(
src
,
py35_plus
=
False
)
==
expected
assert
_fix_
src
(
src
,
py35_plus
=
False
)
==
expected
@xfailif_lt_py35
...
...
@@ -240,7 +240,7 @@ def test_fixes_literals(src, expected):
),
)
def
test_fixes_py35_plus_literals
(
src
,
expected
):
assert
_fix_
commas
(
src
,
py35_plus
=
False
)
==
expected
assert
_fix_
src
(
src
,
py35_plus
=
False
)
==
expected
def
test_noop_tuple_literal_without_braces
():
...
...
@@ -250,7 +250,7 @@ def test_noop_tuple_literal_without_braces():
' 2,
\\\n
'
' 3'
)
assert
_fix_
commas
(
src
,
py35_plus
=
False
)
==
src
assert
_fix_
src
(
src
,
py35_plus
=
False
)
==
src
@pytest.mark.parametrize
(
...
...
@@ -276,7 +276,7 @@ def test_noop_tuple_literal_without_braces():
),
)
def
test_noop_function_defs
(
src
):
assert
_fix_
commas
(
src
,
py35_plus
=
False
)
==
src
assert
_fix_
src
(
src
,
py35_plus
=
False
)
==
src
@pytest.mark.parametrize
(
...
...
@@ -294,7 +294,7 @@ def test_noop_function_defs(src):
),
)
def
test_fixes_defs
(
src
,
expected
):
assert
_fix_
commas
(
src
,
py35_plus
=
False
)
==
expected
assert
_fix_
src
(
src
,
py35_plus
=
False
)
==
expected
def
test_main_trivial
():
...
...
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