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

Set up a code formatter #834

Open
tomitheninja opened this issue Aug 28, 2021 · 0 comments
Open

Set up a code formatter #834

tomitheninja opened this issue Aug 28, 2021 · 0 comments
Assignees
Labels
discussion This issue is opinion based low priority No hurry, this can wait. refactor Rewrite code without changing it's behavior

Comments

@tomitheninja
Copy link
Contributor

tomitheninja commented Aug 28, 2021

In my opinion, there are too many extra whitespaces and long lines in our code.

Maybe we should set up a code formatter like Prettier.

Prettier also integrates well with eslint: https://prettier.io/docs/en/install.html#eslint-and-other-linters
It can take over some of it's rules and do it better.

Prettier has a configuration option, that does not match any eslint rules.

printWidth

Specify the line length that the printer will wrap on.

With eslint we used 100 for max-len, but unlike in eslint this option is not a hard limit. Prettier might make a bit longer lines than this.

In my opinion, we should go with the default value, which is 80.

trailingComma

Print trailing commas wherever possible in multi-line comma-separated syntactic structures. (A single-line array, for example, never gets trailing commas.)
Valid options:

  • "es5" - Trailing commas where valid in ES5 (objects, arrays, etc.). No trailing commas in type parameters in TypeScript.
  • "none" - No trailing commas.
  • "all" - Trailing commas wherever possible (including function parameters and calls). To run, JavaScript code formatted this way needs an engine that supports ES2017 (Node.js 8+ or a modern browser) or downlevel compilation. This also enables trailing commas in type parameters in TypeScript (supported since TypeScript 2.7 released in January 2018).

Currently, we are using no commas.

Because of this when we append a new property to a multi-line structure, a line change will occur in the upper line.

const obj = {
-  foo: 'bar'
+  foo: 'bar',
+  bar: 'foo'
}

This makes the git changelog bloated.

We are probably not using trailing commas because the JSON format does not support it, however, JSON was designed for data transfer and code.

Currently, we are using no commas, but I think we should switch to "es5" to avoid line changes.

@tomitheninja tomitheninja added refactor Rewrite code without changing it's behavior low priority No hurry, this can wait. discussion This issue is opinion based labels Aug 28, 2021
@tomitheninja tomitheninja self-assigned this Aug 28, 2021
@tomitheninja tomitheninja changed the title [discussion] Set up a code formatter Set up a code formatter Aug 28, 2021
tomitheninja added a commit that referenced this issue Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion This issue is opinion based low priority No hurry, this can wait. refactor Rewrite code without changing it's behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant