Skip to content

Commit 915d3d1

Browse files
committed
Enable printf-string-formatting fix with comments on right-hand side
1 parent af88ffc commit 915d3d1

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

crates/ruff_linter/resources/test/fixtures/pyupgrade/UP031_0.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,10 @@
110110
"%s" % (
111111
x, # comment
112112
)
113+
114+
115+
path = "%s-%s-%s.pem" % (
116+
safe_domain_name(cn), # common name, which should be filename safe because it is IDNA-encoded, but in case of a malformed cert make sure it's ok to use as a filename
117+
cert.not_valid_after.date().isoformat().replace("-", ""), # expiration date
118+
hexlify(cert.fingerprint(hashes.SHA256())).decode("ascii")[0:8], # fingerprint prefix
119+
)

crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP031_0.py.snap

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ UP031_0.py:104:5: UP031 [*] Use format specifiers instead of percent format
896896
109 108 |
897897
110 109 | "%s" % (
898898

899-
UP031_0.py:110:1: UP031 Use format specifiers instead of percent format
899+
UP031_0.py:110:1: UP031 [*] Use format specifiers instead of percent format
900900
|
901901
108 | )
902902
109 |
@@ -907,4 +907,36 @@ UP031_0.py:110:1: UP031 Use format specifiers instead of percent format
907907
|
908908
= help: Replace with format specifiers
909909

910+
Unsafe fix
911+
107 107 | % (x,)
912+
108 108 | )
913+
109 109 |
914+
110 |-"%s" % (
915+
110 |+"{}".format(
916+
111 111 | x, # comment
917+
112 112 | )
918+
113 113 |
919+
920+
UP031_0.py:115:8: UP031 [*] Use format specifiers instead of percent format
921+
|
922+
115 | path = "%s-%s-%s.pem" % (
923+
| ________^
924+
116 | | safe_domain_name(cn), # common name, which should be filename safe because it is IDNA-encoded, but in case of a malformed cert make sure it's ok to use as a filename
925+
117 | | cert.not_valid_after.date().isoformat().replace("-", ""), # expiration date
926+
118 | | hexlify(cert.fingerprint(hashes.SHA256())).decode("ascii")[0:8], # fingerprint prefix
927+
119 | | )
928+
| |_^ UP031
929+
|
930+
= help: Replace with format specifiers
931+
932+
Unsafe fix
933+
112 112 | )
934+
113 113 |
935+
114 114 |
936+
115 |-path = "%s-%s-%s.pem" % (
937+
115 |+path = "{}-{}-{}.pem".format(
938+
116 116 | safe_domain_name(cn), # common name, which should be filename safe because it is IDNA-encoded, but in case of a malformed cert make sure it's ok to use as a filename
939+
117 117 | cert.not_valid_after.date().isoformat().replace("-", ""), # expiration date
940+
118 118 | hexlify(cert.fingerprint(hashes.SHA256())).decode("ascii")[0:8], # fingerprint prefix
941+
910942

0 commit comments

Comments
 (0)