From 915d3d1306d6f4edf5af9aaa3bc4366bd435a6f3 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 6 Dec 2023 22:00:58 -0500 Subject: [PATCH] Enable printf-string-formatting fix with comments on right-hand side --- .../test/fixtures/pyupgrade/UP031_0.py | 7 ++++ ...__rules__pyupgrade__tests__UP031_0.py.snap | 34 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP031_0.py b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP031_0.py index 9544e11c4c632c..00fef079b6e30c 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP031_0.py +++ b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP031_0.py @@ -110,3 +110,10 @@ "%s" % ( x, # comment ) + + +path = "%s-%s-%s.pem" % ( + 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 + cert.not_valid_after.date().isoformat().replace("-", ""), # expiration date + hexlify(cert.fingerprint(hashes.SHA256())).decode("ascii")[0:8], # fingerprint prefix +) diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP031_0.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP031_0.py.snap index a06ca5060c82bf..fd5827fcfa4139 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP031_0.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP031_0.py.snap @@ -896,7 +896,7 @@ UP031_0.py:104:5: UP031 [*] Use format specifiers instead of percent format 109 108 | 110 109 | "%s" % ( -UP031_0.py:110:1: UP031 Use format specifiers instead of percent format +UP031_0.py:110:1: UP031 [*] Use format specifiers instead of percent format | 108 | ) 109 | @@ -907,4 +907,36 @@ UP031_0.py:110:1: UP031 Use format specifiers instead of percent format | = help: Replace with format specifiers +ℹ Unsafe fix +107 107 | % (x,) +108 108 | ) +109 109 | +110 |-"%s" % ( + 110 |+"{}".format( +111 111 | x, # comment +112 112 | ) +113 113 | + +UP031_0.py:115:8: UP031 [*] Use format specifiers instead of percent format + | +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 | | ) + | |_^ UP031 + | + = help: Replace with format specifiers + +ℹ Unsafe fix +112 112 | ) +113 113 | +114 114 | +115 |-path = "%s-%s-%s.pem" % ( + 115 |+path = "{}-{}-{}.pem".format( +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 +117 117 | cert.not_valid_after.date().isoformat().replace("-", ""), # expiration date +118 118 | hexlify(cert.fingerprint(hashes.SHA256())).decode("ascii")[0:8], # fingerprint prefix +