Skip to content

Add RequiredAttributeTemplateCheck as a new template rule#605

Merged
zglicz merged 5 commits intomasterfrom
feature/required-attribute-check-template
Mar 13, 2026
Merged

Add RequiredAttributeTemplateCheck as a new template rule#605
zglicz merged 5 commits intomasterfrom
feature/required-attribute-check-template

Conversation

@zglicz
Copy link
Contributor

@zglicz zglicz commented Mar 11, 2026

Summary

  • Adds a new RequiredAttributeTemplateCheck template rule — users can create custom instances with their own tag.attribute configurations
  • Leaves the existing RequiredAttributeCheck untouched so existing users are not affected
  • Instantiates the new template in ruling tests with img.alt as a concrete example (Template_RequiredImgAlt)

Note: the ruling expected file Web-Template_RequiredImgAlt.json is currently empty and will need to be updated with actual results after running the ITs.

Fixes https://community.sonarsource.com/t/track-missing-expected-attributes/179339

🤖 Generated with Claude Code

@zglicz zglicz requested a review from a team March 11, 2026 10:22
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title Make RequiredAttributeCheck a template rule SONARHTML-362 Make RequiredAttributeCheck a template rule Mar 11, 2026
@hashicorp-vault-sonar-prod
Copy link

hashicorp-vault-sonar-prod bot commented Mar 11, 2026

SONARHTML-362

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

Ruling Report

The following ruling changes are in this PR:

Rule: Web-Template_RequiredInputType

🔼 New issues flagged (47 issues)

Silverpeas-Core-master/war-core/src/main/webapp/admin/jsp/DomainsBarSilverpeasV5.jsp:285

   280 | <div id="redExp"><a href="javascript:resizeFrame();"><img src="icons/silverpeasV5/reduct.gif" border="0" name="expandReduce" alt="<fmt:message key="lookSilverpeasV5.reductExtend" />" title="<fmt:message key="lookSilverpeasV5.reductExtend" />"/></a></div>
   281 | <div id="domainsBar">
   282 |   <div id="recherche">
   283 |     <div id="submitRecherche">
   284 |       <form name="searchForm" action="<%=m_sContext%>/RpdcSearch/jsp/AdvancedSearch" method="post" target="MyMain">
>  285 |       <input name="query" size="30" id="query"/>
   286 |       <input type="hidden" name="mode" value="clear"/>
   287 |       <a href="javascript:searchEngine()"><img src="icons/silverpeasV5/px.gif" width="20" height="20" border="0" alt=""/></a>
   288 |       </form>
   289 |     </div>
   290 |         <div id="bodyRecherche">

custom/S6843.html:1

>    1 | <input role="img" />
     2 | <input type="img" role="img" />
     3 | <input type="checkbox" role="img" />

external_webkit-jb-mr1/Source/WebCore/manual-tests/autofill-popup-location.html:18

    13 |       <li> Press 'a' and make sure 'Always show bookmarks bar' is shown in autofill popup window.</li>
    14 |       <li> Select all with pressing Ctrl-a.</li>
    15 |       <li> Press 't' and make sure 'Test' is shown and the popup window location is correct.</li>
    16 |     </ol>
    17 |     <br>
>   18 |     <form><input name=q autofocus></form>
    19 |   </body>
    20 | </html> 

external_webkit-jb-mr1/Source/WebCore/manual-tests/chromium/suggestions-popup-font-change.html:18

    13 |       <li>3. Delete contents of input box, press Cntrl/+ [Command/+ on Mac]
    14 |   to magnify the page contents. Repeat step 2, text size should still
    15 |   match. </li>
    16 |     </ul>
    17 |     <form method="get" action="suggestions-popup-font-change.html" id="form">
>   18 |       <input name="s" id="s" style="font-size:x-large">
    19 |     </form>
    20 | </body>
    21 | </html>

external_webkit-jb-mr1/Source/WebCore/manual-tests/drag-caret.html:2

     1 | <p>This tests dragging over an input element, to make sure no drag-cursor is left behind.</p>
>    2 | <p><input></p>
     3 | <p>Drag some text over the input element and make sure the Drag Caret disappears when the drag exits the input element. Per https://bugs.webkit.org/show_bug.cgi?id=26787</p>

external_webkit-jb-mr1/Source/WebCore/manual-tests/drop-text-acquires-style.html:8

     3 | <title>Dragging plain text into a styled region</title> 
     4 | </head> 
     5 | <body>
     6 | <p>This test ensures the plain text dropped into a styled text region will acquire the appropriate style</p>
     7 | <p>To run this test, drag the text in the input element below into the bold text region.  The dropped text should be bold.</p>
>    8 | <input id="dragme" value="Drag this text" ><br />
     9 | <b contenteditable="true" id="target">Drag the text from the above input element into this bold text</b>
    10 | </body>
    11 | </html>

