Datadog acquired Codiga. This repository is no longer active.
This CLI tool is intended to make interacting with Codiga as smooth as possible.
Ensure you have Node.js installed first. You can do that by running the following in your terminal.
If you don't have it installed, go to download Node.js now.
node -v
Now you can install our CLI tool with either of the following.
# if you want to add it to your package.json
npm i --save-dev @codiga/cli
# if you want to install it globally
npm i -g @codiga/cli
Run the following command to see what's available directly in your terminal or keep reading for more.
codiga --help
Use the command below to set your Codiga API token. This token will be needed to run certain operations. You can create a Codiga API token on our app.
codiga token-add
Use the command below to check if you have a valid Codiga API token set. You can create a new Codiga API token on our app.
codiga token-check
Use the command below to delete a Codiga API token from your system. You can manage your Codiga API tokens on our app.
codiga token-delete
To create a codiga.yml
file with rulesets or to quickly add new rulesets to a codiga.yml
file, we offer a single command.
If you run the command below, we'll open an interactive menu where we can suggest languages and rulesets, and you can choose which ones to use.
codiga ruleset-add
If you know what rulesets you want to add, you can pass their names into the command like you see below.
codiga ruleset-add my-public-ruleset my-private-ruleset
To analyze a single file named file.js
you can could run the following commands. The first command would analyze file.js
for violations with the rules found in foo-ruleset
and the second command would include the rules from bar-ruleset
too.
codiga analyze file.js --ruleset foo-ruleset
codiga analyze file.js --ruleset foo-ruleset --ruleset bar-ruleset
When analyzing a single file, a valid ruleset must be set using the
--ruleset
option.
To analyze a directory and all the files within, you could run any of the following commands to target the directory foo
.
codiga analyze foo
codiga analyze ./foo
codiga analyze /Users/cool-name/foo
When analyzing a directory it isn't necessary to specify a ruleset using --ruleset
, if you have a codiga.yml
file in the targeted directory. If there isn't a codiga.yml
and you haven't specified rulesets in the command, the analyze will exit.
You can find rulesets to use on the Codiga Hub or you can use a command introduced above
codiga ruleset-add
to create acodiga.yml
quickly.
-r/--ruleset
- Specify the rulesets you want your analysis done with
- Required: when analyzing a single file or when there isn't a
codiga.yml
in the root targeted directory - Default:
codiga.yml
- Notes: if set, will override a
codiga.yml
- Required: when analyzing a single file or when there isn't a
- Specify the rulesets you want your analysis done with
-f/--format
- Specify the format you want your analysis reported in
- Options:
text
,json
,csv
- Default:
text
- Options:
- Specify the format you want your analysis reported in
-o/--output
- Specify where you want your analysis reported to
- Default:
stdout
- Examples:
results.csv
,violations.json
,analysis.text
- Notes: If there are no violations, no file will be created.
- Default:
- Specify where you want your analysis reported to
--follow-symlinks
- Specify if you want to follow and analyze symbolic links
- Default: false
- Specify if you want to follow and analyze symbolic links
Use the command below to detect any violations between your two commits.
As the command name suggests, this works best in a pre-push
git hook. Everytime a git push
command is ran, that developer will know that their code doesn't have any violations and if they do, they will need to push new commits to rectify those violations before pushing again.
codiga git-push-hook --remote-sha 1234567 --local-sha 7654321
To utilize the git pre-push
hook automatically, you'll need to follow "Getting Started" above and then copy the following into a .git/hooks/pre-push
file and then run chmod a+x .git/hooks/pre-push
to make it executable.
#!/bin/sh
while read local_ref local_sha remote_ref remote_sha
do
codiga git-push-hook --remote-sha $remote_sha --local-sha $local_sha
done
exit 0
If you're already using a tool like husky to handle git hooks the following would go into a .husky/pre-push
file and then run chmod +x .husky/pre-push
to make it executable.
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
while read local_ref local_sha remote_ref remote_sha
do
codiga git-push-hook --remote-sha $remote_sha --local-sha $local_sha
done
exit 0
MIT