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

[style] Use prettier instead of clang-format #1447

Closed
dayo09 opened this issue Nov 3, 2022 · 6 comments
Closed

[style] Use prettier instead of clang-format #1447

dayo09 opened this issue Nov 3, 2022 · 6 comments
Labels
Discussion Suggestion Suggestion on feature or code

Comments

@dayo09
Copy link
Contributor

dayo09 commented Nov 3, 2022

What?

How about we use prettier for this project instead of clang-format?

Why?

There are three reasons

(1) To follow the trend.
This npm trend graph shows that prettier overwhelms clang-format in npm echo system.
1103-npmtrends

(2) To use null-coalescing operator(??)
#1445 the operator is not considered correct by clang-format, therefore it breaks it into ? ?, which makes compilation error.

(3) (personally) It looks better.

It seems that prettier understands typescript better and prettify objects or arrow functions much better.

1103-prettier

1103-2

1103-3

@dayo09 dayo09 added Discussion Suggestion Suggestion on feature or code labels Nov 3, 2022
@dayo09
Copy link
Contributor Author

dayo09 commented Nov 3, 2022

If contributors agree, I plan to
(1) turn off clang-format in CI
(2) format using prettier
(3) turn on prettier in CI
To apply the change.

npm install --save-dev prettier
npx prettier -w src

@seanshpark
Copy link
Contributor

(1) I'm not sure about the thrend site really reflects clang-format for JS/TS usage. We're not using npm version of clang-format

(2) You can use

// clang-format off
... `??` ...
// clang-format on

(3) Looks better for me too, but 'better' may be a personal preference.

Anyway I'm OK to move to new format and also OK to stay with clang-format.

@dayo09
Copy link
Contributor Author

dayo09 commented Nov 3, 2022

@seanshpark

(1) I'm not sure about the thrend site really reflects clang-format for JS/TS usage. We're not using npm version of clang-format

Sure. But I think that's because typescript users only use prettier by npm. When they need linter or formatter, it's more natural to get tools from npm, not from apt-get system-wise installation.

(2) You can use

// clang-format off
... `??` ...
// clang-format on

I know this but ??'s more like a commonly used operator, so it's a bit ugly to use this formater escape.

(3) Looks better for me too, but 'better' may be a personal preference.

Anyway I'm OK to move to new format and also OK to stay with clang-format.

Sure, thanks for sharing your opinion 😄

@llFreetimell
Copy link
Contributor

llFreetimell commented Nov 7, 2022

Following comment is just my two cents :)
Basically, I am okay with both clang-format and prettier.


Trends

  • I think npm trend graph is not that good for tracking the trends because npm is not a main concern for clang-format.
  • Instead, I searched the download count at VSCode Extension Marketplace.
  • Given above statistics, prettier may be much trendy than clang-format.

Special grammars for typescript/javascript

Additional references

Conclusion

  • For me, prettier seems better but I am not against with using clang-format.
  • ⭐ However, I think eslint and stylelint should be considered just like clang-format because
    • eslint and stylelint have been used for ONE-vscode in package.json. (csslint is faded out)
    • eslint seems bit more popular than prettier according to npm trend graph

@dayo09
Copy link
Contributor Author

dayo09 commented Nov 18, 2022

@llFreetimell Thanks for your summary :-D

Of course, clang-format on/off can resolve these issues, but I prefer to minimize the usage of clang-format on/off. (Just my preference)

I agree with this. For example, I used ?? to make code simple but putting clang-format on/off makes it more ugly.

⭐ However, I think eslint and stylelint should be considered just like clang-format because
eslint and stylelint have been used for ONE-vscode in package.json. (csslint is faded out)
eslint seems bit more popular than prettier according to npm trend graph

FYI, eslint is more a linter than a formatter. The usage of those tools are different, eslint only checks the symantic errors/warnings, not style. We do not need to consider about eslint here. :-D (npm trend graph just draws a graph with any inputs)

@dayo09
Copy link
Contributor Author

dayo09 commented Jan 3, 2023

Done :-D

@dayo09 dayo09 closed this as completed Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Suggestion Suggestion on feature or code
Projects
None yet
Development

No branches or pull requests

3 participants