How to automatically find I18N Violations

257 Views Asked by At

Is there anyway to automatically find I18N violations in a Grails project? For example,

<td valign="top" class="name"><label for="enabled">Enabled:</label></td>

should be flagged because it's not using <g:message> to get the label value.

It would be nice if codenarc had a rule for this, but I don't think it does.

1

There are 1 best solutions below

0
On

I have also looked for such a code quality test and have yet to find one.

Implementing this should be fairly trivial - if all text content in a GSP is required to be applied via tags, your GSP should consist entirely of element nodes and no text nodes.

This crux of the problem is predominantly an XML issue: how do you check a set of XML documents and flag those that contain text nodes?

Assuming you can import org.codehaus.groovy.grails.commons.GrailsResourceUtils in a codenarc rule you can use the VIEWS_DIR_PATH property to determine where all the GSP files live.

From there, the high level process you would need is:

  1. Build a collection of all the GSP files in the application
  2. For each file, load the content into an XML parser (Java has plenty) and check the node type for every node, flagging those files that contain text nodes

I appreciate that this is a very high level solution but conceptually it should work.