Skip to content

Instantly share code, notes, and snippets.

@hernandazevedo
Created July 4, 2019 17:52
Show Gist options
  • Save hernandazevedo/03e0587b585685b01015a3e14315640e to your computer and use it in GitHub Desktop.
Save hernandazevedo/03e0587b585685b01015a3e14315640e to your computer and use it in GitHub Desktop.
static-analysis
apply from: "$project.rootDir/static-analysis/config.gradle"
configurations {
detekt
}
task detekt(type: JavaExec) {
main = "io.gitlab.arturbosch.detekt.cli.Main"
classpath = configurations.detekt
def input = "$projectDir"
def config = "$rulesDir/detekt.yml"
def filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
def params = [ '-i', input, '-c', config, '-f', filters]
args(params)
}
dependencies {
detekt 'io.gitlab.arturbosch.detekt:detekt-cli:1.0.0.RC6'
}
@hernandazevedo
Copy link
Author

hernandazevedo commented Jul 4, 2019

-- $project.rootDir/static-analysis/config.gradle
ext {
reportsDir = "$project.buildDir/reports"
rulesDir = "$project.rootDir/static-analysis/rules"
}

@hernandazevedo
Copy link
Author

hernandazevedo commented Jul 4, 2019

-- $project.rootDir/static-analysis/rules/detekt.yml
autoCorrect: true
failFast: false

test-pattern: # Configure exclusions for test sources
active: true
patterns: # Test file regexes
- './test/.'
- '.*Test.kt'
- '.*Spec.kt'
exclude-rule-sets:
- 'comments'
exclude-rules:
- 'NamingRules'
- 'WildcardImport'
- 'MagicNumber'
- 'MaxLineLength'
- 'LateinitUsage'
- 'StringLiteralDuplication'

build:
warningThreshold: 1
failThreshold: 1
weights:
complexity: 1
formatting: 1
LongParameterList: 1
comments: 1

processors:
active: true
exclude:

- 'FunctionCountProcessor'

- 'PropertyCountProcessor'

- 'ClassCountProcessor'

- 'PackageCountProcessor'

- 'KtFileCountProcessor'

console-reports:
active: true
exclude:

- 'ProjectStatisticsReport'

- 'ComplexityReport'

- 'NotificationReport'

- 'FindingsReport'

- 'BuildFailureReport'

output-reports:
active: true
exclude:

- 'PlainOutputReport'

- 'XmlOutputReport'

potential-bugs:
active: true
DuplicateCaseInWhenExpression:
active: true
EqualsAlwaysReturnsTrueOrFalse:
active: false
EqualsWithHashCodeExist:
active: true
InvalidLoopCondition:
active: false
WrongEqualsTypeParameter:
active: false
IteratorHasNextCallsNextMethod:
active: false
ExplicitGarbageCollectionCall:
active: true
UnconditionalJumpStatementInLoop:
active: false
IteratorNotThrowingNoSuchElementException:
active: false
UnreachableCode:
active: true
LateinitUsage:
active: false
excludeAnnotatedProperties: ''
ignoreOnClassesPattern: ''
UnsafeCallOnNullableType:
active: false
UnsafeCast:
active: false
UselessPostfixExpression:
active: false

performance:
active: true
ForEachOnRange:
active: true
SpreadOperator:
active: false
UnnecessaryTemporaryInstantiation:
active: true

exceptions:
active: true
ExceptionRaisedInUnexpectedLocation:
active: false
methodNames: 'toString,hashCode,equals,finalize'
SwallowedException:
active: false
TooGenericExceptionCaught:
active: true
exceptions:
- ArrayIndexOutOfBoundsException
- Error
- IllegalMonitorStateException
- IndexOutOfBoundsException
- InterruptedException
- NullPointerException
- RuntimeException

- Throwable

TooGenericExceptionThrown:
active: true
exceptions:
- Error
- Exception
- NullPointerException
- RuntimeException
- Throwable
InstanceOfCheckForException:
active: false
NotImplementedDeclaration:
active: false
ThrowingExceptionsWithoutMessageOrCause:
active: false
exceptions: 'IllegalArgumentException,IllegalStateException,IOException'
PrintStackTrace:
active: false
RethrowCaughtException:
active: false
ReturnFromFinally:
active: false
ThrowingExceptionFromFinally:
active: false
ThrowingExceptionInMain:
active: false
ThrowingNewInstanceOfSameException:
active: false

empty-blocks:
active: true
EmptyCatchBlock:
active: true
EmptyClassBlock:
active: false
EmptyDefaultConstructor:
active: true
EmptyDoWhileBlock:
active: true
EmptyElseBlock:
active: true
EmptyFinallyBlock:
active: true
EmptyForBlock:
active: true
EmptyFunctionBlock:
active: true
EmptyIfBlock:
active: true
EmptyInitBlock:
active: true
EmptyKtFile:
active: true
EmptySecondaryConstructor:
active: true
EmptyWhenBlock:
active: true
EmptyWhileBlock:
active: true

