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: JavaScript/TypeScript
validationconfigclean-codemaintainability
Extract validation rules into a small helper/config
Centralize allowed-type validation (e.g. accepted image MIME types) in a helper or config constant so it's easy to find and change, rather than inlining conditions.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | if (file.type !== 'image/png' && file.type !== 'image/jpeg') reject(); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const ALLOWED_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/webp']; |
| 2 | const isAllowedImage = (file: File) => ALLOWED_IMAGE_TYPES.includes(file.type); |
| 3 | if (!isAllowedImage(file)) reject(); |
Explanation (EN)
Objašnjenje (HR)