From 8b115dcb3aaff24b4d71926bde816df0cf8e927f Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Sat, 1 Feb 2020 18:14:00 -0300 Subject: [PATCH] implement detekt --- .gitignore | 2 + .travis.yml | 63 +++ .../main/java/com/hako/friendlists/Test.kt | 3 + build.gradle | 19 + tools/detekt.yml | 437 ++++++++++++++++++ versions.gradle | 2 +- 6 files changed, 525 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 app/src/main/java/com/hako/friendlists/Test.kt create mode 100644 tools/detekt.yml diff --git a/.gitignore b/.gitignore index 3bb4dbc..08558de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.DS_Store + # Built application files *.apk *.ap_ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a394074 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,63 @@ +branches: + only: + - master +language: android +jdk: oraclejdk8 +dist: trusty +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ + - $HOME/.android/build-cache +android: + components: + - tools + - platform-tools + - build-tools-29.0.3 + - android-29 + - sys-img-x86-android-26 + licenses: + - 'android-sdk-preview-license-52d11cd2' + - 'android-sdk-license-.+' + - 'google-gdk-license-.+' +if: "(branch = master AND type = push) OR (head_branch != master AND type = pull_request)" +before_install: + - git fetch origin head_branch + - export FILES_CHANGED="$(git --no-pager diff --name-only --diff-filter AM FETCH_HEAD | egrep .java$ )" + - echo no | android create avd --force -n test -t android-25 --abi armeabi-v7a -c 100M + - emulator -avd test -no-audio -no-window & + - android-wait-for-emulator + - adb shell input keyevent 82 & +install: + - "./travis/install.sh" +stages: + - name: Building Project + - name: Running Tests + if: branch = master AND type = push +jobs: + include: + - stage: Building Project + script: "./gradlew check" + env: JOB=Checking Build + - script: "./gradlew detekt" + env: JOB=Running Linter + - script: "./gradlew mokaRun --profile" + env: JOB=Running UI Tests + - script: "./gradlew uploadToSaucelabs" + env: + - JOB=Uploading APK to Saucylabs + - STG_API_URL=$STG_SERVER_URL + if: branch = master AND type = push +after_success: + - bundle exec danger + - reports-publisher +after_failure: + - bundle exec danger + - reports-publisher + - "./gradlew mokaDisconnect" +notifications: + webhooks: + - https://devhose.spt-engprod-pro.schibsted.io/devhose/travis \ No newline at end of file diff --git a/app/src/main/java/com/hako/friendlists/Test.kt b/app/src/main/java/com/hako/friendlists/Test.kt new file mode 100644 index 0000000..042f92f --- /dev/null +++ b/app/src/main/java/com/hako/friendlists/Test.kt @@ -0,0 +1,3 @@ +package com.hako.friendlists + +//Hola \ No newline at end of file diff --git a/build.gradle b/build.gradle index cf62116..f752cd6 100644 --- a/build.gradle +++ b/build.gradle @@ -13,10 +13,29 @@ buildscript { } } +plugins { + id "io.gitlab.arturbosch.detekt" version "1.5.0" +} + allprojects { addRepos(repositories) } +detekt { + version = "1.5.0" + autoCorrect = true + failFast = false + config = files("$rootDir/tools/detekt.yml") + input = files(rootProject.projectDir) + + reports { + html { + enabled = true + destination = file("$rootDir/build/reports/detekt") + } + } +} + task clean(type: Delete) { delete rootProject.buildDir } diff --git a/tools/detekt.yml b/tools/detekt.yml new file mode 100644 index 0000000..8e64886 --- /dev/null +++ b/tools/detekt.yml @@ -0,0 +1,437 @@ +build: + maxIssues: 0 + weights: + # complexity: 2 + # LongParameterList: 1 + # style: 1 + # comments: 1 + +processors: + active: true + exclude: + # - 'FunctionCountProcessor' + # - 'PropertyCountProcessor' + # - 'ClassCountProcessor' + # - 'PackageCountProcessor' + # - 'KtFileCountProcessor' + +console-reports: + active: true + exclude: + # - 'ProjectStatisticsReport' + # - 'ComplexityReport' + # - 'NotificationReport' + # - 'FindingsReport' + # - 'BuildFailureReport' + +comments: + active: true + CommentOverPrivateFunction: + active: true + CommentOverPrivateProperty: + active: true + EndOfSentenceFormat: + active: false + endOfSentenceFormat: ([.?!][ \t\n\r\f<])|([.?!]$) + UndocumentedPublicClass: + active: false + searchInNestedClass: false + searchInInnerClass: false + searchInInnerObject: false + searchInInnerInterface: false + UndocumentedPublicFunction: + active: false + +complexity: + active: true + ComplexCondition: + active: true + threshold: 4 + ComplexInterface: + active: false + threshold: 10 + includeStaticDeclarations: false + ComplexMethod: + active: true + threshold: 10 + ignoreSingleWhenExpression: false + LabeledExpression: + active: false + LargeClass: + active: false + threshold: 150 + LongMethod: + active: true + threshold: 20 + LongParameterList: + active: false + threshold: 6 + ignoreDefaultParameters: false + MethodOverloading: + active: false + threshold: 6 + NestedBlockDepth: + active: true + threshold: 5 + StringLiteralDuplication: + active: false + threshold: 3 + ignoreAnnotation: true + excludeStringsWithLessThan5Characters: true + ignoreStringsRegex: '$^' + TooManyFunctions: + active: false + thresholdInFiles: 11 + thresholdInClasses: 11 + thresholdInInterfaces: 11 + thresholdInObjects: 11 + thresholdInEnums: 11 + ignoreDeprecated: false + ignorePrivate: false + +empty-blocks: + active: true + EmptyCatchBlock: + active: true + allowedExceptionNameRegex: "^(_|(ignore|expected).*)" + EmptyClassBlock: + active: true + EmptyDefaultConstructor: + active: true + EmptyDoWhileBlock: + active: true + EmptyElseBlock: + active: true + EmptyFinallyBlock: + active: true + EmptyForBlock: + active: true + EmptyFunctionBlock: + active: true + ignoreOverridden: false + EmptyIfBlock: + active: true + EmptyInitBlock: + active: true + EmptyKtFile: + active: true + EmptySecondaryConstructor: + active: true + EmptyWhenBlock: + active: true + EmptyWhileBlock: + active: true + +exceptions: + active: true + ExceptionRaisedInUnexpectedLocation: + active: false + methodNames: 'toString,hashCode,equals,finalize' + InstanceOfCheckForException: + active: true + NotImplementedDeclaration: + active: true + PrintStackTrace: + active: true + RethrowCaughtException: + active: true + ReturnFromFinally: + active: true + SwallowedException: + active: false + ThrowingExceptionFromFinally: + active: true + ThrowingExceptionInMain: + active: true + ThrowingExceptionsWithoutMessageOrCause: + active: true + ThrowingNewInstanceOfSameException: + active: true + TooGenericExceptionCaught: + active: true + exceptionNames: + - Throwable + TooGenericExceptionThrown: + active: true + exceptionNames: + - Throwable + +formatting: + active: true + android: false + autoCorrect: false + ChainWrapping: + active: true + autoCorrect: false + CommentSpacing: + active: true + autoCorrect: false + Filename: + active: true + FinalNewline: + active: true + autoCorrect: false + ImportOrdering: + active: false + autoCorrect: false + Indentation: + active: true + autoCorrect: false + indentSize: 4 + continuationIndentSize: 4 + MaximumLineLength: + active: true + maxLineLength: 120 + ModifierOrdering: + active: true + autoCorrect: false + NoBlankLineBeforeRbrace: + active: true + autoCorrect: false + NoConsecutiveBlankLines: + active: true + autoCorrect: false + NoEmptyClassBody: + active: true + autoCorrect: false + NoLineBreakAfterElse: + active: true + autoCorrect: false + NoLineBreakBeforeAssignment: + active: true + autoCorrect: false + NoMultipleSpaces: + active: true + autoCorrect: false + NoSemicolons: + active: true + autoCorrect: false + NoTrailingSpaces: + active: true + autoCorrect: false + NoUnitReturn: + active: true + autoCorrect: false + NoUnusedImports: + active: true + autoCorrect: false + NoWildcardImports: + active: true + autoCorrect: false + ParameterListWrapping: + active: false + autoCorrect: false + indentSize: 4 + SpacingAroundColon: + active: false + autoCorrect: false + SpacingAroundComma: + active: true + autoCorrect: false + SpacingAroundCurly: + active: true + autoCorrect: false + SpacingAroundKeyword: + active: true + autoCorrect: false + SpacingAroundOperators: + active: true + autoCorrect: false + SpacingAroundRangeOperator: + active: true + autoCorrect: false + StringTemplate: + active: true + autoCorrect: false + +naming: + active: true + ClassNaming: + active: true + classPattern: '[A-Z$][a-zA-Z0-9$]*' + EnumNaming: + active: true + enumEntryPattern: '^[A-Z][_a-zA-Z0-9]*' + ForbiddenClassName: + active: false + forbiddenName: '' + FunctionMaxLength: + active: false + maximumFunctionNameLength: 30 + FunctionMinLength: + active: false + minimumFunctionNameLength: 3 + FunctionNaming: + active: true + functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' + excludeClassPattern: '$^' + MatchingDeclarationName: + active: false + MemberNameEqualsClassName: + active: false + ignoreOverridden: true + ObjectPropertyNaming: + active: true + propertyPattern: '[A-Za-z][_A-Za-z0-9]*' + constantPattern: '[A-Za-z][_A-Za-z0-9]*' + PackageNaming: + active: true + packagePattern: '^[a-z]+(\.[a-z][a-z0-9]*)*$' + TopLevelPropertyNaming: + active: false + constantPattern: '[A-Z][_A-Z0-9]*' + propertyPattern: '[A-Za-z][_A-Za-z0-9]*' + privatePropertyPattern: '(_)?[A-Za-z][A-Za-z0-9]*' + VariableMaxLength: + active: false + maximumVariableNameLength: 64 + VariableMinLength: + active: false + minimumVariableNameLength: 1 + VariableNaming: + active: true + variablePattern: '[a-z][A-Za-z0-9]*' + privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' + excludeClassPattern: '$^' + +performance: + active: true + ForEachOnRange: + active: true + SpreadOperator: + active: false + UnnecessaryTemporaryInstantiation: + active: true + +potential-bugs: + active: true + DuplicateCaseInWhenExpression: + active: true + EqualsAlwaysReturnsTrueOrFalse: + active: true + EqualsWithHashCodeExist: + active: true + ExplicitGarbageCollectionCall: + active: true + InvalidRange: + active: true + IteratorHasNextCallsNextMethod: + active: false + IteratorNotThrowingNoSuchElementException: + active: false + LateinitUsage: + active: false + excludeAnnotatedProperties: "" + ignoreOnClassesPattern: "" + UnconditionalJumpStatementInLoop: + active: false + UnreachableCode: + active: true + UnsafeCallOnNullableType: + active: false + UnsafeCast: + active: false + UselessPostfixExpression: + active: true + WrongEqualsTypeParameter: + active: true + +style: + active: true + CollapsibleIfStatements: + active: true + DataClassContainsFunctions: + active: false + conversionFunctionPrefix: 'to' + EqualsNullCall: + active: true + ExpressionBodySyntax: + active: true + includeLineWrapping: false + ForbiddenComment: + active: false + values: 'TODO:,FIXME:' + FunctionOnlyReturningConstant: + active: true + ignoreOverridableFunction: true + excludedFunctions: 'describeContents' + LoopWithTooManyJumpStatements: + active: false + maxJumpCount: 1 + MagicNumber: + active: true + ignoreNumbers: '-1,0,1,2' + ignoreHashCodeFunction: false + ignorePropertyDeclaration: false + ignoreConstantDeclaration: true + ignoreCompanionObjectPropertyDeclaration: true + ignoreAnnotation: false + ignoreNamedArgument: true + ignoreEnums: true + MandatoryBracesIfStatements: + active: true + MaxLineLength: + active: true + maxLineLength: 120 + excludePackageStatements: false + excludeImportStatements: false + excludeCommentStatements: false + MayBeConst: + active: true + ModifierOrder: + active: true + NestedClassesVisibility: + active: true + NewLineAtEndOfFile: + active: false + NoTabs: + active: false + OptionalAbstractKeyword: + active: true + OptionalUnit: + active: false + OptionalWhenBraces: + active: false + PreferToOverPairSyntax: + active: false + ProtectedMemberInFinalClass: + active: false + RedundantVisibilityModifierRule: + active: true + ReturnCount: + active: false + max: 2 + excludedFunctions: "equals" + SafeCast: + active: true + SerialVersionUIDInSerializableClass: + active: true + SpacingBetweenPackageAndImports: + active: false + ThrowsCount: + active: true + max: 3 + TrailingWhitespace: + active: true + UnnecessaryAbstractClass: + active: false + UnnecessaryInheritance: + active: true + UnnecessaryParentheses: + active: false + UntilInsteadOfRangeTo: + active: false + UnusedImports: + active: true + UnusedPrivateMember: + active: true + UseDataClass: + active: true + excludeAnnotatedClasses: "" + UtilityClassWithPublicConstructor: + active: true + VarCouldBeVal: + active: true + WildcardImport: + active: false + excludeImports: 'java.util.*' diff --git a/versions.gradle b/versions.gradle index 1c984d7..ec55c79 100644 --- a/versions.gradle +++ b/versions.gradle @@ -24,7 +24,7 @@ deps.kotlin = kotlin ext.deps = deps -def addRepos(RepositoryHandler handler) { +static def addRepos(RepositoryHandler handler) { handler.google() handler.jcenter() handler.maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }