Validating code from command line

January 29, 2018

Ever wanted to validate your code on kritika.io before the commit or push? Now you can do that by using our open source command line tool kritika. For example:

kritika src/MyFile.js
kritika src/AnotherFile.pm

Or you can just be lazy and pass all the modified files:

git diff --name-only | kritika

You can also hide all the old violations and check only if you have introduced the new ones by using --diff-* options:

# compare to the upstream branch
kritika --diff-branch master src/MyFile.js

# compare to a specific snapshot
kritika --diff-snapshot 56 src/MyFile.js

Installing kritika app

Linux:

$ mkdir ~/bin
$ curl https://raw.githubusercontent.com/kritikaio/app-kritika/master/kritika.fatpack -o ~/bin/kritika
$ chmod +x ~/bin/kritika

Configuring kritika app

In order for kritika to know the target repository you should create inside of your working directory a file .kritikarc with the following information:

token=YOUR_TOKEN_FROM_KRITIKA_IO_WEBSITE

Treat this token as a password! We suggest you also do chmod 600 .kritikarc on a multiuser computer. Do NOT commit this file non-encrypted.

And that's it!

Automating validation

Here is a simple example on how to integrate kritika app into your workflow:

#!/bin/sh

remote="$1"
url="$2"

z40=0000000000000000000000000000000000000000

while read local_ref local_sha remote_ref remote_sha
do
    if [ "$local_sha" = $z40 ]
    then
        :
    else
        if [ "$remote_sha" = $z40 ]
        then
            range="$local_sha"
        else
            range="$remote_sha..$local_sha"
        fi

        branch="$(git rev-parse --abbrev-ref HEAD)"

        git diff --name-only $range | kritika --diff-branch "$branch" || exit 1
    fi
done

exit 0

Give it a try! And as usual your feedback is very welcome.