Track missing expected attributes

There is already a template rule, which allows to define rules for tracking disallowed attributes (Web:IllegalAttributeCheck). However, for accessibility and other use cases, you often need the opposite: the ability to detect missing attributes that are expected but not present.

Example:

  <ui:define name="headextension">
    <f:metadata>
      <f:viewParam name="id" value="#{baseManagedBean.id}" />
    </f:metadata>
  </ui:define>

  <ui:define name="content">
    <div class="card">
      <h5>Basic</h5>
      <p:inputText />

      <h5>Floating Label</h5>
      <span class="ui-float-label">
        <p:inputText id="float-input" value="#{inputTextView.text}" />
        <p:outputLabel for="@previous" value="Username" />
      </span>

      <h5>Left Icon</h5>
      <span class="ui-input-icon-left">
        <i class="pi pi-search" />
        <p:inputText placeholder="Search" />
      </span>

      <h5>Help Text</h5>
      <div class="field">
        <p:outputLabel styleClass="block">Username</p:outputLabel>
        <p:inputText id="username1" styleClass="block" />
        <small class="block">Enter your username to reset your password.</small>
      </div>

      <h5>Disabled</h5>
      <p:inputText disabled="true" />

      <h5>Image-Examples</h5>
      <div class="card">
        <p:graphicImage name="images/nature/nature4.jpg" library="demo" />
      </div>
    </div>
  </ui:define>
</ui:composition>

In this example it is:

  1. Missing for-attribute on outputlabel
  2. Missing id-attributes on inputText
  3. Missing alt-attribute on grphicImage

In XPath rule template for HTML I have posted a more general approach (using xpath) but maybe just providing this special template rule, would be enough.

Thank you for having a look on that.

Best regards,

Andreas

Looks like there is a rule for that:

Web:RequiredAttributeCheck - Track lack of required attributes

However, it’s not a template rule, which means you can only define it once, and the configuration is far less specific.
In contrast, Web:IllegalAttributeCheck is a template rule, so you can create multiple specialized rules with different explanations and severities.

Would it be possible to define an additional template-rule for that?

1 Like

Hi @aigel,

We have created a new template version of this rule - Add RequiredAttributeTemplateCheck as a new template rule by zglicz · Pull Request #605 · SonarSource/sonar-html · GitHub

It will be available with the next sonar-html release.

Kind regards,

Michal

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.