Skip to content

Commit

Permalink
Add detekt & ktlint support. Closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
skywall committed Nov 8, 2018
1 parent 3e5eead commit 3e0355c
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*.{kt,kts}]

max_line_length=130
indent_size=4
continuation_indent_size=4
35 changes: 35 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
is_pr_big = git.lines_of_code > 500
#has_correct_prefix = github.branch_for_head.match(/^(feature|hotfix|fix|release|housekeep)\//)

#warn("Branch name should have `release/`, `hotfix/`, `fix/`, `housekeep/` or `feature/` prefix.") if !has_correct_prefix
#warn("Pull request is classed as Work in Progress") if is_pr_wip
#warn("This pull request is too big.") if is_pr_big

commit_lint.check warn: :all, disable: [:subject_length]

# Utils
def report_checkstyle_for_directory(directory_name)
if Dir.exists?(directory_name)
Dir.glob(directory_name).each {|f|
report_checkstyle(directory_name + f)
}
end
end

def report_checkstyle(file_name)
if File.file?(file_name)
checkstyle_format.report file_name
end
end

# Setup checkstyle
checkstyle_format.base_path = Dir.pwd

# Detekt checkstyle
report_checkstyle 'build/reports/detekt/detekt.xml'

# Original checkstyle
report_checkstyle 'app/build/reports/checkstyle/checkstyle.xml'

# Ktlint checkstyle
report_checkstyle_for_directory 'app/build/reports/ktlint/'
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'danger-checkstyle_format'
20 changes: 20 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ buildscript {
}
}

plugins {
id "io.gitlab.arturbosch.detekt" version '1.0.0-RC10'
id "org.jlleitschuh.gradle.ktlint" version "3.0.1"
}

ext {
support_lib = '1.0.0-rc01'
arch_components = '2.0.0-rc01'
Expand All @@ -24,6 +29,21 @@ allprojects {
}
}

detekt {
version = '1.0.0-RC10'
input = files("app/src/main/java", "mvvm/src/main/java")
filters = ".*/resources/.*,.*/build/.*"
config = files("detekt.yml")
}

ktlint {
version = "0.29.0"
ignoreFailures = true
android = true
outputToConsole = true
reporters = ["CHECKSTYLE"]
}

task clean(type: Delete) {
delete rootProject.buildDir
}
256 changes: 256 additions & 0 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
autoCorrect: false

build:
maxIssues: 100

complexity:
active: true
ComplexCondition:
active: true
ComplexMethod:
active: true
threshold: 20
LargeClass:
threshold: 250
active: true
TooManyFunctions:
active: true
thresholdInFiles: 30
thresholdInClasses: 30
thresholdInInterfaces: 30
thresholdInObjects: 25
LongParameterList:
active: true
NestedBlockDepth:
active: true
threshold: 4
StringLiteralDuplication:
active: true

empty-blocks:
active: true
EmptyCatchBlock:
active: true
EmptyClassBlock:
active: true
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

exceptions:
active: true
ExceptionRaisedInUnexpectedLocation:
active: true
InstanceOfCheckForException:
active: true
ReturnFromFinally:
active: true
TooGenericExceptionCaught:
active: false
SwallowedException:
active: true
ThrowingExceptionFromFinally:
active: true
ThrowingExceptionsWithoutMessageOrCause:
active: true
ThrowingNewInstanceOfSameException:
active: true
TooGenericExceptionThrown:
active: true

formatting:
active: false

code-smell:
active: true

naming:
ClassNaming:
active: true
ConstructorParameterNaming:
active: true
EnumNaming:
active: true
ForbiddenClassName:
active: true
FunctionMaxLength:
active: true
maximumFunctionNameLength: 30
FunctionMinLength:
active: true
FunctionNaming:
active: true
FunctionParameterNaming:
active: true
MatchingDeclarationName:
active: true
MemberNameEqualsClassName:
active: true
ObjectPropertyNaming:
active: true
PackageNaming:
active: true
TopLevelPropertyNaming:
active: true
VariableMaxLength:
active: true
VariableMinLength:
active: true
VariableNaming:
active: true

performance:
ArrayPrimitive:
active: true
ForEachOnRange:
active: true
SpreadOperator:
active: true
UnnecessaryTemporaryInstantiation:
active: true

potential-bugs:
active: true
DuplicateCaseInWhenExpression:
active: true
EqualsAlwaysReturnsTrueOrFalse:
active: true
EqualsWithHashCodeExist:
active: true
ExplicitGarbageCollectionCall:
active: true
InvalidRange:
active: true
IteratorHasNextCallsNextMethod:
active: true
IteratorNotThrowingNoSuchElementException:
active: true
UnconditionalJumpStatementInLoop:
active: true
UnreachableCode:
active: true
UnsafeCallOnNullableType:
active: true
UnsafeCast:
active: true
UselessPostfixExpression:
active: true
WrongEqualsTypeParameter:
active: true

style:
active: true
MaxLineLength:
active: false
CollapsibleIfStatements:
active: true
DataClassContainsFunctions:
active: false
EqualsNullCall:
active: true
ExplicitItLambdaParameter:
active: true
ExpressionBodySyntax:
active: true
ForbiddenComment:
active: true
ForbiddenImport:
active: true
ForbiddenVoid:
active: true
FunctionMaxLength:
active: true
maximumFunctionNameLength: 50
FunctionOnlyReturningConstant:
active: true
LoopWithTooManyJumpStatements:
active: true
MagicNumber:
active: true
MandatoryBracesIfStatements:
active: true
MayBeConst:
active: true
ModifierOrder:
active: true
NestedClassesVisibility:
active: false
NewLineAtEndOfFile:
active: true
NoTabs:
active: true
OptionalAbstractKeyword:
active: true
OptionalUnit:
active: true
OptionalWhenBraces:
active: true
PreferToOverPairSyntax:
active: false
ProtectedMemberInFinalClass:
active: true
RedundantVisibilityModifierRule:
active: true
ReturnCount:
active: true
max: 4
SafeCast:
active: true
SerialVersionUIDInSerializableClass:
active: true
SpacingBetweenPackageAndImports:
active: true
ThrowsCount:
active: true
TrailingWhitespace:
active: true
UnnecessaryAbstractClass:
active: true
excludeAnnotatedClasses: "dagger.Module,android.arch.persistence.room.Dao"
UnnecessaryApply:
active: false # wait for fix
UnnecessaryInheritance:
active: true
UnnecessaryLet:
active: true
UnnecessaryParentheses:
active: true
UntilInsteadOfRangeTo:
active: true
UnusedImports:
active: false
UnusedPrivateMember:
active: true
UseDataClass:
active: true
UtilityClassWithPublicConstructor:
active: true
VarCouldBeVal:
active: true
VariableMaxLength:
active: true
maximumVariableNameLength: 50
WildcardImport:
active: true
excludeImports: 'kotlinx.android.synthetic.*'

0 comments on commit 3e0355c

Please sign in to comment.