Giter Site home page Giter Site logo

customlintdemo's Introduction

CustomLintDemo

CustomLintDemo is a series of custom Lint rules specific implementation, designed to demonstrate the use of Lint API.

Detailed custom Lint implementation methods and principles, you can see the article:
Android Lint工作原理剖析
浅谈Android自定义Lint规则的实现 (一)
浅谈Android自定义Lint规则的实现 (二)

====== This demo program does Lint checking for the following issues:

[1]Don't use Log/Toast/Handler directly. Use LogUtil/ToastUtil/HandlerUtil instead.
[2]Prefix layout xml file of Activity/Fragment with "activity_"/""fragment_".
[3]Layout resource file in ViewHolder must be named with prefix "item_".
[4]In layout xml file, you should name an view item with specified prefix.
[5]In build.gradle file, version info should refer to gradle-wrapper.properties.
[6]Nested For/If/Try statements can not be more than 3 layers.
[7]A constant should be named with only UPPER CASE letter and underline.
[8]You should not call new Message() directly. Instead, you should use handler.obtainMessage or Message.Obtain().
[9]You should throw your own exception with the one caught in try-catch block.
[10]You should pass in a value or variable as a parameter, rather than passing in the operand and operator as parameters. For example, printName("Lucy") and printName(mName) is legal, while printName(mName1 + mName2) is NOT.

====== CustomLintDemo对Android Lint规则进行了扩展,在不影响Android Lint原有的检查项目的基础上,额外检查以下内容: 【1】不能直接使用log,toast,handler
【2】activity或fragment对应的layout资源,用前缀标示,例如:activity_mediapicker.xml
【3】viewholder关联的资源以item结尾
【4】xml布局文件中使用前缀表明类型,比如,btn_xxx
【5】build.gradle里面那个版本依赖,必须通过 gradle.properties文件中指定
【6】嵌套For/If/Try最大深度3
【7】常量的名称
【8】Message必须采用Message.Obtain获取
【9】throw异常的时候注意把已经捕获的异常也一并带上,例如:throw new ManagerException("数据库异常");应该改成throw new ManagerException("数据库异常",e)
【10】调用特定函数时应该直接传入值或单独的变量作为参数,而不是传入多个操作数和操作符作为变量。比如,printName("Lucy")和printName(mName)是合法的,而printName(mName1 + mName2)是不合法的。

====== 自定义Lint规则的2种检查方法:
1、目前最新版的Android Studio已经把一部分自定义Lint检查的功能集成到了IDE中,直接可见。

2、在终端运行"gradle lint"任务,得到完整Lint报告。

customlintdemo's People

Contributors

ljfxyj2008 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

customlintdemo's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.