Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cairo code formatter #37

Open
mazurroman opened this issue Feb 9, 2024 · 6 comments
Open

Cairo code formatter #37

mazurroman opened this issue Feb 9, 2024 · 6 comments
Assignees
Labels

Comments

@mazurroman
Copy link
Contributor

Let's add a code-format button next to the permalink button. Clicking the button should reformat the Cairo code so that users don't need to manually set indentation.

For the icon, I suggest to use one of these three icons from https://remixicon.com/ : code-line, code-s-line, code-s-slash-line but we're open to hear other icon suggestions

@mazurroman mazurroman moved this from Triage to Todo in cairovm.codes Feb 9, 2024
@remybar
Copy link
Collaborator

remybar commented Feb 11, 2024

Hi @mazurroman 👋

Do you already have an idea of how to format Cairo code from the front-end ?

I've investigated a bit to see how to do that but I didn't find any quick solution:

  • I found that prettier is useable directly in the browser but with some limitations (https://prettier.io/docs/en/browser). There is no parser for Cairo or similar languages like Rust.
  • There is also the possibility to add an API endpoint handled by NextJs on the server side which would execute a command to format like scarb fmt but, for the moment, there is no server side/back-end in your NextJs app so it wouldn't be a good idea to add one just for that,
  • There is a cairo-lang-formatter crate provided by StarkWare (https://docs.rs/crate/cairo-lang-formatter/latest). I'm a pure newbie in Rust but it should be possible to use this formatter in your back-end in Rust and so handle code formatting through a dedicated API endpoint.

Then, if you have an idea about how this code formatting should be implemented, I'm available to do it ;-)

@mazurroman
Copy link
Contributor Author

Hi @remybar thank you for listing all available options, it's very clear and helpful. Let's wait for @barabanovro to suggest which option is the best.

@mazurroman mazurroman moved this from Todo to In Progress in cairovm.codes Feb 11, 2024
@barabanovro
Copy link
Contributor

@mazurroman I would suggest using the cairo-lang-formatter crate that Rémy mentioned and compiling it to WASM so that it can be used on the frontend. It is going to require some work to make the crate compilable to WASM and probably will require forking it.

@mazurroman
Copy link
Contributor Author

@barabanovro I am not a fan of forks and we should avoid them wherever possible. Everything in Starknet is under heavy development. Forking cairo-lang-formatter means we would need to manage our fork which will create new responsibilities and commitments on us.

I like the idea to use WASM here. @barabanovro can you create an issue on the cairo-lang-formatter project to make it WASM compatible and link the issue here as a blocker. Once that issue is done we can resume the work.

@mazurroman mazurroman moved this from In Progress to Todo in cairovm.codes Feb 13, 2024
@barabanovro
Copy link
Contributor

This issue is blocked by cryptonerdcn/wasm-cairo#15

@mazurroman
Copy link
Contributor Author

mazurroman commented Feb 16, 2024

Note: cryptonerdcn (owner of the wasm-cairo repository) confirmed that the cryptonerdcn/wasm-cairo#15 issue is eligible for rewards on OnlyDust

@mazurroman mazurroman moved this from Todo to Backlog in cairovm.codes Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
Development

No branches or pull requests

3 participants