From 3eae714269b5e331596da372089b2dd98556bea1 Mon Sep 17 00:00:00 2001 From: Clemens Zeidler Date: Tue, 19 Jan 2021 21:32:52 +1300 Subject: [PATCH 1/4] 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? From 87f752dfa1f4395429e6bab20891d0af68c360ab Mon Sep 17 00:00:00 2001 From: Clemens Zeidler Date: Fri, 22 Jan 2021 22:22:33 +1300 Subject: [PATCH 2/4] Add reference to TypeScript in the comment on flow annotations Signed-off-by: Clemens Zeidler --- code_style.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_style.md b/code_style.md index c90ad359b3..6333e8cd94 100644 --- a/code_style.md +++ b/code_style.md @@ -156,7 +156,7 @@ ECMAScript - Be careful mixing arrow functions and regular functions, eg. if one function in a promise chain is an arrow function, they probably all should be. - Apart from that, newer ES features should be used whenever the author deems them to be appropriate. -- Flow annotations are welcome and encouraged. +- While flow annotations are welcome and encouraged consider to migrate the JS file to TypeScript (see next section). TypeScript ---------- From 662d89659f27578c9db62dd32257c489987fe900 Mon Sep 17 00:00:00 2001 From: czeidler Date: Tue, 26 Jan 2021 21:23:11 +1300 Subject: [PATCH 3/4] Update code_style.md Co-authored-by: J. Ryan Stinnett --- code_style.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_style.md b/code_style.md index 6333e8cd94..b982395516 100644 --- a/code_style.md +++ b/code_style.md @@ -161,7 +161,7 @@ ECMAScript 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 +- It's 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 From e8e0d808d42d0e905b2c82dca6cf3ac5fd0061f0 Mon Sep 17 00:00:00 2001 From: Clemens Zeidler Date: Tue, 26 Jan 2021 21:24:54 +1300 Subject: [PATCH 4/4] Remove out-dated comment about flow annotation --- code_style.md | 1 - 1 file changed, 1 deletion(-) diff --git a/code_style.md b/code_style.md index b982395516..5747540a76 100644 --- a/code_style.md +++ b/code_style.md @@ -156,7 +156,6 @@ ECMAScript - Be careful mixing arrow functions and regular functions, eg. if one function in a promise chain is an arrow function, they probably all should be. - Apart from that, newer ES features should be used whenever the author deems them to be appropriate. -- While flow annotations are welcome and encouraged consider to migrate the JS file to TypeScript (see next section). TypeScript ----------