diff options
Diffstat (limited to 'STYLE_GUIDE.md')
| -rw-r--r-- | STYLE_GUIDE.md | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/STYLE_GUIDE.md b/STYLE_GUIDE.md index 8dd3be589..a46ce221f 100644 --- a/STYLE_GUIDE.md +++ b/STYLE_GUIDE.md @@ -4,8 +4,71 @@ - AVOID unnecessary destructuring of variables. instead of doing `const { a, b } = obj` just reference it as obj.a and obj.b. this preserves context - AVOID `try`/`catch` where possible -- AVOID `else` statements - AVOID using `any` type -- AVOID `let` statements - PREFER single word variable names where possible - Use as many bun apis as possible like Bun.file() + +# Avoid let statements + +we don't like let statements, especially combined with if/else statements. +prefer const + +This is bad: + +Good: + +```ts +const foo = condition ? 1 : 2 +``` + +Bad: + +```ts +let foo + +if (condition) foo = 1 +else foo = 2 +``` + +# Avoid else statements + +Prefer early returns or even using `iife` to avoid else statements + +Good: + +```ts +function foo() { + if (condition) return 1 + return 2 +} +``` + +Bad: + +```ts +function foo() { + if (condition) return 1 + else return 2 +} +``` + +# Prefer single word naming + +Try your best to find a single word name for your variables, functions, etc. +Only use multiple words if you cannot. + +Good: + +```ts +const foo = 1 +const bar = 2 +const baz = 3 +``` + +Bad: + +```ts +const fooBar = 1 +const barBaz = 2 +const bazFoo = 3 +``` |