external_webkit-jb-mr1/Source/WebCore/manual-tests/find-count-matches-after-text-control.html:14

     9 |     </ol>
    10 | </p>
    11 | <p>
    12 |     The test passes if the Find banner says &ldquo;3 matches&rdquo;.
    13 | </p>
>   14 | <input value="a lemon in a text field"> and another lemon.

external_webkit-jb-mr1/Source/WebCore/manual-tests/focusringcolor-change-on-theme-change.html:1

>    1 | <input value="Click on me!  Focus ring color around this input element should change." style="width:100%">
     2 | <ul>
     3 | <li>Select the input element above.</li>
     4 | <li>Change the system focus ring color.<br>On OS X you can do this by going to System Preferences-&gt;Appearance and selecting another value in the Appearance popup menu.</li>  
     5 | <li>Make Safari the active application again.</li>
     6 | </ul>

external_webkit-jb-mr1/Source/WebCore/manual-tests/input-empty-on-focus.html:2

     1 | <div><img width="200" height="200" src="resources/200x200.png"></div>
>    2 | <div><input onfocus="this.value = ''" value="drop image here go boom"></div>
     3 | <p>Drag the image above down into the text field.
     4 | If the test succeeds there will be no crash and you'll end up with an empty text field with a blinking caret.
     5 | It's arguably a bug that the text field accepts an image at all, so some day we might fix that and make this
     6 | test obsolete. Maybe we can find some other way to test the same code path.</p>

external_webkit-jb-mr1/Source/WebCore/manual-tests/input-type-file-autocomplete-frame-2.html:4

     1 | <html>
     2 | <body>
     3 | <table><tr><td>
>    4 | <form><input size=55 value="type something in here"></form>
     5 | </td></tr></table>
     6 | </body>
     7 | </html>

...and 37 more (see ruling JSON files for full list)

Rule: Web-Template_RequiredScriptType

🔼 New issues flagged (2642 issues)

Silverpeas-Core-master/war-core/src/main/webapp/SILVERMAIL/jsp/readMessage.jsp:58

    53 |     <title>___/ Silverpeas - Corporate Portal Organizer
    54 |       \________________________________________________________________________</title>
    55 |       <view:looknfeel />
    56 |     <script type="text/javascript" src="<c:url value="/util/javaScript/animation.js"/>"></script>
    57 | 
>   58 |     <script>
    59 |       function deleteMessage( pID )
    60 |       {
    61 |         window.opener.location = "DeleteMessage.jsp?ID=" + pID + "&SpaceId=<c:out value="${param.SpaceId}"/>&from=<c:out value="${from}"/>";
    62 |         window.close();
    63 |       }

Silverpeas-Core-master/war-core/src/main/webapp/SILVERMAIL/jsp/redirect.jsp:39

    34 | 
    35 | <%@ page import="com.stratelia.silverpeas.peasCore.URLManager"%>
    36 | 
    37 | <html>
    38 | <head>
>   39 | <script>
    40 | window.location.href = "<%=URLManager.getApplicationURL()%>/dt?SpaceId=<%=request.getParameter("SpaceId")%>";
    41 | </script>
    42 | </head>
    43 | <body>
    44 | </body>

Silverpeas-Core-master/war-core/src/main/webapp/admin/jsp/goBack.jsp:35

    30 | <%@ include file="import.jsp" %>
    31 | 
    32 | <HTML>
    33 | <HEAD>
    34 | <TITLE></TITLE>
