Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Code Analysis #272

Open
nesquena opened this issue Apr 22, 2017 · 2 comments
Open

Static Code Analysis #272

nesquena opened this issue Apr 22, 2017 · 2 comments

Comments

@nesquena
Copy link
Member

nesquena commented Apr 22, 2017

  • Lint
  • Checkstyle
  • PMD
  • FindBugs
  • LeakCanary

APK

  • APK Analyzer
  • Android Profiler
  • Classy Shark
@Amejia481
Copy link

+1

@aemxn
Copy link

aemxn commented Apr 26, 2017

I can help with providing checkstyle config. Here is what I usually use:

  1. Create folders under /app called config/checkstyle/
  2. In checkstyle/, create an xml file called checkstyle.xml. (Note: there is also other config we can use. Refer here)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<!--
    This configuration file was written by the eclipse-cs plugin configuration editor
-->
<!--
    Checkstyle-Configuration: Android Checks (Eclipse)
    Description:
Slightly modified version of Sun Checks that better matches the default code formatter setting of Eclipse.
-->
<module name="Checker">
    <property name="severity" value="warning"/>
    <module name="TreeWalker">
        <property name="tabWidth" value="4"/>
        <module name="FileContentsHolder"/>
        <module name="JavadocMethod">
            <property name="suppressLoadErrors" value="true"/>
            <property name="severity" value="ignore"/>
        </module>
        <!--<module name="JavadocType"/>-->
        <!--<module name="JavadocVariable"/>-->
        <module name="JavadocStyle"/>
        <module name="ConstantName"/>
        <module name="LocalFinalVariableName"/>
        <module name="LocalVariableName"/>
        <module name="MemberName"/>
        <module name="MethodName"/>
        <module name="PackageName"/>
        <module name="ParameterName"/>
        <module name="StaticVariableName"/>
        <module name="TypeName"/>
        <!--<module name="AvoidStarImport"/>-->
        <module name="IllegalImport"/>
        <module name="RedundantImport"/>
        <module name="UnusedImports"/>
        <!--<module name="LineLength"/>-->
        <module name="MethodLength"/>
        <module name="ParameterNumber"/>
        <module name="EmptyForIteratorPad"/>
        <module name="MethodParamPad"/>
        <module name="NoWhitespaceAfter">
            <property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS"/>
        </module>
        <module name="NoWhitespaceBefore"/>
        <module name="OperatorWrap"/>
        <module name="ParenPad"/>
        <module name="TypecastParenPad"/>
        <module name="WhitespaceAfter"/>
        <module name="WhitespaceAround"/>
        <module name="ModifierOrder"/>
        <module name="RedundantModifier"/>
        <module name="AvoidNestedBlocks"/>
        <module name="EmptyBlock"/>
        <module name="LeftCurly"/>
        <module name="NeedBraces"/>
        <module name="RightCurly"/>
        <module name="AvoidInlineConditionals"/>
        <module name="EmptyStatement"/>
        <module name="EqualsHashCode"/>
        <module name="HiddenField"/>
        <module name="IllegalInstantiation"/>
        <module name="InnerAssignment"/>
        <module name="MagicNumber"/>
        <module name="MissingSwitchDefault"/>
        <module name="RedundantThrows">
            <property name="suppressLoadErrors" value="true"/>
        </module>
        <module name="SimplifyBooleanExpression"/>
        <module name="SimplifyBooleanReturn"/>
        <!--<module name="DesignForExtension"/>-->
        <module name="FinalClass"/>
        <module name="HideUtilityClassConstructor"/>
        <module name="InterfaceIsType"/>
        <module name="VisibilityModifier"/>
        <module name="ArrayTypeStyle"/>
        <!--<module name="FinalParameters"/>-->
        <module name="TodoComment">
            <property name="severity" value="ignore"/>
            <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
        </module>
        <module name="UpperEll"/>
        <module name="AnnotationUseStyle"/>
        <module name="MissingDeprecated"/>
        <module name="MissingOverride"/>
        <module name="PackageAnnotation"/>
        <module name="SuppressWarnings"/>
    </module>
    <!--<module name="JavadocPackage"/>-->
    <module name="NewlineAtEndOfFile">
        <property name="severity" value="ignore"/>
        <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
    </module>
    <module name="Translation"/>
    <module name="FileLength"/>
    <module name="FileTabCharacter"/>
    <module name="RegexpSingleline">
        <property name="severity" value="ignore"/>
        <property name="format" value="\s+$"/>
        <property name="message" value="Line has trailing spaces."/>
        <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
    </module>
    <module name="SuppressionCommentFilter"/>
    <module name="SuppressWithNearbyCommentFilter"/>
</module>
  1. In app's build.gradle file, need to apply plugin for this checkstyle file
apply plugin: 'checkstyle'
  1. Then we need to enable the checkstyle by using the following script. Paste this code at the bottom of the gradle file:
task checkstyle(type: Checkstyle) {
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    exclude '**/R.java'
    exclude '**/BuildConfig.java'

    def configProps = ['proj.module.dir': projectDir.absolutePath]
    configProperties configProps

    // empty classpath
    classpath = files()

    showViolations true

    reports {
        xml.enabled false
        html.enabled true
    }
}

preBuild.dependsOn('checkstyle')

Generated reports can be found at app/build/generated/reports/checkstyle. This will also going to be output in the logcat after building of the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants