Install Hyperstyle for Checking the Code Quality

This post is about one of the tasks of my Summer Research. For this task, we had to install Hyperstyle (a powerful code quality analyzer) from the paper ‘Hyperstyle: A Tool for Assessing the Code Quality of Solutions to Programming Assignments’. During the installation process, we realized that it is a bit tricky especially for Windows users. Therefore, we decided to make a documentation that includes clear, concise steps and issues that we encountered as well as how we resolved them.

Authors: Jiajun (Jason) Yu and Jian Zhe Chan


Step 1: Go to the github repo and clone the project


Step 2: Install the environment

  • Windows:
    • Copy and Paste the following commands into the Terminal
    • If you can not use ‘pip install’ in bash, try using the Windows PowerShell.
    • Try to install eslint by the third command, if you get an error like permission denied, try following steps:
      • Press “Windows + I” to open settings and click on “Update & Security”.
      • On the left sidebar, click “For developers”, then scroll down to the “PowerShell” subheading.
      • Tick “change execution policy to allow local PowerShell scripts to run without signing. Require signing for remote scripts.”
  • Mac OS:
    • Just Copy and Paste the following commands into the Terminal
# Copy and Paste
pip install -r requirements.txt
pip install -r requirements-test.txt
npm install eslint@7.5.0 -g 
eslint --init

Step 3: Set up environment variables

  • Find the inspector folder file path: …(Specified by yourself) /hyperstyle/hyperstyle/src/python/review/inspectors
  • Set up the environment variable LINTERS_DIRECTORY to be the file path above
  • Note: All of these environment variables are not permanent, so if you close the bash window or open a new bash window, remember to set them again.
  • Windows:
    • For your inspector folder file (LINTERS_DIRECTORY) path, if you clone the github repo in your Windows file system instead of your Unix file system, you need to add “/mnt/c/” in front of your path.
      • Example: export LINTERS_DIRECTORY=/mnt/c/Users/Jason/…
    • Copy and Paste the following commands into the Terminal
  • Mac OS:
    • Just Copy and Paste the following commands into the Terminal
# Command for setting LINTERS_DIRECTORY (Windows):
export LINTERS_DIRECTORY=...(Specified by yourself) \hyperstyle\hyperstyle\src\python\review\inspectors

# Command for setting LINTERS_DIRECTORY (Mac OS):
export LINTERS_DIRECTORY=...(Specified by yourself) /hyperstyle/hyperstyle/src/python/review/inspectors

# Command for checking:
printevn | grep "LINTERS"
# Make sure the environment variable is correctly set
  • Copy and paste the following bash commands
    • You can open ‘Dockerfile’ to find these commands and check if their versions or directories have been changed or not. If you find any difference, use their command.
# Copy and Paste
export CHECKSTYLE_VERSION=8.44
export CHECKSTYLE_DIRECTORY=${LINTERS_DIRECTORY}/checkstyle

export DETEKT_VERSION=1.14.2
export DETEKT_DIRECTORY=${LINTERS_DIRECTORY}/detekt

export PMD_VERSION=6.37.0
export PMD_DIRECTORY=${LINTERS_DIRECTORY}/pmd

export GOLANG_LINT_VERSION=1.49.0
export GOLANG_LINT_DIRECTORY=${LINTERS_DIRECTORY}/golangci-lint

Step 4: Install Curl and Unzip

  • For Mac OS, if these commands do not work, just skip.
# Copy and Paste
sudo apt -y update
sudo apt -y upgrade
sudo apt -y install curl unzip

Step 5: Install external linters

  • Copy and Paste the following commands into the Terminal
  • If you have a space in your directory path, make sure to put double quotation around your environment variables when you are trying to access those values. Example: CHECKSTYLE_DIRECTORY="${LINTERS_DIRECTORY}"/checkstyle
  • If you encounter ‘curl: (35) OpenSSL SSL_connect: Connection reset by peer in connection to github.com:443’ issue, just try to run these commands in GitBash. Remember to set those environment variables in GitBash again. If you are a Windows user, do not include “/mnt/c/” in front of your path.
# CHECKSTYLE
curl -L https://github.com/checkstyle/checkstyle/releases/download/checkstyle-${CHECKSTYLE_VERSION}/checkstyle-${CHECKSTYLE_VERSION}-all.jar > ${CHECKSTYLE_DIRECTORY}/checkstyle-${CHECKSTYLE_VERSION}-all.jar

# DETEKT
curl -sSLO https://github.com/detekt/detekt/releases/download/v${DETEKT_VERSION}/detekt-cli-${DETEKT_VERSION}.zip \
&& unzip detekt-cli-${DETEKT_VERSION}.zip -d ${DETEKT_DIRECTORY} \
&&  curl -H "Accept: application/zip" https://repo.maven.apache.org/maven2/io/gitlab/arturbosch/detekt/detekt-formatting/${DETEKT_VERSION}/detekt-formatting-${DETEKT_VERSION}.jar -o ${DETEKT_DIRECTORY}/detekt-formatting-${DETEKT_VERSION}.jar

# PMD
curl -sSLO https://github.com/pmd/pmd/releases/download/pmd_releases/${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip \
&& unzip pmd-bin-${PMD_VERSION}.zip -d ${PMD_DIRECTORY}

# GOLANG_LINT
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOLANG_LINT_DIRECTORY} v${GOLANG_LINT_VERSION}