Skip to content

Commit 59ebec2

Browse files
committed
merged with develop
2 parents dc8125e + 44c8812 commit 59ebec2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+14673
-233
lines changed

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Website
1+
# Coding Guidelines
22

3+
This website contains coding standards and guidelines commonly followed at Leapfrog.
34
This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator.
45

56
### Installation
@@ -22,12 +23,4 @@ This command starts a local development server and open up a browser window. Mos
2223
$ yarn build
2324
```
2425

25-
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26-
27-
### Deployment
28-
29-
```
30-
$ GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
31-
```
32-
33-
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
26+
This command generates static content into the `build` directory and can be served using any static contents hosting service.

docs/02-1-files.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/02-2-classes.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/02-3-functions.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/02-4-variables.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/02-5-constants.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/02-6-folders.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/general/clean-code.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
id: clean-code
3+
title: Clean code cheat sheet
4+
---
5+
6+
import useBaseUrl from '@docusaurus/useBaseUrl';
7+
8+
#### [Original Source link](https://www.planetgeek.ch/wp-content/uploads/2014/11/Clean-Code-V2.4.pdf)
9+
<img alt="Docusaurus with Keytar" src={useBaseUrl('clean-code/page-1.png')} width = "2500px" />
10+
11+
<img alt="Docusaurus with Keytar" src={useBaseUrl('clean-code/page-2.png')} width = "2500px" />
12+
13+
<img alt="Docusaurus with Keytar" src={useBaseUrl('clean-code/page-3.png')} width = "2500px" />
14+
15+
<img alt="Docusaurus with Keytar" src={useBaseUrl('clean-code/page-4.png')} width = "2500px" />

docs/general/general-guidelines.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
id: guidelines
3+
title: General Coding Standards
4+
---
5+
6+
* Firstly, it's recommended to use a static code analysis tools to analyze the code before it's pushed to the version control. For eg: eslint, tslint, pylint, codeclimate, sonar etc. Development Team should identify corresponding tool for their tech stack and use it to follow community wide general coding standards and avoid general bad practice.
7+
8+
* No hard coding, use constants/configuration values instead of hard-coding literal values.
9+
10+
* Do not store config as constants in the code. Use separate config files for storing application credentials such as passwords, access key etc. Make sure you add this file in .gitignore file.
11+
12+
* Group similar values under enums, constant groups or similar data structures depending on what the language allows.
13+
14+
* Avoid code duplication (DRY). If the same code needs to be reused in multiple places, create a extract a common function instead.
15+
16+
* While writing code make sure it doesn't violate SRP (Single Responsibility Principle). To be more specific take care of the following:
17+
18+
* A function/method should do only one task.
19+
20+
* A class should have only one concern or should take care of only one aspect.
21+
22+
* Avoid having more than 3 parameters in a function/method.
23+
24+
* Avoid creating God classes or utils that is capable of doing every thing from string manipulation to checking if user is authored. This is a big NO.
25+
26+
* Follow separation of concerns principles properly, and identify what type of code should go in which layer or tier eg: What type of code should be written in Model, View, Service and Controller etc.
27+
28+
* Write pure functions where ever possible. It keeps the code more understandable and deterministic, plus it helps to avoid unexpected run time issues due to mutation.
29+
30+
* If your project is following OOP approach, follow it precisely depending upon the language specific best practices. If the project is following a FP (Functional Programming) approach, use it's best practices. Don't try to mix multiple paradigm, which results in more chaos and confusion in the code.
31+
32+
* Avoid unnecessary else blocks as much as possible for better readability and cleanliness.
33+
34+
<!--JavaScript-->
35+
// Bad practice
36+
function nullIfEmpty(value: any) {
37+
if (typeof value === 'string') {
38+
return value.trim() === '' ? null : value;
39+
} else {
40+
return value;
41+
}
42+
}
43+
44+
// Good practice
45+
function nullIfEmpty(value: any) {
46+
if (typeof value !== 'string') {
47+
return value;
48+
}
49+
return value.trim() === '' ? null : value;
50+
}
51+
52+
* Avoid nested if blocks, multiple if blocks. No pyramid of doom.
53+
54+
* Break down or refactor code with complexity into multiple smaller chunks i.e functions/methods.
55+
56+
* DocBlocks / Doc comments – Add doc blocks for each and every function, class, interface, etc to clearly mention what they do. Docblocks also should mention the parameter types or return types clearly.
57+
58+
* Class level documentation, document public functions and interface. Follow language specific documentation standard.
59+
60+
* Also, make sure you write doc blocks, comments etc in proper english. Re-check your sentences, to ensure they're typo free.
61+
62+
* Different languages have different standards for doc blocks. Follow the language specific standard for doc blocks. For examples:
63+
64+
<!--JavaScript-->
65+
/**
66+
* Hit the twilio API to send notifications.
67+
*
68+
* @param {NotificationPayload} payload
69+
* @returns {Promise<object>}
70+
*/
71+
function sendNotification(payload: NotificationPayload): Promise<object> {
72+
return twilioClient.sendMessage(payload);
73+
}
74+
75+
<!--Python-->
76+
def rollback(id=None):
77+
'''
78+
Deployment rollback to the previous build, or
79+
the build identified by the given id.
80+
'''
81+
82+
(_, current_path) = setup_remote()
83+
history = load_history()
84+
85+
# If the current build in the history is not set yet or
86+
# there aren't any previous builds on the history
87+
# rollback is not possible.
88+
if not history['current'] or not history['builds']:
89+
remote_info('Could not get the previous build to rollback.')
90+
return
91+
...
92+
93+
* Avoid re-inventing the wheel. Use framework features, or utilities provided by libraries wherever possible instead of writing custom code.
94+
95+
* Don't hard-code text data/content in the code itself, instead put text content/messages in the internationalization files and use the content identifiers instead.
96+
97+
* Each Components, Classes, or Interfaces should be written in their own file. And the filename should be named same as it's identifier name. (This could be an exception for python).
98+
99+
* Follow language specific naming convention.
100+
101+
* Use PascalCase naming convention for Components, Classes, or interfaces, enums, or other custom types.
102+
103+
* Use camelCase for naming functions, variables etc.
104+
105+
* Use snake_case for naming database columns, table names etc.
106+
107+
* Use **CAPITAL_CASE_WITH_UNDERSCORES** for defining constants eg: const **PAGINATION_MAX_ROWS = 15**.
108+
109+
* Classes/Interfaces/Components/Services should be **named as a noun (singular)** as they represent a real world entity.
110+
111+
* For instance: **Person, PersonList, User, ArrayAggregator, PerformanceEvaluator, SourceAnalyzer, Inspector, TaskService, UserServiceTest** etc.
112+
Avoid prefixing them with verbs or naming them as plural entities. For example bad class names could be: **GetUser, Users, Todos, Listeners, GetUserById** etc.
113+
Functions or methods should be named as verbs or actions as they represent actions. So, function name should clearly say what that function does.
114+
Good function names: **getPersonList, fetchUsers, getCurrentUser, removeTodoItems, initialize, clear, flush, activate, isActive(), shouldNotify()**
115+
Bad function names are those that isn't meaningful to the task it does.
116+
117+
* A function should do one thing and should be named accordingly. **SRP(Single Responsibility Principle)** also applies here. If you have broken down the function following SRP then there won't be a function such as: **getUserByIdAndActivateItAndLogin**, **checkPeopleAndArchiveThem** (bad practice).
118+
119+
* All the releases should be properly tagged in git.
120+
121+
* Follow Major, Minor and Patch format. and include information about Production and Dev release.
122+
123+
* Patch - Bug fixes
124+
125+
* Minor - Feature additions/enhancements
126+
127+
* Major - Change in business logic.
128+
129+
* All the releases should be identified as pre-release in git if they are not released for production.
130+
131+
* Follow Gitflow.
132+
133+
* Sanity checklist document should be present.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
id: branch_naming_convention
3+
title: Branch Naming Convention
4+
sidebar_label: Branch Naming Convention
5+
---
6+
7+
#### The following convention should be followed:
8+
9+
* Branch name should exactly match with the corresponding JIRA ticket that you will be working on. `<project-name>-<ticket-number>`
10+
* FHF-100
11+
* DEL-200
12+
13+
* If there's no JIRA or project management tool in use, the branch naming strategy should be feature specific.
14+
* upgrade-php
15+
* add-button-tooltip
16+

0 commit comments

Comments
 (0)