Validate XDoc Violation Examples

11 views
Skip to first unread message

R Veach

unread,
Apr 14, 2017, 8:38:12 AM4/14/17
to checkstyle-devel
While I was writing up https://github.com/checkstyle/checkstyle/issues/4216 , I started thinking of ways we can automate this since we are adding more and more examples to our XDocs.

To run validation on an example, 90% of the time all we need are the source file (java) and the configuration file (xml). Taking http://checkstyle.sourceforge.net/config_coding.html#RequireThis as an example, we can see we have both and all our xdocs should follow similar patterns.

The first problem is connecting the configuration to the source.
Thanks to https://github.com/checkstyle/checkstyle/pull/3998 and sagar-shah94 , we know we can put extra attributes on sources without any conflict. We can put a hidden attribute on the configuration to give them a unique ID, and we can have the sources have another hidden attribute which which references the new configuration's ID.

With this, we now have combined the 2 and can validate them for violations.
We can expand this with custom JavaScript on the page, if we want to, so readers can get a hover over and redirect them from the source to the config so the connection is clear to them too.

The next problem is connecting violations from validation to violations comments in the source.
Since violations have line numbers, we can just do a regular expression match in the source on the violation line for the comment. We would also have to make sure we have no extra violations comments anywhere else. We should try to ensure there is only 1 violation per line so the comment can be made clear to the readers.
We may be doing something similar to this in the future with our test inputs after https://github.com/checkstyle/checkstyle/issues/3891 is finished and if we start isolating files between different @Tests since it makes reviewing easier to have the comments there.

Please comment and let me know what you think.
Reply all
Reply to author
Forward
0 new messages