Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank lines not factored into range #307

Open
christianbundy opened this issue Dec 24, 2022 · 2 comments
Open

Blank lines not factored into range #307

christianbundy opened this issue Dec 24, 2022 · 2 comments

Comments

@christianbundy
Copy link

Hello! I've noticed that when I commit a new file with no tests, I'll get unexpected outline because of blank lines and comments.

Expected:

example.py (0.0%): Missing lines 2-59

Actual:

example.py (0.0%): Missing lines 2-4,6-7,10-11,13-14,16-17,20-22,24,27,34-37,40,42-45,49,53-56,58-59

In this example, I have:

  • line 1: comment
  • line 5: blank line
  • line 8-9: blank lines
  • line 12: comment
  • etc

Is there a way to fix this? I'm generating a warning via GitHub Actions and this is generating ~13 warnings when I'd like one warning for the full file. These warnings clutter the UI, but the real problem is that GitHub Actions only allows 10 warnings on job, so I'm inclined to try to use ranges as much as possible.

Thanks!

@mattbachmann-toast
Copy link

So long answer short it really depends on the underlying coverage report.

Diff cover is reporting all those missing lines like that because that's how the underlying coverage report is reporting them.

I'm away from a computer right now (mobile) so I could be misremembering something but I can double check this later.

@Bachmann1234
Copy link
Owner

So I wrote up a test script to demonstrate this.

<?xml version="1.0" ?>
<coverage version="7.0.1" timestamp="1672185636917" lines-valid="8" lines-covered="7" line-rate="0.875" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
	<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
	<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
	<sources>
		<source>/Users/redacted/issue</source>
	</sources>
	<packages>
		<package name="go" line-rate="0.8" branch-rate="0" complexity="0">
			<classes>
				<class name="go.py" filename="go/go.py" complexity="0" line-rate="0.8" branch-rate="0">
					<methods/>
					<lines>
						<line number="5" hits="1"/>
						<line number="10" hits="1"/>
						<line number="13" hits="1"/>
						<line number="15" hits="1"/>
						<line number="16" hits="0"/>
					</lines>
				</class>
			</classes>
		</package>
	</packages>
</coverage>

As you can see the report basically skips these blank lines.

Diff cover is kinda just reporting what this gives.

I suppose it would be possible to update this logic to join blocks that are separated by 'blank' lines and not by 'covered' ones.

That being said it very much strikes me as a preference. I could see an argument for someone prefer seeing how many "blocks" of uncovered code exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants