AndroidLintPlus:定制Lint规则,程序员何苦为难程序员!

来源:互联网 发布:阿里云域名解析记录值 编辑:程序博客网 时间:2024/04/27 13:30

扩展Lint 规则

1、JavaChineseStringDetector:检查 java 代码中的中文字符串,有些团队的开发规范里规定中文字符串必须放到 string.xml里。

2、LayoutFileNameDetector:检查布局文件的文件名,你可以在这个类里定义一套自己团队的命名规范的正则表达式。强制整个团队的命名统一。

3、ViewIdDetector:检查布局文件里 view 的 id,同上上一条,你也可以定义一套自己的正则。

4、用法见下文,顺便提一下你可以把定制后的 lint task加到 build 过程里来强制规范代码,如果 lint 失败则 build 失败。你还可以集成到AndroidCodeQuality
使用checkstyle,pmd,findbug共同提高代码质量。

【Github源码地址,欢迎Star和Follow】

最后一句:程序员何苦为难程序员呢

Feature

1.JavaChineseStringDetector:check chinese string in java file.

2.LayoutFileNameDetector:check xml file name in layout folder.

3.ViewIdDetector:check view id name in layout xml file.

4.custom your own rule in JavaChineseStringDetector.java,LayoutFileNameDetector.java,ViewIdDetector.java

Usage

1.go to the module ‘library_java’ and run ‘../gradlew clean install’

2.config which Detector to use

android {    ...    lintOptions {        abortOnError true        textReport true        //checkAllWarnings true        check 'ViewId','JavaChineseString','LayoutFileName'    }}

3.run ‘./gradlew lint’ at project root

4.you can config this to the build task,when the check rule error,stop build task. you can integrate this into AndroidCodeQuality

To go further

This project is based on these two other projects, which are awesome. Consider take a look at them :
- custom-lint-rules.
- linette.

0 0