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 ruleP1universalStack: JavaScript/TypeScript
validationuxuploadscorrectness
Validate input at the point of entry, not after the side effect
Check constraints (e.g. file size) when the user provides the input so the action can be blocked, rather than validating only at final submit after the upload already happened.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | // only checked on submit, after the image already uploaded |
| 2 | const onSubmit = () => { |
| 3 | if (uploadedImage.size > MAX) showError(); |
| 4 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | fileInput.addEventListener('change', () => { |
| 2 | const file = fileInput.files?.[0]; |
| 3 | if (file && file.size > MAX) { |
| 4 | showError(); |
| 5 | fileInput.value = ''; |
| 6 | } |
| 7 | }); |
Explanation (EN)
Objašnjenje (HR)