Skip to content

Commit

Permalink
Add option to show filename for each violation msg (#119)
Browse files Browse the repository at this point in the history
Partially contributed by @gigi-minds-ai
  • Loading branch information
jsh9 authored Feb 7, 2024
1 parent b8b4396 commit fa41757
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## [0.3.10] - 2024-02-07

- Added

- A new config option `--show-filenames-in-every-violation-message` (or
`-sfn`), which makes it more convenient to jump to the corresponding line
in IDEs by clicking on the violation message in the terminal

- Full diff
- https://github.com/jsh9/pydoclint/compare/0.3.9...0.3.10

## [0.3.9] - 2024-01-16

- Fixed
Expand Down
39 changes: 37 additions & 2 deletions docs/config_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ page:
- [11. `--check-yield-types` (shortform: `-cyt`, default: `True`)](#11---check-yield-types-shortform--cyt-default-true)
- [12. `--baseline`](#12---baseline)
- [13. `--generate-baseline` (default: `False`)](#13---generate-baseline-default-false)
- [14. `--config` (default: `pyproject.toml`)](#14---config-default-pyprojecttoml)
- [14. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`)](#14---show-filenames-in-every-violation-message-shortform--sfn-default-false)
- [15. `--config` (default: `pyproject.toml`)](#15---config-default-pyprojecttoml)

<!--TOC-->

Expand Down Expand Up @@ -189,7 +190,41 @@ in that file.
Required to use with `--baseline` option. If `True`, generate the baseline file
that contains all current violations.

## 14. `--config` (default: `pyproject.toml`)
## 14. `--show-filenames-in-every-violation-message` (shortform: `-sfn`, default: `False`)

If False, in the terminal the violation messages are grouped by file names:

```
file_01.py
10: DOC101: ...
25: DOC105: ...
37: DOC203: ...
file_02.py
24: DOC102: ...
51: DOC107: ...
126: DOC203: ...
246: DOC105: ...
```

If True, the file names are printed in the front of every violation message:

```
file_01.py:10: DOC101: ...
file_01.py:25: DOC105: ...
file_01.py:37: DOC203: ...
file_02.py:24: DOC102: ...
file_02.py:51: DOC107: ...
file_02.py:126: DOC203: ...
file_02.py:246: DOC105: ...
```

This can be convenient if you would like to click on each violation message and
go to the corresponding line in your IDE. (Note: not all terminal app offers
this functionality.)

## 15. `--config` (default: `pyproject.toml`)

The full path of the .toml config file that contains the config options. Note
that the command line options take precedence over the .toml file. Look at this
Expand Down
32 changes: 26 additions & 6 deletions pydoclint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ def validateStyleValue(
' file should be specified by the --baseline option.)'
),
)
@click.option(
'-sfn',
'--show-filenames-in-every-violation-message',
type=bool,
show_default=True,
default=False,
help='If True, show file names in the front of every violation message.',
)
@click.argument(
'paths',
nargs=-1,
Expand Down Expand Up @@ -283,6 +291,7 @@ def main( # noqa: C901
require_yield_section_when_yielding_nothing: bool,
generate_baseline: bool,
baseline: str,
show_filenames_in_every_violation_message: bool,
config: Optional[str], # don't remove it b/c it's required by `click`
) -> None:
"""Command-line entry point of pydoclint"""
Expand Down Expand Up @@ -433,14 +442,25 @@ def main( # noqa: C901
if counter > 1:
print('')

click.echo(
click.style(filename, fg='yellow', bold=True),
err=echoAsError,
)
if not show_filenames_in_every_violation_message:
click.echo(
click.style(filename, fg='yellow', bold=True),
err=echoAsError,
)

for violation in violationsInThisFile:
violationCounter += 1
fourSpaces = ' '
click.echo(fourSpaces, nl=False, err=echoAsError)
if not show_filenames_in_every_violation_message:
fourSpaces = ' '
click.echo(fourSpaces, nl=False, err=echoAsError)
else:
click.echo(
click.style(filename, fg='yellow', bold=True),
nl=False,
err=echoAsError,
)
click.echo(':', nl=False, err=echoAsError)

click.echo(
f'{violation.line}: ', nl=False, err=echoAsError
)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pydoclint
version = 0.3.9
version = 0.3.10
description = A Python docstring linter that checks arguments, returns, yields, and raises sections
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit fa41757

Please sign in to comment.