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
a9b3be1c
Kaydet (Commit)
a9b3be1c
authored
Tem 15, 2017
tarafından
Anthony Sottile
Kaydeden (comit)
GitHub
Tem 15, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #14 from asottile/single_pass
Change back to single pass now that it is top-down
üst
0139612d
a6a2c5f0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
32 deletions
+4
-32
add_trailing_comma.py
add_trailing_comma.py
+4
-32
No files found.
add_trailing_comma.py
Dosyayı görüntüle @
a9b3be1c
...
@@ -254,7 +254,7 @@ def _find_literal(literal, i, tokens):
...
@@ -254,7 +254,7 @@ def _find_literal(literal, i, tokens):
return
_find_simple
(
i
,
tokens
)
return
_find_simple
(
i
,
tokens
)
def
_fix_
comma_and_unhug
(
fix_data
,
add_comma
,
tokens
):
def
_fix_
brace
(
fix_data
,
add_comma
,
tokens
):
first_brace
,
last_brace
=
fix_data
.
braces
first_brace
,
last_brace
=
fix_data
.
braces
# Figure out if either of the braces are "hugging"
# Figure out if either of the braces are "hugging"
...
@@ -317,13 +317,9 @@ def _fix_comma_and_unhug(fix_data, add_comma, tokens):
...
@@ -317,13 +317,9 @@ def _fix_comma_and_unhug(fix_data, add_comma, tokens):
if
add_comma
and
tokens
[
i
]
.
src
!=
','
and
i
+
1
!=
last_brace
:
if
add_comma
and
tokens
[
i
]
.
src
!=
','
and
i
+
1
!=
last_brace
:
tokens
.
insert
(
i
+
1
,
Token
(
'OP'
,
','
))
tokens
.
insert
(
i
+
1
,
Token
(
'OP'
,
','
))
# Fix trailing brace to match leading indentation
def
_fix_trailing_brace
(
fix_data
,
tokens
):
_
,
last_brace
=
fix_data
.
braces
back_1
=
tokens
[
last_brace
-
1
]
back_1
=
tokens
[
last_brace
-
1
]
back_2
=
tokens
[
last_brace
-
2
]
back_2
=
tokens
[
last_brace
-
2
]
if
(
if
(
back_1
.
name
==
UNIMPORTANT_WS
and
back_1
.
name
==
UNIMPORTANT_WS
and
back_2
.
name
==
'NL'
and
back_2
.
name
==
'NL'
and
...
@@ -373,31 +369,7 @@ def _fix_src(contents_text, py35_plus):
...
@@ -373,31 +369,7 @@ def _fix_src(contents_text, py35_plus):
add_comma
=
False
add_comma
=
False
if
fix_data
is
not
None
:
if
fix_data
is
not
None
:
_fix_comma_and_unhug
(
fix_data
,
add_comma
,
tokens
)
_fix_brace
(
fix_data
,
add_comma
,
tokens
)
# need to additionally handle literals afterwards as tuples report
# their starting index as the first element, which may be one of the
# above things.
if
key
in
visitor
.
literals
:
fix_data
=
_find_literal
(
visitor
.
literals
[
key
],
i
,
tokens
)
if
fix_data
is
not
None
:
_fix_comma_and_unhug
(
fix_data
,
True
,
tokens
)
# Need a second pass to fix trailing braces after indentation is fixed
for
i
,
token
in
_changing_list
(
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
)
# Handle parenthesized things
elif
token
.
src
==
'('
:
fix_data
=
_find_simple
(
i
,
tokens
)
if
fix_data
is
not
None
:
_fix_trailing_brace
(
fix_data
,
tokens
)
# need to additionally handle literals afterwards as tuples report
# need to additionally handle literals afterwards as tuples report
# their starting index as the first element, which may be one of the
# their starting index as the first element, which may be one of the
...
@@ -405,7 +377,7 @@ def _fix_src(contents_text, py35_plus):
...
@@ -405,7 +377,7 @@ def _fix_src(contents_text, py35_plus):
if
key
in
visitor
.
literals
:
if
key
in
visitor
.
literals
:
fix_data
=
_find_literal
(
visitor
.
literals
[
key
],
i
,
tokens
)
fix_data
=
_find_literal
(
visitor
.
literals
[
key
],
i
,
tokens
)
if
fix_data
is
not
None
:
if
fix_data
is
not
None
:
_fix_
trailing_brace
(
fix_data
,
tokens
)
_fix_
brace
(
fix_data
,
True
,
tokens
)
return
tokens_to_src
(
tokens
)
return
tokens_to_src
(
tokens
)
...
...
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