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

Use DPrint to ensure consistent code formatting #7474

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

linonetwo
Copy link
Contributor

@linonetwo linonetwo commented May 22, 2023

As an alternative to #7394

I suggest dprint because it is very fast (rust) and secure (see dprint.json, plugins are wasm in sandbox).

And I also suggest using pnpm because it can reuse packages across projects and is fast. (optional if you prefer npm, but I don't know why can't get npm install things on my Mac today, its been a while since last using it.)

No need to run dprint/prettier alone, they can be integrated into eslint and use eslint . --fix instead. Or we can do this file-by-file, when modifying a file in the future.

There are lots of style to be fixed, due to (function(){ })() on many js file that should introduce indentation but there was no indentation.
(I'm not sure this wrapper is necessary, I never write them in my plugins and still works fine.)

I also config dprint errors as warning in eslint, so in VSCode it looks softer:

图片

Use alt+shift+G to fix eslint error on a file, as well as dprint/prettier errors:

图片

@vercel
Copy link

vercel bot commented May 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
tiddlywiki5 ✅ Ready (Inspect) Visit Preview May 22, 2023 1:48pm

@@ -0,0 +1,23 @@
{
"lineWidth": 120,
"typescript": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://dprint.dev/plugins/typescript/config/ , this also works for JS, not only TS

@Jermolene
Copy link
Member

Thanks @linonetwo I won't be able to try this out for a few days, but it looks good.

  • I'm not familiar with pnpm, perhaps it's worth opening another issue to make the case and gather the evidence. We generally use npm because it is included in the default install from nodejs.org, and doesn't need to be separately installed
  • The extra (function(){ })() wrapper around every module is redundant, and we should remove them all

@pmario
Copy link
Member

pmario commented May 22, 2023

There are lots of style to be fixed, due to (function(){ })() on many js file that should introduce indentation but there was no indentation.
(I'm not sure this wrapper is necessary, I never write them in my plugins and still works fine.)

at 19c052d#commitcomment-107771231 Jeremy wrote

pmario wrote

IMO If we want to use that, the redundant wrapper function has to go.

I'd like to remove the redundant wrappers in any case.

Jeremy wrote

So we would be able to get rid of all the (function(){ })() wrappers ...

The problem is even removing \r from the TW file reduced the file size quite a bit. So adding more characters for indentation as there is at the moment will have a negative impact on the file size.

So @linonetwo .. Did you compare the "vanilla" TW file size before and after you did use dprint?

@linonetwo
Copy link
Contributor Author

@pmario After removing (function(){ })(), there won't be much changes. It won't add a lot indentations

图片

@linonetwo
Copy link
Contributor Author

linonetwo commented May 22, 2023

I didn't see a rule to save this space, this might add a lot of spaces

图片

dprint/dprint-plugin-typescript#526

@pmario
Copy link
Member

pmario commented May 22, 2023

I didn't see a rule to save this space, this might add a lot of spaces

This one is a tricky one. From my point of view, in general the extra space would improve human readability. But it has a negative impact on file size.


You did open a "feature request" at the dprint repo. right? ... We'll see what they say.

@linonetwo
Copy link
Contributor Author

dprint wasm might work in browser too, so we might be able to write a Rust formatted compile to wasm and run with drpint as a tw codemirror plugin

@linonetwo
Copy link
Contributor Author

linonetwo commented Jun 14, 2023

@pmario size compare linonetwo#3

Before: 1,803,178 B (1.8MB)

After--: 1,803,407 B (1.8MB)

@linonetwo
Copy link
Contributor Author

linonetwo commented Jun 14, 2023

If this is merged, other developers need to run npx eslint . --fix before pr, so there will no be conflict.

@pmario
Copy link
Member

pmario commented Jun 14, 2023

@linonetwo Your sizes are interesting. If I download empty.html from tiddlywiki.com I do get a file with 2328kByte in size.

grafik

If I create it with latest master v5.3.0-pre it's 2400kByte

@linonetwo
Copy link
Contributor Author

linonetwo commented Jun 14, 2023

Sorry, I just right-click the core/ folder or tiddlywiki to show its info for size. So it does not include the verbose HTML syntax in HTML.

Also, @Jermolene you wish to decide between #7394 and this after 5.3.0?

@pmario
Copy link
Member

pmario commented Jun 14, 2023

OK. But still. What do I need to do to activate dprint for all files so I can create a new file afterwards.

@linonetwo
Copy link
Contributor Author

See linonetwo#3 (comment) , but also a pr to add it to npm script so no one need to ask about this #7539

@pmario
Copy link
Member

pmario commented Jun 14, 2023

IMO in #7474 (comment) there is a typo:

IMO it should be npx eslint . --fix ... because exlint wants to install something and then throws an error

@pmario
Copy link
Member

pmario commented Jun 14, 2023

Very interesting.

  • The log reports 13 errors and
  • modified 68 files.

That's almost nothing. I did expect much more problems. I'll have to have a closer look, what actually has been changed.

@linonetwo
Copy link
Contributor Author

IMO in #7474 (comment) there is a typo:

IMO it should be npx eslint . --fix ... because exlint wants to install something and then throws an error

yes, updated.

About error, I think we can merge the auto fixed version, then take spare time to fix other errors one PR by one PR.

@pmario
Copy link
Member

pmario commented Jun 14, 2023

Did you find a configuration to ignore the "additional indentation" cause by the wrapper functions?

@linonetwo
Copy link
Contributor Author

linonetwo commented Jun 14, 2023

Did you find a configuration to ignore the "additional indentation" cause by the wrapper functions?

Not yet, maybe we can just accept the space? Or I have to add that rule using rust.

But spaces is not so much, as far as we tested.

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

Successfully merging this pull request may close these issues.

3 participants