nedbat / coveragepy

The code coverage tool for Python
https://coverage.readthedocs.io
Apache License 2.0
2.9k stars 419 forks source link

Configurable tabsize in HTML reports #1342

Open Paebbels opened 2 years ago

Paebbels commented 2 years ago

Is your feature request related to a problem? Please describe. In #6, it was reported that \t get handled in HTML reports.
When checking html.py this mentioned code seams to be gone.

When using tab characters for indentation in Python files, coverage.py converts all tabs to 8 spaces (checked in Chrome browser).
When checking the HTML source code, then 8 spaces can be found:

HTML Code HTML View
image image

Describe the solution you'd like Offer an option in the configuration file, so the conversion of tab characters to spaces can be specified.

[html]
tabstyle = spaces
tabsize = 2

Or this

[html]
tabstyle = tabs
tabsize = 2

This would allow CSS to specify the representation with a default of 2.

Describe alternatives you've considered

  1. The documentation contains no options to configure the tab to space translation process.
  2. I think modifying CSS is not possible, because the HTML code contains already 8 spaces.
    So the representation of tab characters can't be modified.

    #source { padding: 1em 0 1em 3.5rem; font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
    #source p { position: relative; white-space: pre; }
    #source p * { box-sizing: border-box; }
    #source p .t { display: inline-block; width: 100%; box-sizing: border-box; margin-left: -.5em; padding-left: 0.3em; border-left: 0.2em solid #fff; }

Additional context


/cc @umarcor

Paebbels commented 2 years ago

Added research about CSS for tabs.

nedbat commented 2 years ago

I'd like to handle this by reading .editorconfig files, but that will require some refactoring, and using an optional third-party library.

Paebbels commented 2 years ago

The .editorconfig sounds also good.

But shouldn't there be a fallback to the pyproject.toml or similar?

nedbat commented 2 years ago

I would rather not invent a coverage.py-only setting for this. editorconfig files are good, and more people should use them.

Paebbels commented 2 years ago

I also would prefer the .editorconfig.

What do you mean by "coverage.py-only"?
Coverage.py is already reading from pyproject.toml.

[tool.pytest.ini_options]
# Don't set 'python_classes = *' otherwise, pytest doesn't search for classes
# derived from unittest.Testcase
python_files = "*"
python_functions = "test_*"

[tool.coverage.run]
branch = true
omit = [
    "*site-packages*",
    "setup.py"
]

[tool.coverage.report]
skip_covered = true
skip_empty = true
exclude_lines = [
    "raise NotImplementedError"
]

[tool.coverage.html]
directory = "report/coverage/html"

[tool.coverage.xml]
output = "report/coverage/coverage.xml"
nedbat commented 2 years ago

What do you mean by "coverage.py-only"?

I meant that a setting like [tool.coverage.html] tab_size=2 would only be read by coverage.py. It would be duplicating information that's already in the editorconfig file.

Paebbels commented 1 year ago

@nedbat any progress on this topic?

nedbat commented 1 year ago

I have not put any work into this. BTW: one of the reasons people prefer spaces to tabs is because it avoids having to add a tab-size feature to everything that displays code.