How to run local analysis - Set up the Codacy Analysis CLI

Set up the Codacy Analysis CLI

Follow the installation guide to get the codacy-analysis-cli executable running on your build server.

Running an analysis with the CLI

At the moment, the CLI still requires to retrieve the configuration from Codacy to perform an analysis. In order to access the repository, you will have to obtain a Project Token as explained in the CLI documentation.

Check our Codacy Analysis CLI documentation page here for important information, notes, advanced configurations, and more on ignored issues.

Please let us know if you need further help! :desktop_computer: :computer:

1 Like

I was going to ask about this.
I have problems running the cli locally.

I think the cli tool is great because we can check our code without waiting for the CI pipeline.
I am honestly trying to learn to use the tool, and help you improve on some points (I find) relevant.
I’m not criticising or ranting about it, even if I may come across that way :slight_smile:

So, some problems I have…

Where can I find available options for --tool <TOOL-SHORT-NAME>?

Also, when I pass wrong parameters to the CLI it terminates with no error, no result.
Other times it just never returns control to the terminal but does not print anything either, so I don’t know what is it doing at all.

For example:

codacy-analysis-cli analyze \
  --tool eslint \
  --directory $(pwd)
Starting analysis ...
Analysis complete

It took minutes to print Starting analysis ...
Then, when it’s done, now what? Where’s some sort of report?
Why do I need to back into reading online documentation to find this?
Do I need to fix anything or can I commit and push? :slight_smile:

Another UX issue:

➜ codacy-analysis-cli validate-configuration
Could not find Codacy configuration file. Make sure you have a file named like one of .codacy.yaml, .codacy.yml.

Why does it take 30 seconds to execute the above?
And more importantly, If my config is wrong, Analysis complete should have been an error instead, right ?

Hello @vetras, and welcome to the Codacy Community! :wave: Thank you for your valuable feedback.

I may be able to help with some of your questions:

Where can I find available options for --tool <TOOL-SHORT-NAME> ?

Currently, the documentation doesn’t mention where you can find the short names of the tools to use with the flag --tool. We have plans to improve that, but in the meanwhile:

  • You can use the list of tool short names in this documentation page. However, it’s not guaranteed that this list up-to-date (it may not contain the most recent tools);
  • Alternatively, and perhaps a better option, is to use the listTools API endpoint to obtain the up-to-date list of short names for all supported tools. You can open the URL https://app.codacy.com/api/v3/tools on your browser, search for the tool you’re interested in, and take note of the value of shortName.

Also, when I pass wrong parameters to the CLI it terminates with no error, no result.
Other times it just never returns control to the terminal but does not print anything either, so I don’t know what is it doing at all.

In this case, I suggest using the flag --verbose to have more information about what’s going on.

And more importantly, If my config is wrong, Analysis complete should have been an error instead, right ?

I’m not sure if this answers your question, but I tested this and the Codacy Analysis CLI needs the flag --directory when validating a Codacy configuration file. For example:

$ codacy-analysis-cli validate-configuration --directory $(pwd)
Successfully loaded the Codacy configuration file in /home/paulo/git/docs/.codacy.yml
CodacyConfigurationFile(None, Some(Set()), None)

I know I haven’t answered all your questions, but do let us know if my suggestions above were useful. We will also use your feedback when working on improving the Codacy Analysis CLI documentation. :+1: :bookmark_tabs:

1 Like

Thanks for your reply! Appreciated.

True, I forgot to put that parameter into the post. My mistake, but the problem here is that I don’t think the command should take so long to tell me there are config errors.

Indeed the verbose flags helps to understand what is going on. But how should I look at my test result?
I don’t seem to find a PDF or HTML report and looking at the terminal logs does not work for so many things being reported.