jsfintellij-ideastructural-search

IntelliJ inspection to find tags without 'id' attribute


I need to setup an inspection in IntelliJ that will find xhtml/html/jsf page elements without an `id attribute.

<h:outputText value="myOutputValue"
                        styleClass="someStyle"/>
<h:outputText value="myOtherOutputValue" />

I tried setting up a code inspection in intelliJ under "Structural search". With the following regexp however I can't configure it properly. Any help would be appreciated.

<(?:h:inputText|h:outputText)(?:\s+(?!id\b)[\w\-.:]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[\w\-.:]+))?)*\s*/?>

I know the regexp works because it will find the occurrences in my file when entered into the find box.

One last thing, in the end I'll want to expand (?:h:inputText|h:outputText) to include numerous tags so if using variables in the inspection or something else in intelliJ then that solution would be best. We want to make sure all developers put id attributes on all applicable page elements to aide in testing ease. (JSF tags are hideous)


Solution

  • You can use a Structural Search pattern like the following:

    <$name$ $id$>
    

    Remember to set the correct file type. Click Edit Variables... and give $name$ the following constraints:
    Text/regexp: h:inputText|h:outputText

    Give $id$ the following constraints:
    Text/regexp: id
    Occurrences count: 0,0

    This will find all <h:inputText> and <h:outputText> tags without id attribute.