Skip to content

Coding Guidelines

Lean towards kebab case for most file names. If you see an exception such as the ‘gg_native’ folder its because the react native init system doesn’t except kebab case.

Most coding conventions are applied by the Biome linter and formatter. You can find the ‘biome.json’ config file in the root of the repo.

  • Directory.github/
  • Directory.vscode/
  • Directorymono/
  • Directorynative/
  • .gitignore
  • biome.json

Functions

Explicit functions should be ‘named’, not arrow functions

// Valid
function myFunction() {
// ...
}
// Not valid
const myFunction = () => {
// ...
}

Arrow functions are great when needed in-line

myArray.map((item) => {
return item + 1;
});

Imports

When importing functions from the project (not NPM) use file extensions. This means the monorepo tools don’t need to do extra work trying a range of extensions on hundreds of files. The project is set up so you can rely on autocomplete for imports and it will add the extension for you.

// Valid
import { myFunction } from './my-file.ts';
// Not valid
import { myFunction } from './my-file';

Exports

A common problem is the use of ‘barrel files’ which export everything from a folder. This can cause performance issues, especially in a monorepo. You need just one function from a file, but behind the scenes the whole file is being imported and parsed.

Instead, export each function directly from the file and rely on autocomplete to help you find the right file.

// Valid
export function myFunction() {
// ...
}
// Not valid
export * from './my-file';

The Biome linter enforces this rule.

TypeScript

To avoid TSX parsing issues with < > arrays are declared as any[] and not Array<T>.

// Valid
const myArray: any[] = [];
// Not valid
const myArray: Array<T> = [];

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

feat: add hat wobble
^--^ ^------------^
| |
| +-> Summary in present tense.
|
+-------> Type: chore, docs, feat, fix, refactor, style, or test.

More Examples:

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

References: