当你看完这篇文章,咱们接下来就该学习怎么配置checkstyle
步骤:
1.https://github.com/android/platform_development/blob/master/ide/intellij/codestyles/AndroidStyle.xml
2.将AndroidStyle.xml复制到~/.AndroidStudio/config/codestyles/(C:\Users\Administrator.AndroidStudio1.5\config\codestyles)
如果没有codestyles就创建一个
3.在Settings(or Preferences in Mac OS X) > Code Style > Java, 选择AndroidStyle,同时CodeStyle > XML , 选择AndroidStyle.
4.重启androidstudio, 执行Analyze(菜单)–> InspectCode.
5.在这个时候你如果不小心在codestyles中加入了错误的的文件,androidstudio重启的时候会报错,这时删除~/.AndroidStudio/system/caches/(C:\Users\Administrator.AndroidStudio1.5\system\caches)中的所有文件,重启即可,附:这个问题折磨了我一天
6.接下来这篇博客会介绍如何使用checkstyle
更多参考文档:
http://www.thinksaas.cn/group/topic/349857/
http://www.cnblogs.com/liugang/archive/2010/10/26/1860903.html
http://www.cnblogs.com/qianxudetianxia/archive/2012/01/01/2309102.html
gradle 配置checkStyle:
http://blog.csdn.net/forlong401/article/details/42077013
http://gradle.org/docs/current/dsl/org.gradle.api.plugins.quality.Checkstyle.html
下面附送一个中英对照
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<!--
Checkstyle configuration that checks the sun coding conventions from:
- the Java Language Specification at
http://java.sun.com/docs/books/jls/second_edition/html/index.html
- the Sun Code Conventions at http://java.sun.com/docs/codeconv/
- the Javadoc guidelines at
http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
- the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
- some best practices
Checkstyle is very configurable. Be sure to read the documentation at
http://checkstyle.sf.net (or in your downloaded distribution).
Most Checks are configurable, be sure to consult the documentation.
To completely disable a check, just comment it out or delete it from the file.
Finally, it is worth reading the documentation.
-->
<module name="Checker">
<property name="severity" value="warning"/>
<!--
If you set the basedir property below, then all reported file
names will be relative to the specified directory. See
http://checkstyle.sourceforge.net/5.x/config.html#Checker
<property name="basedir" value="${basedir}"/>
-->
<!-- Checks that a package-info.java file exists for each package. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
<module name="JavadocPackage"/>
<!-- Checks whether files end with a new line. -->
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile
-->
<!-- 检查文件是否以一个新行结束-->
<module name="NewlineAtEndOfFile"/>
<!-- Checks that property files contain the same keys. -->
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
<!-- 检查**.properties配置文件 是否有没有设值的key-->
<module name="Translation"/>
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<!-- 检查文件的长度 default max=2000 -->
<module name="FileLength"/>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<!-- 检查文件中是否含有'\t'-->
<module name="FileTabCharacter"/>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<!-- 不知道作用 -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
</module>
<module name="TreeWalker">
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<!-- Checks the Javadoc of a method or constructor. By default, does not check for unused throws. To allow documented java.lang.RuntimeExceptions that are not declared, set property allowUndeclaredRTE to true. The scope to verify is spec