>   35 | <script language='Javascript'>
    36 | function forwardToComponent()
    37 | {
    38 |     <% 
    39 |         String component = (String)request.getParameter("component");
    40 |         String space = (String)request.getParameter("space");

Silverpeas-Core-master/war-core/src/main/webapp/admin/jsp/importFrameSet.jsp:73

    68 |   ResourceLocator message = null;
    69 |   ResourceLocator homePageSettings = null;
    70 |   String m_sContext = null;
    71 |   if (m_MainSessionCtrl == null) {
    72 | %>
>   73 | <script>
    74 |   top.location = "../../Login.jsp";
    75 | </script>
    76 | <%  } else {
    77 |     organizationCtrl = m_MainSessionCtrl.getOrganisationController();
    78 |     gef = (GraphicElementFactory) session.getAttribute(GraphicElementFactory.GE_FACTORY_SESSION_ATT);

Silverpeas-Core-master/war-core/src/main/webapp/admin/jsp/popupError.jsp:168

   163 | 	<tr>
   164 | 		<td class="intfdcolor4" nowrap="nowrap">
   165 | 			<center>
   166 | 				<br/>
   167 | 				<span class="txtnav">
>  168 | 				<script language="JavaScript">
   169 | 					window.document.write(window.opener.document.formulaire.message.value);
   170 | 				</script>
   171 | 				</span>
   172 | 			</center>
   173 | 			<br/>

Silverpeas-Core-master/war-core/src/main/webapp/alertUserPeas/jsp/close.jsp:31

    26 | 
    27 | <%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    28 | 
    29 | <%@ include file="check.jsp" %>
    30 | 
>   31 | <SCRIPT LANGUAGE="JavaScript">
    32 | <!--
    33 | 	self.close();
    34 | //-->
    35 | </SCRIPT>

Silverpeas-Core-master/war-core/src/main/webapp/alertUserPeas/jsp/writeMessage.jsp:49

    44 |     <%
    45 |           out.println(gef.getLookStyleSheet());
    46 |     %>
    47 |     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    48 | 
>   49 |     <script language="JavaScript">
    50 |       function validateUsers() {
    51 |         document.EDform.submit();
    52 |       }
    53 |     </script>
    54 |   </head>

Silverpeas-Core-master/war-core/src/main/webapp/applicationIndexer/jsp/didYouMeanIndexer.jsp:158

   153 | <head>
   154 | <title>Navigation</title>
   155 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   156 | <!--link rel="stylesheet" href="styleSheets/admin.css"-->
   157 | <% out.println(gef.getLookStyleSheet()); %>
>  158 | <script language="JavaScript">
   159 | function index(action, compo, space)
   160 | {
   161 | 	var message = "Vous êtes sur le point de recréer un index pour la fonctionnalité \"voulez vous dire ?\" pour   ";
   162 | 	if (action == "Index")
   163 | 	{

Silverpeas-Core-master/war-core/src/main/webapp/clipboard/jsp/Idle.jsp:72

    67 | %>
    68 | 
    69 | <html>
    70 | <HEAD>
    71 | <script type="text/javascript" src="<%=m_context%>/util/javaScript/animation.js"></script>
>   72 | <Script language="JavaScript">
    73 | var counter = 0;
    74 | <%
    75 |    if (clipboardSC != null) {
    76 |         out.println("var interval = " + clipboardSC.getIntervalInSec() + ";");
    77 |    }

Silverpeas-Core-master/war-core/src/main/webapp/clipboard/jsp/PasteError.jsp:47

    42 | 
    43 | <%@ include file="checkClipboard.jsp.inc" %>
    44 | 
    45 | <html>
    46 | <HEAD>
>   47 | <Script language="JavaScript">
    48 | 
    49 | var counter = 0;
    50 | var interval = 5; //secondes
    51 | // call Update function in 1 second after first load
    52 | ID = window.setTimeout ("DoIdle();", interval * 1000);

...and 2632 more (see ruling JSON files for full list)


Ruling tests passed.

@zglicz zglicz force-pushed the feature/required-attribute-check-template branch from b6541af to 8f9eba9 Compare March 11, 2026 10:29
Copy link
Contributor

@vdiez vdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by doing this you are effectively removing the rule. I think we cannot spot it because ruling does not have expected issues for RequiredAttributeCheck. Double check adding issues on ruling for this rule, I expect nothing will be raised. Have a look that for ruling we instantiate a template if we want the rule enabled:

instantiateTemplateRule("IllegalAttributeCheck", "Template_DoNotUseNameProperty", "attributes=\"name\"");

I would suggest to create a new rule for this, so we don't affect existing users

@zglicz zglicz changed the title SONARHTML-362 Make RequiredAttributeCheck a template rule Add RequiredAttributeTemplateCheck as a new template rule Mar 11, 2026
@zglicz zglicz marked this pull request as draft March 11, 2026 14:09
zglicz and others added 5 commits March 12, 2026 11:49
Allows users to create custom instances of RequiredAttributeCheck
with their own attribute/element configurations, consistent with
how IllegalAttributeCheck already works.

Fixes https://community.sonarsource.com/t/track-missing-expected-attributes/179339

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Adds a new template rule that allows users to create custom instances
checking for required attributes on specific HTML elements, without
affecting the existing RequiredAttributeCheck rule and its users.

Also instantiates the template in ruling tests with img.alt as an example.

Fixes https://community.sonarsource.com/t/track-missing-expected-attributes/179339

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Aligns with the RSPEC convention of using S-numbers for new rules.
Renames resource files from RequiredAttributeTemplateCheck to S8488
and updates all references accordingly.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@zglicz zglicz force-pushed the feature/required-attribute-check-template branch from 6ccc9c3 to fb3d3b1 Compare March 12, 2026 13:39
@sonarqube-next
Copy link

@zglicz zglicz marked this pull request as ready for review March 12, 2026 13:54
@zglicz zglicz requested review from a team and vdiez March 12, 2026 13:54
@zglicz zglicz merged commit 3d94d37 into master Mar 13, 2026
11 checks passed
@zglicz zglicz deleted the feature/required-attribute-check-template branch March 13, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants