summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-10-30 09:28:50 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-10-30 09:28:50 -0400
commit3d962a30a3f659978b96ef59811e8062867b358b (patch)
treee493f0e0df16849c0f45df277a1399e495433e38
parent5f20bf99f115c0227a320fa37bf7c6af44de0ce4 (diff)
downloadpython-coveragepy-git-3d962a30a3f659978b96ef59811e8062867b358b.tar.gz
style: remove implicit string concatenation
.. and also add trailing commas where needed to remove ambiguity. I used semgrep with this config: ``` rules: - id: implicit-string-concatenation pattern: | "$X" "$Y" languages: - python message: string cat BAD severity: INFO ``` Running it showed this: ``` $ semgrep --config=../lab/string-cat.yml coverage tests doc ci igor.py setup.py __main__.py Running 1 rules... setup.py severity:info rule:lab.implicit-string-concatenation: string cat BAD 128: 'https://tidelift.com/subscription/pkg/pypi-coverage' 129: '?utm_source=pypi-coverage&utm_medium=referral&utm_campaign=pypi' tests/test_api.py severity:info rule:lab.implicit-string-concatenation: string cat BAD 319: "!coverage.py: This is a private format, don't read it directly!" 320: '{"lines":{"/private/tmp/foo.py":[1,5,2,3]}}' tests/test_html.py severity:info rule:lab.implicit-string-concatenation: string cat BAD 614: ('<span class="key">if</span> <span class="num">1</span> ' 615: '<span class="op">&lt;</span> <span class="num">2</span>'), -------------------------------------------------------------------------------- 616: (' <span class="nam">a</span> ' 617: '<span class="op">=</span> <span class="num">3</span>'), -------------------------------------------------------------------------------- 665: ('<span class="key">if</span> <span class="nam">x</span> ' 666: '<span class="op">&lt;</span> <span class="num">2</span>'), -------------------------------------------------------------------------------- 667: (' <span class="nam">a</span> <span class="op">=</span> ' 668: '<span class="num">3</span>'), -------------------------------------------------------------------------------- 949: ('<span class="key">if</span> <span class="num">1</span> ' 950: '<span class="op">&lt;</span> <span class="num">2</span>'), -------------------------------------------------------------------------------- 951: (' <span class="nam">a</span> <span class="op">=</span> ' 952: '<span class="num">3</span>'), ran 1 rules on 134 files: 8 findings ``` This wasn't all of the instances, so I wrote a bug report: https://github.com/returntocorp/semgrep/issues/4184
-rw-r--r--setup.py2
-rw-r--r--tests/test_api.py2
-rw-r--r--tests/test_html.py48
3 files changed, 26 insertions, 26 deletions
diff --git a/setup.py b/setup.py
index fe9bad34..83553c92 100644
--- a/setup.py
+++ b/setup.py
@@ -125,7 +125,7 @@ setup_args = dict(
project_urls={
'Documentation': __url__,
'Funding': (
- 'https://tidelift.com/subscription/pkg/pypi-coverage'
+ 'https://tidelift.com/subscription/pkg/pypi-coverage' +
'?utm_source=pypi-coverage&utm_medium=referral&utm_campaign=pypi'
),
'Issues': 'https://github.com/nedbat/coveragepy/issues',
diff --git a/tests/test_api.py b/tests/test_api.py
index 401949b6..3b34afd7 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -316,7 +316,7 @@ class ApiTest(CoverageTest):
def test_cov4_data_file(self):
cov4_data = (
- "!coverage.py: This is a private format, don't read it directly!"
+ "!coverage.py: This is a private format, don't read it directly!" +
'{"lines":{"/private/tmp/foo.py":[1,5,2,3]}}'
)
self.make_file(".coverage", cov4_data)
diff --git a/tests/test_html.py b/tests/test_html.py
index 0e697545..ab7422ea 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -611,9 +611,9 @@ class HtmlGoldTest(CoverageTest):
compare_html(gold_path("html/a"), "out/a")
contains(
"out/a/a_py.html",
- ('<span class="key">if</span> <span class="num">1</span> '
+ ('<span class="key">if</span> <span class="num">1</span> ' +
'<span class="op">&lt;</span> <span class="num">2</span>'),
- (' <span class="nam">a</span> '
+ (' <span class="nam">a</span> ' +
'<span class="op">=</span> <span class="num">3</span>'),
'<span class="pc_cov">67%</span>',
)
@@ -662,24 +662,24 @@ class HtmlGoldTest(CoverageTest):
compare_html(gold_path("html/b_branch"), "out/b_branch")
contains(
"out/b_branch/b_py.html",
- ('<span class="key">if</span> <span class="nam">x</span> '
+ ('<span class="key">if</span> <span class="nam">x</span> ' +
'<span class="op">&lt;</span> <span class="num">2</span>'),
- (' <span class="nam">a</span> <span class="op">=</span> '
+ (' <span class="nam">a</span> <span class="op">=</span> ' +
'<span class="num">3</span>'),
'<span class="pc_cov">70%</span>',
- ('<span class="annotate short">3&#x202F;&#x219B;&#x202F;6</span>'
- '<span class="annotate long">line 3 didn\'t jump to line 6, '
+ ('<span class="annotate short">3&#x202F;&#x219B;&#x202F;6</span>' +
+ '<span class="annotate long">line 3 didn\'t jump to line 6, ' +
'because the condition on line 3 was never false</span>'),
- ('<span class="annotate short">12&#x202F;&#x219B;&#x202F;exit</span>'
- '<span class="annotate long">line 12 didn\'t return from function \'two\', '
+ ('<span class="annotate short">12&#x202F;&#x219B;&#x202F;exit</span>' +
+ '<span class="annotate long">line 12 didn\'t return from function \'two\', ' +
'because the condition on line 12 was never false</span>'),
- ('<span class="annotate short">20&#x202F;&#x219B;&#x202F;21,&nbsp;&nbsp; '
- '20&#x202F;&#x219B;&#x202F;23</span>'
- '<span class="annotate long">2 missed branches: '
- '1) line 20 didn\'t jump to line 21, '
- 'because the condition on line 20 was never true, '
- '2) line 20 didn\'t jump to line 23, '
+ ('<span class="annotate short">20&#x202F;&#x219B;&#x202F;21,&nbsp;&nbsp; ' +
+ '20&#x202F;&#x219B;&#x202F;23</span>' +
+ '<span class="annotate long">2 missed branches: ' +
+ '1) line 20 didn\'t jump to line 21, ' +
+ 'because the condition on line 20 was never true, ' +
+ '2) line 20 didn\'t jump to line 23, ' +
'because the condition on line 20 was never false</span>'),
)
contains(
@@ -906,7 +906,7 @@ assert len(math) == 18
contains(
"out/partial_626/index.html",
'<a href="partial_py.html">partial.py</a>',
- '<span class="pc_cov">87%</span>'
+ '<span class="pc_cov">87%</span>',
)
else:
cov.html_report(partial, directory="out/partial")
@@ -923,7 +923,7 @@ assert len(math) == 18
contains(
"out/partial/index.html",
'<a href="partial_py.html">partial.py</a>',
- '<span class="pc_cov">91%</span>'
+ '<span class="pc_cov">91%</span>',
)
def test_styled(self):
@@ -946,17 +946,17 @@ assert len(math) == 18
contains(
"out/styled/a_py.html",
'<link rel="stylesheet" href="extra.css" type="text/css">',
- ('<span class="key">if</span> <span class="num">1</span> '
+ ('<span class="key">if</span> <span class="num">1</span> ' +
'<span class="op">&lt;</span> <span class="num">2</span>'),
- (' <span class="nam">a</span> <span class="op">=</span> '
+ (' <span class="nam">a</span> <span class="op">=</span> ' +
'<span class="num">3</span>'),
- '<span class="pc_cov">67%</span>'
+ '<span class="pc_cov">67%</span>',
)
contains(
"out/styled/index.html",
'<link rel="stylesheet" href="extra.css" type="text/css">',
'<a href="a_py.html">a.py</a>',
- '<span class="pc_cov">67%</span>'
+ '<span class="pc_cov">67%</span>',
)
def test_tabbed(self):
@@ -985,10 +985,10 @@ assert len(math) == 18
contains(
"out/tabbed_py.html",
- '> <span class="key">if</span> '
- '<span class="nam">x</span><span class="op">:</span>'
- ' '
- '<span class="com"># look nice</span>'
+ '> <span class="key">if</span> ' +
+ '<span class="nam">x</span><span class="op">:</span>' +
+ ' ' +
+ '<span class="com"># look nice</span>',
)
doesnt_contain("out/tabbed_py.html", "\t")