jcf-cli
jcf-cli copied to clipboard
Jedi Code Formatter CLI
Jedi Code Formatter CLI
I took Jedi Code Formatter (JCF) from Lazarus IDE repository and made it as CLI (command line interface) version by removing all the GUI (graphical user interface) parts from the original GUI version. The CLI version can be used as Pascal code formatter in Visual Studio Code, or as backend engine of an online Pascal code beautifier.
How To Build Using Lazarus
- You must have Lazarus IDE already installed on your system.
- Clone or download this
jcf-cliGitHub repo into your own folder. - Start your Lazarus IDE and open
jcf.lpiproject withinjcf-cli/CommandLine/Lazarusfolder. - Build it via Lazarus' Run → Build menu.
- Wait while Lazarus is building the JCF project.
- Take the executable
JCFfile fromjcf-cli/Output/Lazarusfolder along with thejcf.xmlconfiguration file. - Just to make sure, test it from Terminal using
./JCF -?command. It should show the usage manual.
How To Build Using VS Code
- You must have both Free Pascal compiler and VS Code already installed on your system.
- Clone or download this
jcf-cliGitHub repo into your own folder. - Start your VS Code and open
jcf.lprproject withinjcf-cli/CommandLine/Lazarusfolder. - Build it via VS Code's Tasks → Run Task... → JCF: Build Release menu.
- Wait while FPC is building the JCF project.
- Open
test.pasfile fromjcf-clifolder. - Test
JCFprogram using Tasks → Run Task... → JCF: Test CLI Program menu and you should see the result in thetest.pasfile.
Note: I've included the executable file for Linux, Mac, and Windows in
Output/Lazarusfolder so you don't need to build it yourself. However, it's not guaranteed using the latest modification. 😊
How To Use JCF in VS Code
- Copy the
JCFandjcf.xmlconfig files into your Pascal workspace folder. - Create a new VS Code task or open the
tasks.jsonif you already have one. - Copy the task example below and paste it into your
tasks.jsonfile.
{
"label" : "JCF: Beautify Code",
"type" : "shell",
"command": "./JCF",
"args": [
"${file}",
"-clarify",
"-inplace",
"-config=jcf.xml"
],
"presentation": {
"reveal": "never"
},
"problemMatcher": []
},
- It's a task to beautify Pascal code.
- If you need a task to obfuscate code, simply make another task using the code above, but then change
-clarifyarg into-obfuscate. - Save your
tasks.json. Now you should have new JCF's tasks in your tasks list.
The Problem With JCF
Although JCF is a good Pascal code formatter, it has one single problem that quite annoying. JCF requires the code must be compilable which means it has to be a complete program and syntactically correct. JCF will fail on code snippets or wrong code. To make it works on code snippet, it must be put between a begin..end pair and has a correct program header, like this:
program test;
begin
// put code snippet here
end.
Demo
Here's JCF CLI in action within VS Code (with OmniPascal):

Note: If you're also interested in my other tasks shown in the demo, see my gist about it here.
Hope it's gonna be useful to other Pascal fellows out there. Have fun! 😊