rspec/rules/S3373/xml/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

84 lines
2.5 KiB
Plaintext

== Why is this an issue?
It makes sense to handle all related actions in the same place. Thus, the same ``++<action>++`` might logically handle all facets of CRUD on an entity, with no confusion in the naming about which ``++<forward/>++`` handles which facet. But go very far beyond that, and it becomes difficult to maintain a transparent naming convention.
So to ease maintenance, this rule raises an issue when an ``++<action>++`` has more than the allowed number of ``++<forward/>++`` tags.
=== Noncompliant code example
With the default threshold of 4:
[source,xml]
----
<action path='/book' type='myapp.BookDispatchAction' name='form' parameter='method'>
<forward name='create' path='/WEB-INF/jsp/BookCreate.jspx' redirect='false'/>
<forward name='read' path='/WEB-INF/jsp/BookDetails' redirect='false'/>
<forward name='update' path='/WEB-INF/jsp/BookUpdate.jspx' redirect='false'/>
<forward name='delete' path='/WEB-INF/jsp/BookDelete.jspx' redirect='false'/>
<forward name='authorRead' path='WEB-INF/jsp/AuthorDetails' redirect='false'/> <!-- Noncompliant -->
</action>
----
=== Compliant solution
[source,xml]
----
<action path='/book' type='myapp.BookDispatchAction' name='bookForm' parameter='method'>
<forward name='create' path='/WEB-INF/jsp/BookCreate.jspx' redirect='false'/>
<forward name='read' path='/WEB-INF/jsp/BookDetails' redirect='false'/>
<forward name='update' path='/WEB-INF/jsp/BookUpdate.jspx' redirect='false'/>
<forward name='delete' path='/WEB-INF/jsp/BookDelete.jspx' redirect='false'/>
</action>
<action path='/author' type='myapp.AuthorDispatchAction' name='authorForm' parameter='method'>
<forward name='authorRead' path='WEB-INF/jsp/AuthorDetails' redirect='false'/>
</action>
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Reduce the number of forwards in this action from m to at most n.
=== Parameters
.threshold
****
----
4
----
Maximum allowed number of "<forward/>" mappings in an "<action>".
****
=== Highlighting
* primary: ``++<action>++`` tag
* secondary: n+ ``++<forward/>++`` tags
** message: Move this forward to another action.
'''
== Comments And Links
(visible only on this page)
=== on 12 Oct 2015, 14:39:44 Ann Campbell wrote:
relates to ``++struts-config.xml++``.
I was very tempted to add ``++struts-config.xml++`` or ``++xml-config++`` or something similar as an implementation detail, but refrained.
endif::env-github,rspecator-view[]