Code format, style, and TypeScript issue #2863
Replies: 1 comment 1 reply
-
Hey @JosefBredereck — these are all good things to note. We are working on adopting the exact suggested settings from the ESLint and Prettier authors, and there is a PR in the works to do so. At that time, we will be solidifying our formatting style guide, and I'll make sure that the team addresses these items in our contributing guide. I will convert this to a discussion because optimizing our formatting / style guide options is more of a feature request than an issue, but as a heads-up - - this is very important and I do see the value in clearly documenting all of this very soon. @AlessioGr is working on that as we speak. Good to have you in our community. The team and I are impressed with the work you're already contributing and we hope to continue to see you around! You are very clearly a talented engineer. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Link to reproduction
https://github.com/payloadcms/payload
To Reproduce
Describe the Bug
While I was working on the code to contribute, I stumbled upon, an issue.
My IDE automatically reformats files when I save so that I do not have to rely on maintaining spaces and line breaks by myself.
Therefore, I looked into the codebase which settings you follow, but I couldn't grasp which format is preferred.
The contribution guidelines do not state any info regarding this topic.
Types:
They come in three different formats, like the ones below.
payload/src/types/index.ts
Lines 26 to 30 in 51c2ab1
payload/src/auth/operations/login.ts
Lines 17 to 21 in 51c2ab1
payload/src/uploads/types.ts
Lines 91 to 96 in 51c2ab1
Occasionally, they even come in all three versions in the same file https://github.com/payloadcms/payload/blob/master/src/uploads/types.ts
Function definitions
Functions can be written as function declaration and as arrow function. I have seen both possibilities used to my feeling random.
Is there any preferred style, or can I use what I think fits the purpose?
Exports and imports
When I want to add new functionality and want to expose it to the other parts of the code base, do you prefer :
Default exports/imports
Named exports/imports
Code Format
There are those two rules defined for the entire codebase.
What about the other possible formats?
Typescript code checks
Furthermore, worth noting. If you have a type configured and there are properties that can be either a value or null/undefined typescript will not notice if you are using something wrong.
Since you have
"strict": false
in the compiler options, the types will always be converted to the non nullish types. And this is by far the biggest issue in the whole codebase because TypeScript will not tell you if you need to use optional chaining or if a type guard is missing!Beta Was this translation helpful? Give feedback.
All reactions