Setting Up CheckStyle - nus-cs2030/2324-s2 GitHub Wiki
Setting up Vim and Checkstyle
You will first need to open a File Explorer Window in msys (if you are using Windows), or a Finder Window in Terminal (if you are using MacOS). Instructions have been provided here.
This should open up the relevant folder.
Vim Settings
Get the relevant .vimrc file here: https://github.com/nus-cs2030/2324-s2/blob/main/.vimrc
Paste the .vimrc file into the folder that you opened above.
NOTE: After downloading the file, make sure there is NO .txt extension. (Enable 'file name extensions' on your file explorer to make sure).
RENAME IT to .vimrc without the .txt.
Checkstyle
Download the checkstyle-10.3.3-all.jar and the cs2030_checks.xml file to the same folder as before.
Making sure you did it right:
Your folder should look something like the following (give or take a few files).
Shortcut to run Checkstyle
To run checkstyle normally, you do:
java -jar checkstyle-10.3.3-all.jar -c cs2030_checks.xml YourFilenameHere.java
But we can make it simpler to run.
DISCLAIMER: Shortcuts are just a convenience. You may risk corrupting the startup scripts. Back up often!
1. Setting up your profile
Type the following:
echo $SHELL
One of the following outputs should correspond to the profile you need to create:
- for
/bin/sh
your profile is~/.profile
- for
/bin/bash
your profile is~/.bash_profile
- for
/bin/zsh
your profile is~/.zprofile
The command below creates a profile if it does not exist; if
it exists then it leaves it untouched. For example if your profile is
~/.profile
, then execute the following:
touch ~/.profile
2. To make checkstyle alias on specific java file only
Add alias to the bottom of the profile (assuming its ~/.profile
) and save it
echo "alias checkstyle=\"java -jar ~/checkstyle-10.3.3-all.jar -c ~/cs2030_checks.xml\"" >> ~/.profile
Then run the new profile (assuming ~/.profile
) using
source ~/.profile
3. To run the file in msys:
checkstyle (your filename or *.java)
e.g.
checkstyle HelloWorld.java
If you get Command 'checkstyle' not found, ...
, try restarting your session.
Testing Vim and Checkstyle
You will now use the vim
editor to write your first Java program in the msys
or Terminal
window.
If you are wondering how to use vim
, execute the vimtutor
command.
It will open up a text file in vim
with instructions on how to use
vim
.
Follow the instuctions and you will soon be a proficient user of vim
.
Once you are ready, create your first java program HelloWorld.java
in vim and write the following:
class HelloWorld {
}
Save the file and exit vim
. Then run checkstyle
on
HelloWorld.java
by typing
checkstyle HelloWorld.java
You should get the following output:
Starting audit...
Audit done.