File encoding and code conventions are two orthogonal aspects of a source file. As such it is violating the principle "separation of concerns" that Checkstyle currently only allows to configure file encoding per check configuration. This potentially prevents reuse of config files among projects.
Consider some project that uses UTF-8 for its sources, another project that used Latin-1 and yet another that uses Big5. Even if all these projects were to enforce the the same code conventions, they would need separate Checkstyle configurations just for the sake of using the right charset. Keep in mind that using the default platform encoding is no option because the file encoding is conceptually specific to a project, not to a developer/machine/OS.
Especially for integration into build tools or IDEs, it would be helpful if Checkstyle offered a programmatic way to configure the file encoding to use for a particular invocation of the checker. The new setting should always override the property from the config file.
Right now, one has to post-process the loaded Configuration object by searching for the TreeWalker module and casting down to DefaultConfiguration in order to set the "charset" property. This just doesn't look like the right way.
Log in to post a comment.