Naming
-
Follow the guidelines in this naming cheatsheet .
-
Use
camelCasefor variables, functions, methods, and props. UsePascalCasefor React components, classes, and exported type 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 the globs in the package’sextract-translationsscript. -
Specialized components use purpose-specific suffixes instead of the base
.componentsuffix. They include:.extensionfor components that render extensions e.g. lab-order-basket-panel.extension.tsx for theLab Order Basket panelextension..modalfor components that render modals e.g. delete-condition.modal.tsx for theDelete Conditionsmodal..workspacefor components that render forms in the workspace e.g. order-basket.workspace.tsx for theOrder Basketworkspace.
-
Keep the
extract-translationsscript aligned with the suffixes used in the package. Generated modules scan.component.tsx,.extension.tsx,.modal.tsx, andsrc/index.tsby default; addsrc/**/*.workspace.tsxif a workspace file contains translatable strings. -
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
.componentin their name. Name them after the component or feature they style, usually with the.scssextension (for example,user.scssforuser.component.tsx). Use.module.scssonly when the package is intentionally using CSS Modules. -
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 function UserComponent(props: UserComponentProps) { return <div>User Component</div>; }- Use the
.tsextension for files that do not contain JSX.
// user.resource.ts export async function fetchUser() { const response = await openmrsFetch<User>('/ws/rest/v1/user'); return response.data; }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 its 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 the event they handle, such as
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 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-dependencies, andtest/add-order-basket-coverage.