Skip to content

Commit 186621f

Browse files
committed
add a cocalc style guide
1 parent 3ceed73 commit 186621f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/dev/STYLE.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
CoCalc Style Guide
2+
3+
- Use the _defaults_ with the latest version of prettier on all of our Javascript and Typescript code.
4+
5+
- Language: Always prefer Typescript over Javascript and CoffeeScript
6+
7+
- Use the standard Javascript camelCase convention for variable names, unless there is a good reason otherwise. Good reasons include: variable names that are also used in PostgreSQL and interop with Python (lower case with underscores).
8+
9+
- React: Always prefer functional components over class components
10+
11+
- React: Use the style of https://react.dev/learn/typescript for React with Typescript. In particular, use
12+
13+
```ts
14+
function MyButton({ title, disabled }: MyButtonProps) {
15+
return <button disabled={disabled}>{title}</button>;
16+
}
17+
```
18+
19+
and do NOT use
20+
21+
```ts
22+
function MyButton(props: MyButtonProps) {
23+
return <button disabled={props.disabled}>{props.title}</button>;
24+
}
25+
```
26+
27+
also, do NOT use
28+
29+
```ts
30+
const MyButton: React.FC<MyButtonProps> = (props) => {
31+
return <button disabled={props.disabled}>{props.title}</button>;
32+
};
33+
```
34+
35+
Advantages of the first version:
36+
37+
- typescript detects unused props,
38+
- defaults are natural and do not need MyButton.defaultProps, which is deprecated,
39+
- uses minimal notation (less characters typed),
40+
- very common in tutorials and other code

0 commit comments

Comments
 (0)