Overview

HTTPS SSH

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

  1. You must have Lazarus IDE already installed on your system.
  2. Start your Lazarus IDE and open jcf.lpi project within CommandLine/Lazarus folder.
  3. Build it via Lazarus' RunBuild menu.
  4. Wait while Lazarus is building the JCF project.
  5. Take the executable JCF file from Output/Lazarus folder along with the jcf.xml configuration file.
  6. Just to make sure, test it from Terminal using ./JCF -? command. It should show the usage manual.

Note: Just for your convenience, I suggest you to rename the executable file name into jcf (lowercased).

Alternatively, you may also compile the JCF project using Visual Studio Code using just Free Pascal compiler (no Lazarus IDE is required). However, since FPC doesn't read .lpi project file, you must compile the JCF.lpr main program instead. Make sure you supply all the required compiler parameters correctly, especially the -Fi, -Fu and -FE options.

Note: I've included the executable file for Linux, Mac, and Windows in Output/Lazarus folder so you don't need to build it yourself.

How To Use JCF in VS Code

  1. Copy the jcf and jcf.xml config files into your Pascal workspace folder.
  2. Create a new VS Code task or open the tasks.json if you already have one.
  3. Copy the task example below and paste it into your tasks.json file.
  {
    "label"  : "fpc: Beautify Code",
    "type"   : "shell",
    "command": "./jcf",
    "args": [
      "${file}",
      "-clarify",
      "-inplace",
    ],
    "presentation": {
      "reveal": "never"
    },
    "problemMatcher": []
  }
  1. It's a task to beautify Pascal code.
  2. If you need a task to obfuscate code, simply make another task using the code above, but then change -clarify arg into -obfuscate.
  3. Save your tasks.json. Now you should have new JCF's tasks in your tasks list.

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! 😊