From 8b115dcb3aaff24b4d71926bde816df0cf8e927f Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Sat, 1 Feb 2020 18:14:00 -0300 Subject: [PATCH 1/7] 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' } From 17fd2d7b95cf66e4d1570e73855a57398f3c5c99 Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Sat, 1 Feb 2020 18:59:45 -0300 Subject: [PATCH 2/7] fix output path fix travis fix travis fix travis fix travis fix travis fix travis fix travis fix travis fix travis fix travis --- .travis.yml | 29 ++----------------- .../main/java/com/hako/friendlists/Test.kt | 3 -- build.gradle | 2 +- 3 files changed, 3 insertions(+), 31 deletions(-) delete mode 100644 app/src/main/java/com/hako/friendlists/Test.kt diff --git a/.travis.yml b/.travis.yml index a394074..1afaa60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,19 +18,11 @@ android: - 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: @@ -41,23 +33,6 @@ jobs: include: - stage: Building Project script: "./gradlew check" - env: JOB=Checking Build + env: JOB=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 + env: JOB=Linter \ 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 deleted file mode 100644 index 042f92f..0000000 --- a/app/src/main/java/com/hako/friendlists/Test.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.hako.friendlists - -//Hola \ No newline at end of file diff --git a/build.gradle b/build.gradle index f752cd6..46f5087 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ detekt { reports { html { enabled = true - destination = file("$rootDir/build/reports/detekt") + destination = file("$rootDir/build/reports/detekt/report.html") } } } From dd0c9c9aa4a147907513139e866edf79b648730f Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Sat, 1 Feb 2020 20:23:05 -0300 Subject: [PATCH 3/7] fix travis --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1afaa60..69c5780 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,9 +22,6 @@ android: - '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)" -install: - - "./travis/install.sh" stages: - name: Building Project - name: Running Tests From 0bdcab99562a8df351ff20fb77c72b41160a34b7 Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Sat, 1 Feb 2020 20:26:17 -0300 Subject: [PATCH 4/7] fix dependencies --- base/build.gradle | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/base/build.gradle b/base/build.gradle index 12c1a6e..404a2a5 100644 --- a/base/build.gradle +++ b/base/build.gradle @@ -45,11 +45,11 @@ dependencies { api deps.okhttp_logging_interceptor api deps.timber //Testing - testImplementation deps.testing.junit - testImplementation deps.testing.koin - androidTestImplementation deps.testing.core - androidTestImplementation deps.testing.rules - androidTestImplementation deps.testing.runner - androidTestImplementation deps.testing.ext - androidTestImplementation deps.testing.espresso + api deps.testing.junit + api deps.testing.koin + api deps.testing.core + api deps.testing.rules + api deps.testing.runner + api deps.testing.ext + api deps.testing.espresso } From 990f5730b6c111532af2bbabe7b51218f1d90f8c Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Sat, 1 Feb 2020 20:37:34 -0300 Subject: [PATCH 5/7] fix detekt rules --- app/build.gradle | 4 ++++ tools/detekt.yml | 3 +++ 2 files changed, 7 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 1620323..0b27de6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,6 +37,10 @@ android { testOptions { unitTests.returnDefaultValues = true } + + lintOptions { + abortOnError false + } } dependencies { diff --git a/tools/detekt.yml b/tools/detekt.yml index 8e64886..58e7062 100644 --- a/tools/detekt.yml +++ b/tools/detekt.yml @@ -25,6 +25,7 @@ console-reports: # - 'BuildFailureReport' comments: + excludes: "**/*Test.kt, **/*Spec.kt" active: true CommentOverPrivateFunction: active: true @@ -265,6 +266,7 @@ naming: active: true functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' excludeClassPattern: '$^' + excludes: "**/*Test.kt, **/*Spec.kt" MatchingDeclarationName: active: false MemberNameEqualsClassName: @@ -368,6 +370,7 @@ style: ignoreAnnotation: false ignoreNamedArgument: true ignoreEnums: true + excludes: "**/*Test.kt, **/*Spec.kt" MandatoryBracesIfStatements: active: true MaxLineLength: From aa4bfe63649d9ddce4eb3a614b76b97ccdab57ab Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Sat, 1 Feb 2020 20:41:15 -0300 Subject: [PATCH 6/7] add template --- docs/pull_request_template.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/pull_request_template.md diff --git a/docs/pull_request_template.md b/docs/pull_request_template.md new file mode 100644 index 0000000..b5f5833 --- /dev/null +++ b/docs/pull_request_template.md @@ -0,0 +1,3 @@ +### Proposed changes + +### Sources From 5078a91b4f49253e19eed1d7f422c013d41750e5 Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Sat, 1 Feb 2020 20:48:14 -0300 Subject: [PATCH 7/7] fix missing lint ignore --- base/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/base/build.gradle b/base/build.gradle index 404a2a5..75c9e33 100644 --- a/base/build.gradle +++ b/base/build.gradle @@ -22,6 +22,10 @@ android { testOptions { unitTests.returnDefaultValues = true } + + lintOptions { + abortOnError false + } } dependencies {