Skip to content

(cli): remove prettier #290

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

Open
ryoppippi opened this issue Mar 31, 2025 · 6 comments
Open

(cli): remove prettier #290

ryoppippi opened this issue Mar 31, 2025 · 6 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@ryoppippi
Copy link
Member

ryoppippi commented Mar 31, 2025

low priority

problem

prettier is really large. we want to remove it

solution

Instead of pass the whole code to prettier, we can indent the code

  1. use detect-indent to identify the code indent width
  2. calculate the width of indent of /// INSERT CONTROLLER HERE code and /// INSERT IMPORT HERE
  3. change the indent of the insert code based of step2 with indent-string
  4. remove prettier and related function

Also

  • we need to write a test
  • implement the indent logic into utils.ts
  • implement code inserting logic into connectors.ts(we can include code formatting logic)
  • call the insert function from start.ts
@ryoppippi ryoppippi self-assigned this Mar 31, 2025
@ryoppippi ryoppippi added the good first issue Good for newcomers label Apr 2, 2025
@luke0408
Copy link
Contributor

@ryoppippi

This looks like a fun task! If no one is currently working on it, would it be okay if I take it on? I'd also like to compare the actual time it takes to format code using Prettier versus the approach you've proposed—just adjusting the indent level.

@ryoppippi
Copy link
Member Author

@luke0408 Thank you so much! We don't have so much time right now, so if you help us it must be really great!
I was going to leave this for at least another two weeks. I urge you to give it a go.
Using prettier is easy, but downloading 8MB just to fix the indentation is a bit of an exaggeration, so I made this issue!
I'll be reviewing it, so please give it a go!
Don't forget to write a formatter test too!

@luke0408
Copy link
Contributor

Sounds good!
I'm not the most skilled, but I'll try to get it done as quickly as possible!

@ryoppippi
Copy link
Member Author

It will be fun! I'll support you!

@luke0408
Copy link
Contributor

@ryoppippi

May I ask you a question?

Here’s how I understand the two libraries:

  • detectIndent() identifies the indentation style (spaces/tabs and width) used across the entire code.
  • indentString() applies uniform indentation to the entire input string.

Given this, I believe we need to recursively walk through indentation-relevant elements like braces ({}), if statements, etc., and apply the detected indentation style using indentString().

So, under the assumption that we stick with these tools, I'm considering building a lightweight "depth tree" of the code — ignoring the content, but keeping track of structural depth for formatting purposes.

Alternatively, I'm also exploring the idea of generating an actual AST using something like @typescript-eslint/typescript-estree, and then using astring to regenerate the code. But I’m wondering if that might be overkill or outside the intended scope of this task.

What do you think?

@ryoppippi
Copy link
Member Author

ryoppippi commented Apr 16, 2025

@luke0408
Thank you for your detailed explanation!
And thank that you think about it a lot!

I think our goal of this task is:

  • use libraries with small bundle size
  • if some parts are not accurate we don't mind

so I think

So, under the assumption that we stick with these tools, I'm considering building a lightweight "depth tree" of the code — ignoring the content, but keeping track of structural depth for formatting purposes.

This approach might be a good choice.
Also, in my opinion, using @typescript-eslint/typescript-estree is not a good idea because we need eslint/typescript/@typescript-eslint/typescript-estree, which means the bundle size would be bigger than just using prettier!

In our implementation, we replace the two lines in a template file:

export function insertCodeIntoAgenticaStarter({
content,
importCode,
connectorCode,
}: InsertCodeIntoAgenticaStarterProps): string {
return content
.replace("/// INSERT IMPORT HERE", importCode)
.replace("/// INSERT CONTROLLER HERE", connectorCode);
}

So what we want is:

  • calculate indent depth
  • apply the indentation to the code for replacement (see as an example)
  • replace /// INSERT IMPORT HERE with ↑ code

So overall, you don't need to do searching stuff. It will be simpler than you consider

If I might miss, probably you think more than me. In that case please create a draft PR first then we can start discussing based on your prototype!

Again, thank you for your effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants