com um clique
writing-code-style-guide
// This skill contains in-depth code style guidance and best practices. You should read it before writing application code.
// This skill contains in-depth code style guidance and best practices. You should read it before writing application code.
Use whenever it is necessary to work with the echoes shared component library or design tokens from @sonarsource/echoes-react
Use this skill when you need a better understanding of how the projects in the webapp NX monorepository are connected, how they interact, and where code should live. Recommend using this skill eagerly if it seems like it may be helpful.
Use this skill when you need to write or understand testing best practices in webapp
| name | writing-code-style-guide |
| description | This skill contains in-depth code style guidance and best practices. You should read it before writing application code. |
| allowed-tools | Read, Grep, Glob |
Default exports can lead to confusion as they can be imported with a different name, sometimes unwittingly.
export default <const, function, etc>export { } or export <const, function, etc>We use functional components instead of class components. There are still some class components, we should migrate away from these as appropriate.
We mostly prefer Tailwind helper classes for styling, but Emotion.js can also be used to build components.
For now, any text that is to appear in the UI must be declared in English:
libs/sq-server-commons/src/l10n/default.ts for SQSprivate/apps/sq-cloud/src/l10n/messages.json for SQCText should always be plain text, and no markup is allowed.
translate() and translateWithParameters()<FormattedMessage id="msg_id" /> or intl.formatMessage({ id: 'msg_id' })intl objectconst intl = useIntl(); can be used inside functional componentsconst intl = getIntl(); can be used everywhere else.The <FormattedMessage> component from React Intl also allows to inject additional markup. For instance:
<FormattedMessage
id="billing.price_from_x"
values={{
price: <span className="big">{formatPrice(startingPrice)}</span>
}}
/>
Currently, most of the code uses fragmented translations to style elements or add interactive embedded elements. e.g.:
// Do not do this:
<FormattedMessage
id="portfolio_overview.desciption"
values={{
link: (
<DocumentationLink to={DocLink.ManagingPortfolios}>
{translate('portfolio_overview.desciption.link')}
</DocumentationLink>
),
}}
/>
// Translation looks like:
// portfolio_overview.desciption=A summary of information from the project branches that was chosen for this portfolio. To learn more about how portfolio ratings are calculated, see {link}.
// portfolio_overview.desciption.link=managing portfolios documentation
This makes the translation more challenging. We can minimize the transition load by using rich translations. The above example would be rewritten:
// Do this instead:
<FormattedMessage
id="portfolio_overview.desciption"
values={{
link: (text) => (
<DocumentationLink to={DocLink.ManagingPortfolios}>
{text}
</DocumentationLink>
),
}}
/>
// Translation looks like:
// portfolio_overview.desciption=A summary of information from the project branches that was chosen for this portfolio. To learn more about how portfolio ratings are calculated, see <link>managing portfolios documentation</link>.