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

[Proposal] Move to Standard coding style + away from function expressions #119

Open
davestewart opened this issue Jul 18, 2024 · 3 comments

Comments

@davestewart
Copy link
Contributor

davestewart commented Jul 18, 2024

Hey @bernaferrari,

I wanted to raise this as I've been working a lot with the code, but how would you feel about moving to the Standard coding style?

The major changes / benefits are...

Single rather than double quotes

  • less typing – one key press not two (usingSHIFT key)
  • easier to write HTML – no need to escape double-quoted HTML attributes

No semicolons:

  • less to type
  • less visual clutter
  • greater consistency

Also, prefer functions to function expressions:

  • simpler to identify functions vs values – function is start of line vs () => at end of line
  • consistent with other keywords – let, const, type, interface, function, ...
  • simpler to identify async functions – async is start of line vs middle of line
  • no trailing semi-colon required
  • shorter / less tokens / less typing
  • built-in benefits like hoisting
  • use function expressions only where necessary – i.e. React functional components
function test () {
  ...
}

const test = () => {
  ...
};

async function test () {
  ...
}

const test = async () => {
  ...
};

export const PreviewPanel: React.FC<PreviewPanelProps> = (props) => {
  ...
};

If you're warm to the idea, I could set up the linter to --fix the existing code so it wouldn't take any time to get going.

LMK!

@bernaferrari
Copy link
Owner

Usually I use const instead of function, but I guess it is personal. I can't promise the code will stay in your style forever (in case I start maintaining again in the future) lol but while you are working, sure, absolutely, go for it. I have no problem. Make as much changes as you want. I welcome every addition.

@davestewart
Copy link
Contributor Author

Totally expected you to say "no way"... so, thanks!

I'll worry about it after the next set of PRs.

Thanks again!

@bernaferrari
Copy link
Owner

For me the semicolon helps, last time I tried without a few years ago I had many issues. Maybe some were solved, maybe all were solved. Nowadays I just write the code and do command+l to format, prettier auto-adds the semicolon for me, so I almost never have to worry about it. But if you have zero issues, zero bugs, never had a problem, go for it. Vercel doen't use them, shadcn/ui also doesn't, as long as it works fine, feel free.

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

No branches or pull requests

2 participants