Skip to content
Prettify Cadence

Prettify Cadence

Improve the readability and programing of Cadence.

Created on 27th February 2023

•

Prettify Cadence

Prettify Cadence

Improve the readability and programing of Cadence.

The problem Prettify Cadence solves

Flow uses a language called Cadence to realize the resource orientation of Flow.
This Cadence is used to write smart contracts, transactions to execute them, and scripts to obtain information.
In Flow Blockchain, the script to be executed is displayed to the user at the time of transaction signing to ensure the transparency of the executed transaction.
The smart contract code itself is also archived in readable form on the blockchain so that users can see what the contents of the smart contract to be executed are.
We believe that the above efforts to ensure transparency of transactions to be executed are very important.

However, there is currently no Code Formatter for Cadence and standard formatting is not available.
Smart contracts (contracts) should be managed in a certain format, but this does not ensure transparency due to intentional non-formatting of codes.

Therefore, this project will develop a standard formatter for Cadence.
We used ANTLR to create the abstract syntax tree.
We also use Prettier as a Formatter, which is often used in several development languages, and proceed to develop a plugin for Prettier.
By creating a plugin for Prettier, it will be possible to format and display Cadence code, and we expect to improve the developer experience by using it with plugins such as VSCode.
We are innovating to improve the user and developer experience in the Flow Blockchain.

Challenges I ran into

It was my first time to create a Prettier Plugin and VSCode Extension, and I had never worked with abstract syntax trees before, so that was a challenge for me.
Since there were no comprehensive articles on the subject, I looked for solutions one by one.

Also, when I actually started development, I could not easily get the latest version of Prettier's library to run because it was still provided in CommonJS, while the Parser automatically generated by ANTLR was in ES Module. Eventually I decided to drop one middle version of ANTLR and adopt the version output in CommonJS.

Tracks Applied (1)

Extending the Ecosystem

Provide easy-to-read code for everyone who uses Flow

Discussion

Builders also viewed

See more projects on Devfolio