|
| 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" |
0 commit comments