ruff icon indicating copy to clipboard operation
ruff copied to clipboard

feat: ruff --statistics

Open seanabreau opened this issue 2 years ago • 4 comments

adds --statistics flag from issue #1814 open to all feedback :)

seanabreau avatar Jan 22 '23 20:01 seanabreau

A few thoughts that come to mind...

Would it be possible to provide the following additional flags?

  • --statistics-sort-field accepting count (default) and code
  • --statistics-sort-order with asc and desc (default)

Would it make sense to split the code into a separate column to the description? In future additional columns could be possibly be added to the stats via --statistics-fields... For example, filename could be added to have a breakdown by file.

What about also accepting --statistics-format where there could be text (default), json, jsonl, etc.?

I guess these could be farmed out to separate issues to break this down into smaller chunks, but the sorting should be relatively straightforward to add here?

ngnpope avatar Jan 23 '23 10:01 ngnpope

I'd love to try and output in a format that's amenable to doing those kinds of transforms in a downstream tool, e.g. with Unix-style piping, rather than implement all the flags and options in Ruff itself. For example: --format=json is intended to work here, so users could always output as JSON then sort and filter themselves. But maybe there's a way to output standard tabular data that can be manipulated in that way too? I'd have to look at what some other, comparable tools for inspiration.

charliermarsh avatar Jan 23 '23 17:01 charliermarsh

I tried using it and currently get:

error[E0425]: cannot find value `cli` in this scope
   --> ruff_cli/src/args.rs:436:15
    |
436 |     } else if cli.statistics {
    |               ^^^ not found in this scope


should be args.statistics

spaceone avatar Jan 26 '23 15:01 spaceone

FYI: as I am using this heavily I used your WIP version and rebased onto latest main: https://github.com/spaceone/ruff/pull/new/statistics (in case you want to continue working on it without resolving the merge conflicts on your own).

spaceone avatar Jan 27 '23 13:01 spaceone

Closing in favor of #2284 -- which just merged!

charliermarsh avatar Jan 29 '23 18:01 charliermarsh