[2.0.0-alpha3] Compoennt validator: some changes and additions

Created on 13 June 2024, 5 months ago
Updated 3 July 2024, 5 months ago

Menu & route

  • UI Patterns components >> UI Components
  • UI Patterns validation details for components. >> Components definitions and templates validation, provided by UI Patterns
  • /admin/reports/ui-patterns-devel >> /admin/reports/ui-components

General look

Can you put the warning lines in yellow instead of red?

Wording changes

Contextual. Related to Drupal installation.

"Keep components sandboxed by avoiding functions calling Drupal application "

Missing Stories on your definition, you should add one.

Notice: "You should declare a story in the definition."

Unknown variable: {var}! This variable is not in your definition or set in your template.

Error: "Unknown variable: {var}. The variable is declared in the component definition neither "

Don't use the bang ("!", "point d'interrogation" in French)

Forbidden Twig filter: `render`. Early rendering is harmful.

Error: "Forbidden Twig filter: `render`. Please ensure you are not rendering content too early."

Forbidden Twig filter: `without`. Manipulating Drupal content object is not compatible with Design system.

Notice: "Avoid `without filter on slots, which must stay opaque. Allowed with attributes objects until #3296456 is fixed."

Do not manipulate Drupal renderables in template. Slots are opaque.

"Keep slots opaque by not manipulating renderables in the template."

Wording: avoid telling about "bad architecture"

I know it comes from some internal documents, but it is not a very nice way of sharing this issue

Bad architecture for include: Component calling components.

Proposal: "Use slots instead of hard embedding a component in the template"

Bad architecture: The attachment is not easily discoverable.

Proposal: "The asset library attachment would be more discoverable if declared in the component definition."

Bad architecture for block: Component calling components.

Remove this rule, for now. Too soon. Still a bit controversial among the SDC community.

New rules (definition side)

See: https://docs.google.com/document/d/1-GaMK1Qk-h0hmB7GtAcnqPTuCOGMaxeRguop...

We can do another issue for those tasks, in beta2.

New rules (template side)

Methods

When checking the callables, check also the methods. Example: 'media--type-' ~ media.bundle()|clean_class,. They are all forbidden except the ones from https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%...

constant function

Example: {% if status is constant('MARK_NEW') %}

Must raise an error: "Keep components sandboxed by avoiding functions calling Drupal application "

Other rules

See specs for rules not implemented yet: https://docs.google.com/document/d/1-GaMK1Qk-h0hmB7GtAcnqPTuCOGMaxeRguop...

Updated rules

We are not promoting the use of {% block foo %} for slots, but if present, we need to add "foo" to the used variables instead of raising an "unused variable". So no unused errors for {% set foo = 'foo' %}{% block foo %}{% endblock %}.

📌 Task
Status

Fixed

Version

2.0

Component

UI Patterns Devel [2.x only]

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024