You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add code_style, developer_guide and fix CONTRIBUTING.md (#29210)
* Remove reference to matrix-js-sdk in code_style.md
* Absorb exisiting documentation from matrix-react-sdk
* Crete a separate developer guide
* Remove sign-off from CONTRIBUTING.md
Since sign-off is irrelevant to element-web repo with the introduction
of CLA.
* Link to the new docs in README
* Elaborate on the rule
* Fix lint
Copy file name to clipboardExpand all lines: code_style.md
+37-45Lines changed: 37 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,6 @@ adjacent to. As of writing, these are:
5
5
6
6
- element-desktop
7
7
- element-web
8
-
- matrix-js-sdk
9
-
10
-
Other projects might extend this code style for increased strictness. For example, matrix-events-sdk
11
-
has stricter code organization to reduce the maintenance burden. These projects will declare their code
12
-
style within their own repos.
13
-
14
-
Note that some requirements will be layer-specific. Where the requirements don't make sense for the
15
-
project, they are used to the best of their ability, used in spirit, or ignored if not applicable,
16
-
in that order.
17
8
18
9
## Guiding principles
19
10
@@ -234,17 +225,19 @@ Unless otherwise specified, the following applies to all code:
234
225
235
226
Inheriting all the rules of TypeScript, the following additionally apply:
236
227
237
-
1. Types for lifecycle functions are not required (render, componentDidMount, andsoon).
238
-
2. Class components must always have a `Props` interface declared immediately above them. It can be
228
+
1. Component source files are named with upper camel case (e.g. views/rooms/EventTile.js)
229
+
2. They are organised in a typically two-level hierarchy - first whether the component is a view or a structure, and then a broad functional grouping (e.g. 'rooms'here)
230
+
3. Types for lifecycle functions are not required (render, componentDidMount, andsoon).
231
+
4. Class components must always have a `Props` interface declared immediately above them. It can be
239
232
empty if the component accepts no props.
240
-
3. Class components should have an `State` interface declared immediately above them, but after `Props`.
241
-
4. Props and State should not be exported. Use `React.ComponentProps<typeofComponentNameHere>`
233
+
5. Class components should have an `State` interface declared immediately above them, but after `Props`.
234
+
6. Props and State should not be exported. Use `React.ComponentProps<typeofComponentNameHere>`
242
235
instead.
243
-
5. One component per file, except when a component is a utility component specifically for the "primary"
236
+
7. One component per file, except when a component is a utility component specifically for the "primary"
244
237
component. The utility component should not be exported.
245
-
6. Exported constants, enums, interfaces, functions, etc must be separate from files containing components
238
+
8. Exported constants, enums, interfaces, functions, etc must be separate from files containing components
246
239
or stores.
247
-
7. Stores should use a singleton pattern with a static instance property:
240
+
9. Stores should use a singleton pattern with a static instance property:
248
241
249
242
```typescript
250
243
class FooStore {
@@ -261,44 +254,41 @@ Inheriting all the rules of TypeScript, the following additionally apply:
5. ClassnamesforDOMelementswithinaviewwhicharen'tcomponentsarenamedbyappendingalowercamelcaseidentifiertotheview'sclassname - e.g. .mx_MyFoo_randomDivishowyou'dnametheclassofanarbitrarydivwithintheMyFooview.
0 commit comments