From 3eae714269b5e331596da372089b2dd98556bea1 Mon Sep 17 00:00:00 2001 From: Clemens Zeidler Date: Tue, 19 Jan 2021 21:32:52 +1300 Subject: [PATCH] Update code_style.md - Remove invalid single quotes item - Add TypeScript section - Add item regarding React function components and hooks Signed-off-by: Clemens Zeidler --- code_style.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/code_style.md b/code_style.md index fe04d2cc3d..c90ad359b3 100644 --- a/code_style.md +++ b/code_style.md @@ -35,12 +35,6 @@ General Style - lowerCamelCase for functions and variables. - Single line ternary operators are fine. - UPPER_SNAKE_CASE for constants -- Single quotes for strings by default, for consistency with most JavaScript styles: - - ```javascript - "bad" // Bad - 'good' // Good - ``` - Use parentheses or `` ` `` instead of `\` for line continuation where ever possible - Open braces on the same line (consistent with Node): @@ -164,6 +158,14 @@ ECMAScript - Apart from that, newer ES features should be used whenever the author deems them to be appropriate. - Flow annotations are welcome and encouraged. +TypeScript +---------- +- TypeScript is preferred over the use of JavaScript +- Its desirable to convert existing JavaScript files to TypeScript. TypeScript conversions should be done in small + chunks without functional changes to ease the review process. +- Use full type definitions for function parameters and return values. +- Avoid `any` types and `any` casts + React ----- - Pull out functions in props to the class, generally as specific event handlers: @@ -201,6 +203,8 @@ React this.state = { counter: 0 }; } ``` +- Prefer class components over function components and hooks (not a strict rule though) + - Think about whether your component really needs state: are you duplicating information in component state that could be derived from the model?