Does someone know of a checkstyle plugin that can be configured with a set of words, and will mark all occurences of those words as warnings (in identifiers or in string values) ?
The project we're working on requires that all code is in english. But most people are not native speakers and they sometimes accidentally include non-english words in their code. We'd like to detect at least some of those mistakes and signal them.
Try this rule which checks for several non-English variants of "Cheers!", ignoring case:
<module name="Regexp">
<property name="format" value="(?i)(na zdrowie|kippis|a votre sante|prost)"/>
<property name="message" value="Use only English language"/>
<property name="illegalPattern" value="true"/>
</module>
Related
I have a project with several hundred packages. It's mostly generated code from a conversion from COBOL to inline java so the vast majority of it (~11,000 files) is something I do not want to run checkstyle on. I do have a couple packages in the project that are "real" java that I have added to replace utilities that could not be generated by the code conversion and I do want to run checkstyle on those.
I'm having trouble getting the suppression to work properly.
This is the relevant fragment from the checkstyle.xml:
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the Google coding conventions from Google Java Style
that can be found at https://google.github.io/styleguide/javaguide.html.
Checkstyle is very configurable. Be sure to read the documentation at
http://checkstyle.sf.net (or in your downloaded distribution).
To completely disable a check, just comment it out or delete it from the file.
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
-->
<module name = "Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="SuppressionFilter">
<property name="file" value="${config_loc}/checkstyleSuppress.xml"/>
<property name="optional" value="false"/>
</module>
<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format"
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message"
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true"/>
<propert ...
I'm confident that the checkstyleSuppress.xml file is getting read because checkstyle will error out if I add a character to the file name to make it wrong.
The content of checkstyleSuppress.xml is as follows:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress files="[/\\].+" checks=".*"/>
<suppress checks=".*" files="app[\\/]dbio[\\/].java"/>
<suppress checks=".*" files="app[\\/]dbio[\\/]internal[\\/].java"/>
<suppress checks=".*" files="app[\\/]f17*[\\/].java"/>
<suppress checks=".*" files="app[\\/]f17*[\\/]internal[\\/].java"/>
</suppressions>
What I'm trying to do is suppress all checks for anything in the app.dbio and app.f17* packages. To see if my rules are running I added the first line in the file which I thought would suppress all checks on all files.
None of these filters are suppressing anything. Checkstyle checks all files in all packages (and reports over 400,000 violations, which is a bit too many to wade through for the ones I care about! lol)
Most projects are ground up, so I have previously used checkstyle with no suppression. This is my first attempt to limit the scope of the code review and it's not going as I had hoped. I'm not sure where my issue lies here.
Any suggestions are much appreciated.
I think BeforeExecutionExclusionFileFilter is the thing you are looking for. You can provide regexp(s) which matches packages you want to exclude, they will not be checked.
there,
I hope I choosed the right Forum category...
I've uploaded a windows 10 app to the windows store. I've seen that under supported languages is just german, but in my Package.appxmanifest I have
<Resources>
<Resource Language="de-DE" />
<Resource Language="en-US" />
</Resources>
In the Partner-Dashboard I have also german and english in my store entrys..
Thanks for your help!
Chris
The Store listing on dashboard contains two language lists: Languages supported by your packages and Additional Store listing Languages.The Language supported list of the app in the Store is the same as the Languages supported by your packages list in dashboard.
The language shown in the Languages supported by your packages list is the language your package supported. If your project supports multiple languages,not only will you need to add languages in the Package.appxmanifest file (as shown in the code you listed) ,you will also need to add a.resw file for each language in the project.
In your Resource Language list, the first language 'de-DE' is the default language for your project.For more information about this, please see : App manifest language list
After several days of trying to solve this problem, with the help of the Unity people I finally found the answer:
Text edit the Package.appxmanifest file and change from
<Resources>
<Resource Language="x-generate" />
</Resources>
To the languages your game supports.
<Resources>
<Resource Language="en-us" />
<Resource Language="fr" />
<Resource Language="de" />
<Resource Language="nl" />
<Resource Language="pt-br" />
<Resource Language="ja" />
</Resources>
Then edit the vcxproj of your project and before the add this (using the same language codes from before) :
<AppxBundleAutoResourcePackageQualifiers>DXFeatureLevel</AppxBundleAutoResourcePackageQualifiers>
<AppxDefaultResourceQualifiers>Language=EN-US;FR;DE;JA;NL;PT-BR</AppxDefaultResourceQualifiers>
Okay, now just generate the build and send it to the store and all the languages your game supports will appear as expected. =)
Is there a way to check if the file is using LFs only and no CRLFs or vice versa in checkstyle?
The only check which I have found is
NewlineAtEndOfFile
But I search for more as only at the end of the file?
Only to supplement the Michal Kordas's good answer.
Below is a slightly modified configuration, which will only match the first wrong newline and forbid also the Mac OS Line Endings (CR):
<module name="RegexpMultiline">
<property name="format" value="(?s:(\r\n|\r).*)"/>
<property name="message" value="CRLF and CR line endings are prohibited, but this file uses them."/>
</module>
It has been posted by Michael Vorburger in this discussion, so kudos for him - I've posted it here for completeness.
There is nothing out-of-the box in Checkstyle yet. If you want to prohibit CRLF you can use the following config:
<module name="RegexpMultiline">
<property name="format" value="\r\n"/>
<property name="message" value="CRLF line endings are prohibited"/>
</module>
and this one to ban LFs:
<module name="RegexpMultiline">
<property name="format" value="(?<!\r)\n"/>
<property name="message" value="LF line endings are prohibited"/>
</module>
I have written a new checkstyle check as a filescanner. I modeled my junits after the code I found in the checkstyle code. The junits run just fine and everything looks good.
But then, I add the check to my project.
<module name="TreeWalker">
<property name="tabWidth" value="4" />
<module name="com.onuspride.codetools.checkstyles.DuplicateClassNames"/>
</module>
and my ant task
<taskdef resource="checkstyletask.properties">
<classpath refid="classpath" />
</taskdef>
<property name="checkstyle.suppressions.file" value="checkstyle/suppressions.xml" />
<property name="translation.severity" value="error" />
<target name="checkStyle" description="TestTask to evaluate the checkstyle system.">
<checkstyle config="checkstyle/checkstyle_checks.xml">
<fileset dir="${msg.src}" includes="**/*.java" />
<formatter type="plain" />
<formatter type="xml" toFile="${msg.build.jar}/checkstyle_errors.xml" />
<classpath refid="classpath" />
</checkstyle>
</target>
the duplicateclassnames class calls several classes in the same jar. For some reason, when ant runs it, ant finds the check class, but can't find the supporting classes, when they are all in the same jar file. here's what i get in ant
[checkstyle] [class]:0: Got an exception - java.lang.NoClassDefFoundError: com/onuspride/codetools/common/classpath/criteria/ClassNameCriteriaCollector
Im stumped. Ive checkd all the dependencies of my jar, they are all in the classpath, I don't understand how it can find one class file but not another in the same jar. Ive done all my dirty little tricks and I just don't get it.
any ideas?
You can do it like following :
Create plugin project and add your custom checks there.
Make appropriate changes to plugin.xml, checkstyle_packages.xml.
Export the project as Deployable Plug-ins and fragments (Export > Plug-in Developement)
Copy the jar file to Eclipse Plugin folde, so no need to install your custom check .
You can go through this tutorial for reference
To reduce effort, download a Sample Check, the file is here under the name net.sf.eclipsecs.sample
Just replace your source in src folder. Before replacing, refer this 3 files in src/net/sf/eclipsecs/sample/checks/ directory as you will need them in your com/onuspride/codetools/checkstyles/ directory :
checkstyle-metadata.properties
checkstyle-metadata.xml
messages.properties
After replacing the code, make appropriate changes in checkstyle_packages.xml file in src/ directory.
Extending Check is described nicely there.
Is there a way to factor out and parameterize repeating parts of Logback XML configuration? I have many different rolling file appenders configured basically the same except for the file names. I use that in conjunction with a bunch of loggers with their 'additivity' turned off so I can redirect different parts of the stack to different files. This adds up to a cumbersome and long configuration file composed of many almost identical segments.
I've used Logback's <include> feature before, but it doesn't address this reuse issue since I can't parameterize the included configuration. I'd expect such a feature to look something akin to:
<include resource="file-appender.xml">
<property name="filePath" value="/where/logs/go" />
<property name="baseLogger" value="com.mycompany.thatpartofthestack" />
</include>
But as far as I understand that's wishful thinking. Is there another way of factoring out Logback's configuration via templates, macros, functions or whatnot?
Try using variable substitution in local and/or context scope.
Perhaps the easiest way is to define variables in some resource file, say logback.properties bundled with each each application. Moreover, each application would carry a logback.xml file importing logback.properties.
<configuration debug="true">
<property resource="logback.properties" />
<!-- set root level as given by the value of the root.level variable -->
<!-- if root.level is undefined default to DEBUG -->
<root level="${root.level:-DEBUG}"/>
</configuration>
If you wish to set the root level to WARN in webapp-A, simply add the following line in logback.properties file bundled with webapp-A.
root.level=WARN
You can bundle logback.xml as a resource in a artifact common to your various applications.