Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: TypeScript
constantsi18nmaintainability
Centralize user-facing strings in a single constants module
Collect repeated user-facing strings (error/success messages, labels, locale codes) into one `as const` object or enum instead of scattering literals across code and tests. A single source keeps wording consistent, makes it reusable in assertions, and is the first step toward i18n.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codets
| 1 | res.status(404).json({ message: 'Not found' }); |
| 2 | // ...and in the test: |
| 3 | expect(body.message).toBe('Not found'); |
Explanation (EN)
The literal is duplicated across code and tests; changing wording means hunting every copy.
Objašnjenje (HR)
Good example
New codets
| 1 | export const Messages = { NOT_FOUND: 'Not found' } as const; |
| 2 | res.status(404).json({ message: Messages.NOT_FOUND }); |
| 3 | expect(body.message).toBe(Messages.NOT_FOUND); |
Explanation (EN)
One constant is referenced everywhere, so wording stays in sync.
Objašnjenje (HR)