Hyperstyle Installation

Hyperstyle is a convenient and powerful tool that is built on top of various existing linters (Pylint, PMD, etc). All of these linters are integrated and configured by Hyperstyle. However, installation of Hyperstyle could be tricky especially for Windows users. This post will go through the detailed steps of installing Hyperstyle.

Installing Hyperstyle using Docker

Authors: Jian Zhe Chan and Jiajun (Jason) Yu

Functionality

  1. Runs linters for various programming languages including Python, Java, etc and parse their output.
  2. Print linter outputs to the terminal in the JSON format for easy data manipulation.
  3. Calculates the code quality value (EXCELLENT, GOOD, MODERATE, BAD) based on the linters’ output.

 

Installation via Docker

The first method is complicated and tedious. It requires us to create a set of environmental variable and run many commands. Today, we are going to talk about the alternative method, installing via Docker. Basically, we will build a docker image from the Hyperstyle Dockerfile and run the tool inside this image.

 

Step 1: Clone the Hyperstyle GitHub Repository

Go to the Hyperstyle GitHub Repository and clone it to a desired directory.
Example:
s

This will result in a folder ‘hyperstyle’ being created in my Desktop directory

 

Step 2: Build a Docker image using hyperstyle’s Dockerfile

For the following steps, we will be using the VSCode Docker Extension as it is more convenient. First, install the extension on VSCode. Next, open the hyperstyle folder on VSCode, right click on the Dockerfile file and click “Build Image”. This will build an image called ‘hyperstyle’ using the Dockerfile file.

s

 

Step 3: Run the Docker image

After installing the extension, we should be able to see Docker’s icon on the left sidebar. If it doesn’t appear on the left sidebar, right click on it and make sure ‘Docker’ is checked.
s

 

Now we will run the hyperstyle image. Right click on latest and click ‘Run Interactive’
s

 

Done!

At this point we have successfully built the Hyperstyle container and can now use Hyperstyle in the interactive terminal.
s
s

 

Running Hyperstyle

Now let’s try runnign Hyperstyle. Note that we will be in the container environment, so we need to move the files that we want to analyze into the environment. To do so, we can use the docker cp command. But first, we need to get the id of the container. To do so, run the following command in your host’s terminal.

s

Once we got the container’s id, we can start moving files into the container from the host. To do so, we use the docker cp command:

s

This will copy the file a.py which is in my Desktop directory to the root directory of the container’s environment. However, we want the file to be in the specific directory: /review/hyperstyle/src/python/review. To do so, we need to modify our command above slightly:

s

Now we can see that a.py is in the right directory:

s

We can now analyze a.py in the container’s environment. However, we need to be in the specific directory mentioned above first. Since the container’s environment is the same across all computers, we can just copy the following command:

cd review/hyperstyle/src/python/review

To run Hyperstyle, we can use the following command:

python run_tool.py a.py

The output will then be printed on the terminal

s