getcodelimit / codelimit

Your Refactoring Alarm 🔔
https://codelimit.vercel.app
GNU General Public License v3.0
36 stars 3 forks source link

Invoking without tui #15

Closed marvin8 closed 1 year ago

marvin8 commented 1 year ago

Is there a way to run codelimit from the command line without using a TUI?

Basically I'd like a way to run codelimit from NOX and have it report back similar to how codelimit reports back using the pre-commit hook.

robvanderleek commented 1 year ago

/cib

create-issue-branch[bot] commented 1 year ago

Branch issue-15-Invoking_without_tui created!

robvanderleek commented 1 year ago

Hi @marvin8

The command-line interface is still very fluid so let's see if I can support your use case 🙂

I don't know NOX, perhaps you can let me know how it interfaces with testing tools? Does NOX calls the testing tools with a list of files or does it expect the tools to scan the codebase? Also, what kind of output works best? Regular console output or something formatted? And does it expects error codes for failure/success?

I've already adapted the CLI a bit in this branch, it offers a scan and check command (see README in branch). The check command is used by pre-commit, however, it does expect to be called with a list of files.

marvin8 commented 1 year ago

As I understand it, NOX just issues a CLI command.

The check command sounds like it would work for my use case, if it could accept a directory to scan all files within.

If i could call codelimit something like codelimit check src/ and it won't invoke the tui with that command, that would be splendid.

In terms of output. For this use case i think regular console output would work well. It would be nice if any formatting of the output of that command would consider "machine readability" so output could be processed with the usual CLI commands grep, awk, cut, etc.

Return / exit code of 0 for success / no refactoring needed and a non '0' return code for refactoring needed would be good as well. I am guessing that is how pre-commit works as well.

robvanderleek commented 1 year ago

HI @marvin8

In this branch I've split the CLI in two commands: check and scan. The scan command opens the TUI, the check command generates only console output.

I've looked at ruff and black for console formatting inspiration, below is an example of the current output.

Let me know if this would work for your use case so I can merge it to main 🙂

KR, Rob

❯ poetry run codelimit check /Users/rob/projects/opensource/fastapi
/Users/rob/projects/opensource/fastapi/fastapi/params.py:462:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/params.py:23:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/params.py:574:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/params.py:132:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/params.py:298:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/params.py:657:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/params.py:216:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/params.py:382:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:51:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:291:5: [ 58] add_api_route
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:472:5: [ 54] get
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:527:5: [ 54] put
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:582:5: [ 54] post
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:637:5: [ 54] delete
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:692:5: [ 54] options
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:747:5: [ 54] head
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:802:5: [ 54] patch
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:857:5: [ 54] trace
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:233:5: [ 43] setup
/Users/rob/projects/opensource/fastapi/fastapi/applications.py:350:5: [ 31] api_route
/Users/rob/projects/opensource/fastapi/fastapi/encoders.py:101:1: [60+] jsonable_encoder
/Users/rob/projects/opensource/fastapi/fastapi/utils.py:112:1: [ 49] create_cloned_field
/Users/rob/projects/opensource/fastapi/fastapi/utils.py:63:1: [ 45] create_response_field
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:780:5: [60+] include_router
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:366:5: [60+] __init__
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:195:1: [60+] get_request_handler
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:591:5: [60+] add_api_route
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:901:5: [ 55] get
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:957:5: [ 55] put
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:1013:5: [ 55] post
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:1069:5: [ 55] delete
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:1125:5: [ 55] options
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:1181:5: [ 55] head
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:1237:5: [ 55] patch
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:1293:5: [ 55] trace
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:522:5: [ 47] __init__
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:74:1: [ 41] _prepare_response_content
/Users/rob/projects/opensource/fastapi/fastapi/routing.py:673:5: [ 32] api_route
/Users/rob/projects/opensource/fastapi/fastapi/param_functions.py:316:1: [60+] Body
/Users/rob/projects/opensource/fastapi/fastapi/param_functions.py:162:1: [60+] Header
/Users/rob/projects/opensource/fastapi/fastapi/param_functions.py:396:1: [60+] Form
/Users/rob/projects/opensource/fastapi/fastapi/param_functions.py:474:1: [60+] File
/Users/rob/projects/opensource/fastapi/fastapi/param_functions.py:10:1: [60+] Path
/Users/rob/projects/opensource/fastapi/fastapi/param_functions.py:86:1: [60+] Query
/Users/rob/projects/opensource/fastapi/fastapi/param_functions.py:240:1: [60+] Cookie
/Users/rob/projects/opensource/fastapi/fastapi/dependencies/models.py:16:5: [ 41] __init__
/Users/rob/projects/opensource/fastapi/fastapi/dependencies/utils.py:317:1: [60+] analyze_param
/Users/rob/projects/opensource/fastapi/fastapi/dependencies/utils.py:241:1: [ 50] get_dependant
/Users/rob/projects/opensource/fastapi/fastapi/dependencies/utils.py:753:1: [ 46] get_body_field
/Users/rob/projects/opensource/fastapi/fastapi/dependencies/utils.py:636:1: [ 33] request_params_to_args
/Users/rob/projects/opensource/fastapi/fastapi/dependencies/utils.py:162:1: [ 32] get_flat_dependant
/Users/rob/projects/opensource/fastapi/fastapi/openapi/utils.py:205:1: [60+] get_openapi_path
/Users/rob/projects/opensource/fastapi/fastapi/openapi/utils.py:422:1: [60+] get_openapi
/Users/rob/projects/opensource/fastapi/fastapi/openapi/utils.py:90:1: [ 35] get_openapi_operation_parameters
11495 files checked, 54 functions need refactoring.
marvin8 commented 1 year ago

Thanks @robvanderleek

That looks like it should do the trick quite nicely.

marvin8 commented 1 year ago

Just gave the new version a spin and works great with NOX now. Thank you for making the changes.

I'll add codelimit to CI in my projects now.

robvanderleek commented 1 year ago

Thanks for opening the issue 🙂

Codelimit is still a young project, do not hesitate to open issues in the future, much appreciated!