Naming
-
Follow the guidelines in this naming cheatsheet (opens in a new tab).
-
Use
camelCasefor variables, functions, methods, and class names. -
Use
kebab-casefor file names and folder names. -
Components should contain the
.componentsuffix in their name (e.g.user.component.tsx). This nomenclature is used to distinguish components from other files such as resources, stylesheets, and tests, and determines where the i18next-parser tool extracts translation keys and strings from. Translation keys and strings will not be extracted from files that do not match this convention by default. -
Components may also contain different suffixes to indicate their purpose. These custom suffixes should be used in addition to the base
.componentsuffix. They include:.extensionfor components that render extensions e.g. lab-order-basket-panel.extension.tsx (opens in a new tab) for theLab Order Basket panelextension..modalfor components that render modals e.g. delete-condition.modal.tsx (opens in a new tab) for theDelete Conditionsmodal..workspacefor components that render forms in the workspace e.g. order-basket.workspace.tsx (opens in a new tab) for theOrder Basketworkspace.
-
Unit and integration test files should contain the
.testsuffix in their name (e.g.user.test.tsx). Do not include the wordcomponentin the test file name. -
Playwright e2e tests should contain the
.specsuffix in their name (e.g.user.spec.ts). -
Stylesheets should not contain
.componentsuffix in their name (e.g.user.component.scss). This is because stylesheets are not components, and are not translated by the translation system. Instead, stylesheets should be named after the component they are styling (e.g.user.scss). -
Resource files that encapsulate data fetching logic should contain the
.resourcesuffix in their name (e.g.user.resource.ts). This is to distinguish them from other files such as components, stylesheets, and tests. -
Use appropriate extensions for TypeScript files:
- Use the
.tsxextension for files that contain JSX.
// user.component.tsx const UserComponent: React.FC<UserComponentProps> => { return <div>User Component</div> }- Use the
.tsextension for files that do not contain JSX.
// user.resource.ts export const fetchUser = () => { return openmrsFetch<User>('/ws/rest/v1/user'); }In most cases, you shouldn't need to use the
.tsxextension for files outside thesrcdirectory. - Use the
-
Follow the extension system nomenclature guide when naming your extensions and extension slots.
-
Use the file name as the component name. For example,
user.component.tsxshould contain a component namedUserComponent. This makes it easier to find the component in the codebase. -
Avoid using DOM component prop names for different purposes. For example, avoid using the
styleprop to pass configuration options. Instead, use a descriptive prop name that matches its purpose, such asconfigoroptions. -
Use
camelCasefor prop names. This is consistent with the naming convention for variables, functions, and methods. -
Translation keys should be in
camelCasewhereas translation strings should be insentence case. For example,firstNameis a translation key whereasFirst nameis it's corresponding translation string. -
Frontend modules in monorepos should have names that start with the
esm-prefix. The name of the module should describe what the module does. For example,esm-user-managementis a good name for a frontend module handling user management concerns andesm-patient-chartis a good name for a frontend module handling patient chart concerns. -
Event handler props should be named after they event they handle
e.g. onClickfor a click handler. By convention, event handler props should start with theonprefix, followed by a capital letter. -
State updater functions should be named after the state they update. For example,
setFirstNameis a good name for a state updater function that updates thefirstNamestate. -
What to name your branches is typically down to personal preference. However, when in doubt, name your branches using the conventional commit (opens in a new tab) type that your work conforms to, followed by a slash and a short dash-separated description of the work. Good examples include:
feat/debounced-order-basket-search,fix/missing-translation,chore/bump-dependenciesandrefactor/remove-unused-code.