Install any skill in seconds. Free to start, no credit card required.
Get Started Free →If-else formatting, spacing, function parameters, and conditional rendering rules for the Trezor Suite codebase. Use when writing or reviewing TypeScript/React code.
.claude/skills/trezor-basic-syntax/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | -11% | 0% |
| case-09 | ✓→✓ | = Same ✓ | 40% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 39% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 90% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 38% | 0% |
tsx// bad - we don't like inline-if with else branch, harder to read if (condition) doSomething(); else doSomethingElse(); // good if (condition) { doSomething(); } else { doSomethingElse(); } // also good - inline if without else is fine if (condition) doSomething();
Try to use empty lines as a tool for structuring the code even better.
🔴 Hard to read function without spaces:
tsxexport const getPrerequisites = ({ router, device, transport }: PrerequisitesInput) => { const excluded = getExcludedPrerequisites(router); const prerequisite = getPrerequisiteName({ router, device, transport }); if (typeof prerequisite === 'undefined') return; if (excluded.includes(prerequisite)) return; return prerequisite; };
🟢 Well-arranged code:
tsxexport const getPrerequisites = ({ router, device, transport }: PrerequisitesInput) => { const excluded = getExcludedPrerequisites(router); const prerequisite = getPrerequisiteName({ router, device, transport }); if (typeof prerequisite === 'undefined') { return; } if (excluded.includes(prerequisite)) { return; } return prerequisite; };
As you can see, there is no line between excluded and prerequisite – that's because in this context that separation adds little benefit, instead the constants become the group. Base the groups not only on type of code _(method call, if-block, declaration)_ but on what that code does.
Functions accepting multiple parameters tend to be less readable and more error-prone. This can be solved by wrapping the params (all of them, or just some, i.e. "config" params) in an object, thus effectively naming the parameters. A rule of thumb is to use wrapping for functions with more than two params, but it depends on the specific case.
🔴 Confusing function call with many arguments:
tsxconst logAnimalNames = (cat: string, dog: string, guineaPig?: string, showHeading?: boolean) => { if (showHeading) { console.log('My Animals'); } console.log(cat); console.log(dog); if (guineaPig) { console.log(guineaPig); } }; logAnimalNames('Nancy', 'Rob', null, true);
What is the correct order? Why do I have to specify null for an optional param? What does true mean here?
🟢 Tidy function call with wrapped arguments:
tsxinterface LogAnimalParams { cat: string; dog: string; guineaPig?: string; showHeading?: boolean; } const logAnimalNames = ({ cat, dog, guineaPig, showHeading }: LogAnimalParams) => { if (showHeading) { console.log('My Animals'); } console.log(cat); console.log(dog); if (guineaPig) { console.log(guineaPig); } }; logAnimalNames({ cat: 'Nancy', dog: 'Rob', showHeading: true });
Make sure that a condition in JSX can only be true/false . If it could be 0 or "" , -42 , [] etc. React can render some of those values. In React Native it can also cause text outside Text component!
🔴 Do not use random value as condition
tsx// BAD { value && <Component value={value} />; }
🟢 Prefer
tsx// typeof hasValue === 'boolean' { hasValue && <Component value={value} />; }
tsx{ !!value && <Component value={value} />; }
tsxif (!value) return null; return <Component value={value} />;
Other measured skills in the registry, with their headline benchmark lift.