This is a POC for what could be a new CLI for us. The idea is to rely on the native tools and SARIF format instead of relying on Docker.
The codacy-cli-v2
is a command-line tool for Codacy that supports analyzing code using ESLint and uploading the results in SARIF format to Codacy. It provides two main commands: analyze
and upload
.
-
analyze
Command: Runs ESLint analysis on the codebase.--output, -o
: Output file for the results.--tool, -t
: Specifies the tool to run analysis with (e.g., ESLint).--fix, -f
: Automatically fixes issues when possible.--new-pr
: Creates a new GitHub PR with fixed issues.
-
upload
Command With Project Token: Uploads a SARIF file containing analysis results to Codacy.--sarif-path, -s
: Path to the SARIF report.--commit-uuid, -c
: Commit UUID.--project-token, -t
: Project token for Codacy API.
-
upload
Command With API Token: Uploads a SARIF file containing analysis results to Codacy.--sarif-path, -s
: Path to the SARIF report.--commit-uuid, -c
: Commit UUID.--api-token, -a
: User level token for Codacy API.--provider, -p
: Provider name (e.g., gh, gl, bb).--owner, -o
: Repository owner.--repository, -r
: Repository name.
.codacy/codacy.yaml
: Configuration file to specifynode
andeslint
versions for the CLI.runtimes: - [email protected] tools: - [email protected]
codacy-cli-v2 install
: Command to install the specified node and eslint versions before running analysis.
To install codacy-cli-v2
using Homebrew:
brew install codacy/codacy-cli-v2/codacy-cli-v2
For Linux, we rely on the codacy-cli.sh script in the root. To download the CLI, run:
bash <(curl -Ls https://raw.githubusercontent.com/codacy/codacy-cli-v2/main/codacy-cli.sh)
You can either put the downloaded script in a specific file or create an alias that will download the script and look for changes:
alias codacy-cli-v2="bash <(curl -Ls https://raw.githubusercontent.com/codacy/codacy-cli-v2/main/codacy-cli.sh)"
Before running the analysis, install the specified tools:
codacy-cli install
To run ESLint and output the results to the terminal:
codacy-cli analyze --tool eslint
To store the results as SARIF in a file:
codacy-cli analyze -t eslint -o eslint.sarif
To upload a SARIF file to Codacy:
codacy-cli upload -s path/to/your.sarif -c your-commit-uuid -t your-project-token
As an example, you can check https://github.com/troubleshoot-codacy/eslint-test-examples for a repository that has an action relying on this CLI.