Skip to content

Commit 26edd14

Browse files
authored
Merge pull request #14 from junekimdev/Implement-cording-standards
Implement cording standards
2 parents 036594f + cd610e4 commit 26edd14

File tree

18 files changed

+238
-157
lines changed

18 files changed

+238
-157
lines changed

coding-standards.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Coding Standards
2+
3+
## Table of Contents
4+
5+
1. [Naming Convention](#naming-convention)
6+
1. [Import](#import)
7+
8+
---
9+
10+
## Naming Convention
11+
12+
### Format Options[^1]
13+
14+
1. `camelCase` : standard `camelCase` format - no underscores are allowed between characters, and consecutive capitals are allowed (i.e. both `myID` and `myId` - are valid).
15+
1. `PascalCase` : same as `camelCase`, except the first character must be upper-case.
16+
1. `snake_case` : standard `snake_case` format - all characters must be lower-case, and underscores are allowed.
17+
1. `strictCamelCase` : same as `camelCase`, but consecutive capitals are not allowed (i.e. `myId` is valid, but `myID` is not).
18+
1. `StrictPascalCase` : same as `strictCamelCase`, except the first character must be upper-case.
19+
1. `UPPER_CASE` : same as `snake_case`, except all characters must be upper-case.
20+
21+
### Format of Names
22+
23+
#### General
24+
25+
| Name Of | Format | Prefix |
26+
| --------: | :----------- | -------------------- |
27+
| Classe | `PascalCase` | |
28+
| Variable | `camelCase` | |
29+
| Function | `camelCase` | |
30+
| File | `camelCase` | (component name)[^2] |
31+
| Directory | `camelCase` | |
32+
| Constant | `UPPER_CASE` | |
33+
34+
##### Files for React Component
35+
36+
1. Prefix with component name
37+
1. Postfix with utility
38+
1. Use **singular** form for `type` and `state` files
39+
1. Postfix view-file with import-name of the `View` component
40+
1. Extension should be `tsx` only when `react` element is exported
41+
1. Example:
42+
- `compInteractor.ts`
43+
- `compPresenter.tsx`
44+
- `compViewInput.tsx`
45+
- `compState.ts`
46+
- `compType.ts`
47+
48+
#### React Variables
49+
50+
| Name Of | Format | Prefix |
51+
| --------: | :----------- | ------ |
52+
| Component | `PascalCase` | |
53+
| Type | `PascalCase` | |
54+
| Interface | `PascalCase` | |
55+
| State | `camelCase` | |
56+
| Hook | `camelCase` | `use` |
57+
| URL | `UPPER_CASE` | |
58+
59+
## Import
60+
61+
### Local
62+
63+
1. Import local states as `mState` and use them with dot notation
64+
1. Import local types as `mType` and use them with dot notation
65+
1. Import example:
66+
- State : `import * as mState from './compState';`
67+
- Type : `import * as mType from './compType';`
68+
1. Usage example:
69+
- State : `const inputValue = useAtom(mState.inputValue);`
70+
- Type :`const inputValue : mType.InputValue = {};`
71+
72+
### Global
73+
74+
1. Import global states as `gState` and use them with dot notation
75+
1. Import global types as `gType` and use them with dot notation
76+
1. Import example:
77+
- State : `import * as gState from '../../controller/data/states';`
78+
- Type : `import * as gType from '../../controller/data/types';`
79+
1. Usage example:
80+
- State : `const inputValue = useAtom(gState.inputValue);`
81+
- Type :`const inputValue : gType.InputValue = {};`
82+
83+
[^1]: <https://typescript-eslint.io/rules/naming-convention/#format-options>
84+
85+
[^2]: `( )` means "if applicable"

components/errors/errorsViewImage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { useAtomValue } from 'jotai';
22
import Image from 'next/image';
33
import Link from 'next/link';
4-
import { stateErrorCode } from '../../controllers/data/states';
4+
import * as gState from '../../controllers/data/states';
55
import imageSrc404 from '../../public/assets/images/404_broken_robot.png';
66
import imageSrc500 from '../../public/assets/images/500_faulty_dog.png';
77
import styles from './errors.module.scss';
88

99
const View = () => {
10-
const errorCode = useAtomValue(stateErrorCode);
10+
const errorCode = useAtomValue(gState.errorCode);
1111

1212
return (
1313
<div className={styles.errorImage}>

components/example/examplePresenter.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { placeholderUrl } from '../../controllers/apiURLs';
22
import { useStaticQuery } from '../../controllers/net/staticQuery';
33
import styles from './example.module.scss';
4-
import { ExamplePost } from './exampleType';
4+
import * as mType from './exampleType';
55
import Posts from './exampleViewPosts';
6-
76
const Presenter = () => {
8-
const query = useStaticQuery<ExamplePost[]>(placeholderUrl);
7+
const query = useStaticQuery<mType.Post[]>(placeholderUrl);
98

109
let contents;
1110
switch (query.status) {

components/example/exampleType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type ExamplePost = {
1+
export type Post = {
22
id: number;
33
title: string;
44
body: string;

components/example/exampleViewPostSingle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { memo } from 'react';
22
import styles from './example.module.scss';
3-
import { ExamplePost } from './exampleType';
3+
import * as mType from './exampleType';
44

55
// This uses props to get data from parent
6-
const View = ({ post }: { post: ExamplePost }) => {
6+
const View = ({ post }: { post: mType.Post }) => {
77
return <p className={styles.view}>{post.title}</p>;
88
};
99

components/example/exampleViewPosts.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import styles from './example.module.scss';
2-
import { ExamplePost } from './exampleType';
2+
import * as mType from './exampleType';
33
import PostSingle from './exampleViewPostSingle';
44

5-
const View = ({ data }: { data: ExamplePost[] }) => {
6-
const dataMapper = (post: ExamplePost) => <PostSingle key={post.id} post={post} />;
5+
const View = ({ data }: { data: mType.Post[] }) => {
6+
const dataMapper = (post: mType.Post) => <PostSingle key={post.id} post={post} />;
77

88
return <div className={styles.view}>{data.map(dataMapper)}</div>;
99
};

components/meta/meta.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Head from 'next/head';
22
import { useGTM } from './gtm';
3-
import { TMPropsMeta } from './metaType';
3+
import * as mType from './metaType';
44

5-
const Meta = (props: TMPropsMeta) => {
5+
const Meta = (props: mType.Props) => {
66
const authorName = 'junekimdev';
77
const siteName = "another junekimdev's website";
88
const homeUrl = process.env.NEXT_PUBLIC_URL ?? 'localhost:3000';

components/meta/metaType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReactNode } from 'react';
22

3-
export type TMPropsMeta = {
3+
export type Props = {
44
title: string;
55
desc: string;
66
url: string;

controllers/data/states.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { atom } from 'jotai';
22

3-
export const stateErrorCode = atom(500);
3+
export const errorCode = atom(500);

controllers/data/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type TypeError = { code: number; message: string };
1+
export type Error = { code: number; message: string };

0 commit comments

Comments
 (0)