import-linter icon indicating copy to clipboard operation
import-linter copied to clipboard

Less verbose output

Open tuukkamustonen opened this issue 2 years ago • 5 comments

Hi, thanks for the great library. Taking it into use in a legacy repository that we've been refactoring mercilessly! The layered mode will come to good use.

What would you think of option for less verbose output? Even with no violations, the output is quite verbose:

=============
Import Linter
=============

---------
Contracts
---------

Analyzed 653 files, 2276 dependencies.
--------------------------------------

Layers KEPT

Contracts: 1 kept, 0 broken.

I'd rather only get single line (or no line at all, if all is okay).

We run import-linter alongside other tools, via a bash script. It will output something like:

Running Black...
All done! ✨ 🍰 ✨
26 files left unchanged.
Running ruff check --fix...
Running isort...
Running autoflake...
Running docformatter...
Running ruff...
Running flake8...
Running pydocstyle...

Most tools seem to default to not print anything at all, if there are no violations (only Black is more verbose as can be seen above). Would be nice to have the same behavior for import-linter, too?

tuukkamustonen avatar Nov 03 '23 08:11 tuukkamustonen

Nice idea. Happy to consider a pull request for this if anyone is interested.

I suggest we follow the same approach as Ruff, that is we add a --quiet flag which cannot be used with --verbose. That would be backwards compatible. Open to other suggestions.

seddonym avatar Nov 06 '23 14:11 seddonym

I'm not sure, is --quiet for something else?

  -q, --quiet    Print diagnostics, but nothing else
❯ touch foobar.py                                                                   
❯ ruff foobar.py             
❯ ruff --quiet foobar.py

Prints nothing (no violations).

❯ echo "blahlbha" > foobar.py                                                                   
❯ ruff foobar.py             
foobar.py:1:1: B018 Found useless expression. Either assign it to a variable or remove it.
foobar.py:1:1: F821 Undefined name `blahlbha`
Found 2 errors.
❯ ruff --quiet foobar.py
foobar.py:1:1: B018 Found useless expression. Either assign it to a variable or remove it.
foobar.py:1:1: F821 Undefined name `blahlbha`

The --quiet seems to remove the "Found 2 errors." but it doesn't affect the violations output.

In any case, just to clarify what this ticket suggests:

  • No violations -> print nothing
  • Violations -> print them

tuukkamustonen avatar Nov 07 '23 19:11 tuukkamustonen

I don't understand, that seems to be what ruff is doing but I might be misunderstanding. In any case, feel free to outline here how you propose things should work in detail (maybe with some examples)?

seddonym avatar Nov 08 '23 11:11 seddonym

I mean that ruff by default acts as suggested in this ticket. The explicit ruff --quiet only removes "Found 2 errors." when there are errors but it doesn't do anything when there aren't. Ruff is kinda quiet by default. I'm not exactly sure what the --quiet in ruff would be useful for...

So import-linter doesn't need similar --quiet but yes it needs --quiet to avoid changing the default behavior, which is opposite to ruff and most tools out there. For that reason, you might consider changing the default behavior but I totally understand if you don't want to.

I hope I sketched it out better this time! If not... we'll just carry on 😄

tuukkamustonen avatar Nov 08 '23 19:11 tuukkamustonen

you might consider changing the default behavior but I totally understand if you don't want to

I don't think I'll do this unless as part of a major release. In the meantime, open to pull requests that add a --quiet flag (or some other suggested API) but don't change the default behaviour.

seddonym avatar Nov 09 '23 09:11 seddonym