complexity:
active: true
LongMethod:
active: true
threshold: 20
NestedBlockDepth:
active: true
threshold: 3
LongParameterList:
active: true
threshold: 25
LargeClass:
active: true
threshold: 300
ComplexInterface:
active: false
threshold: 10
includeStaticDeclarations: false
ComplexMethod:
active: true
threshold: 30
MethodOverloading:
active: false
threshold: 5
TooManyFunctions:
active: false
thresholdInClasses: 30
thresholdInInterfaces: 30
thresholdInObjects: 30
thresholdInEnums: 30
ComplexCondition:
active: true
threshold: 5
LabeledExpression:
active: false
StringLiteralDuplication:
active: false
threshold: 2
ignoreAnnotation: true
excludeStringsWithLessThan5Characters: true
ignoreStringsRegex: '$^'

code-smell:
active: true
FeatureEnvy:
threshold: 0.5
weight: 0.45
base: 0.5

style:
active: true
ReturnCount:
active: true
max: 4
ThrowsCount:
active: true
max: 2
NewLineAtEndOfFile:
active: false
OptionalAbstractKeyword:
active: true
OptionalWhenBraces:
active: false
CollapsibleIfStatements:
active: false
EqualsNullCall:
active: false
ForbiddenComment:
active: true
values: 'TODO:,FIXME:,STOPSHIP:'
ForbiddenImport:
active: false
imports: ''
PackageDeclarationStyle:
active: false
LoopWithTooManyJumpStatements:
active: false
maxJumpCount: 1
MethodNameEqualsClassName:
active: false
ignoreOverriddenFunction: true
ModifierOrder:
active: true
MagicNumber:
active: true
ignoreNumbers: '-1,0,1,2'
ignoreHashCodeFunction: false
ignorePropertyDeclaration: false
ignoreConstantDeclaration: true
ignoreCompanionObjectPropertyDeclaration: true
ignoreAnnotation: false
ignoreNamedArgument: true
ignoreEnums: false
WildcardImport:
active: true
excludeImports: 'java.util.,kotlinx.android.synthetic.'
SafeCast:
active: true
MaxLineLength:
active: true
maxLineLength: 120
excludePackageStatements: true
excludeImportStatements: true
PackageNaming:
active: true
packagePattern: '^[a-z]+(.[a-z][a-z0-9])$'
ClassNaming:
active: true
classPattern: '[A-Z$][a-zA-Z0-9$]'
EnumNaming:
active: true
enumEntryPattern: '^[A-Z$][a-zA-Z_$]
$'
FunctionNaming:
active: true
functionPattern: '^([a-z$][a-zA-Z$0-9])|(.*)$'
FunctionMaxLength:
active: false
maximumFunctionNameLength: 30
FunctionMinLength:
active: false
minimumFunctionNameLength: 3
VariableNaming:
active: true
variablePattern: '^(_)?[a-z$][a-zA-Z$0-9]
$'
ConstantNaming:
active: true
constantPattern: '^([A-Z_]*|serialVersionUID)$'
VariableMaxLength:
active: false
maximumVariableNameLength: 30
VariableMinLength:
active: false
minimumVariableNameLength: 3
ForbiddenClassName:
active: false
forbiddenName: ''
ProtectedMemberInFinalClass:
active: false
SerialVersionUIDInSerializableClass:
active: false
UnnecessaryParentheses:
active: false
UnnecessaryInheritance:
active: false
UtilityClassWithPublicConstructor:
active: false
DataClassContainsFunctions:
active: false
conversionFunctionPrefix: 'to'
UseDataClass:
active: false
UnnecessaryAbstractClass:
active: false
OptionalUnit:
active: false
OptionalReturnKeyword:
active: false
ExpressionBodySyntax:
active: false
UnusedImports:
active: false
NestedClassesVisibility:
active: false
RedundantVisibilityModifierRule:
active: false
FunctionOnlyReturningConstant:
active: false
ignoreOverriddenFunction: true
excludedFunctions: 'describeContents'

comments:
active: true
CommentOverPrivateFunction:
active: true
CommentOverPrivateProperty:
active: true
UndocumentedPublicClass:
active: false
searchInNestedClass: true
searchInInnerClass: true
searchInInnerObject: true
searchInInnerInterface: true
UndocumentedPublicFunction:
active: false

experimental feature

Migration rules can be defined in the same config file or a new one

migration:
active: true
imports:
# your.package.Class: new.package.or.Class
# for example:
# io.gitlab.arturbosch.detekt.api.Rule: io.gitlab.arturbosch.detekt.rule.Rule
v

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