diff --git a/.travis.yml b/.travis.yml index 71ead7e6d..9942717aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,7 +48,7 @@ before_script: - adb shell input keyevent 82 & script: - - ./gradlew jacocoInstrumentationTestReport ktlintCheck app:lintDebug core:lintDebug custom:lintCustomexampleDebug jacocoTestDebugUnitTestReport jacocoTestCustomExampleDebugUnitTestReport app:assembleDebug + - ./gradlew jacocoInstrumentationTestReport ktlintCheck detekt app:lintDebug core:lintDebug custom:lintCustomexampleDebug jacocoTestDebugUnitTestReport jacocoTestCustomExampleDebugUnitTestReport app:assembleDebug after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/app/detekt_baseline.xml b/app/detekt_baseline.xml new file mode 100644 index 000000000..52fa7ee05 --- /dev/null +++ b/app/detekt_baseline.xml @@ -0,0 +1,59 @@ + + + + + EmptyFunctionBlock:None.kt$None${ } + EmptyFunctionBlock:SimplePageChangeListener.kt$SimplePageChangeListener${ } + EmptyFunctionBlock:ZimHostActivity.kt$ZimHostActivity.<no name provided>${} + ForbiddenComment:KiwixMainActivity.kt$KiwixMainActivity$// TODO: Show to user + LongParameterList:ZimManageViewModel.kt$ZimManageViewModel$( booksOnFileSystem: List<BookOnDisk>, activeDownloads: List<DownloadModel>, allLanguages: List<Language>, libraryNetworkEntity: LibraryNetworkEntity, filter: String, fileSystemState: FileSystemState ) + MagicNumber:LibraryFragment.kt$LibraryFragment$1024f + MagicNumber:ShareFiles.kt$ShareFiles$24 + MagicNumber:ZimManageViewModel.kt$ZimManageViewModel$5 + MagicNumber:ZimManageViewModel.kt$ZimManageViewModel$500 + MagicNumber:ZimManageViewModel.kt$ZimManageViewModel$60 + PackageNaming:ConnectivityBroadcastReceiver.kt$package org.kiwix.kiwixmobile.zim_manager + PackageNaming:DefaultLanguageProvider.kt$package org.kiwix.kiwixmobile.zim_manager + PackageNaming:DeleteFiles.kt$package org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects + PackageNaming:DownloadAdapter.kt$package org.kiwix.kiwixmobile.zim_manager.download_view + PackageNaming:DownloadFragment.kt$package org.kiwix.kiwixmobile.zim_manager.download_view + PackageNaming:DownloadViewHolder.kt$package org.kiwix.kiwixmobile.zim_manager.download_view + PackageNaming:Fat32Checker.kt$package org.kiwix.kiwixmobile.zim_manager + PackageNaming:FileSelectListState.kt$package org.kiwix.kiwixmobile.zim_manager.fileselect_view + PackageNaming:HotspotStateReceiver.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot + PackageNaming:LibraryAdapter.kt$package org.kiwix.kiwixmobile.zim_manager.library_view.adapter + PackageNaming:LibraryDelegate.kt$package org.kiwix.kiwixmobile.zim_manager.library_view.adapter + PackageNaming:LibraryFragment.kt$package org.kiwix.kiwixmobile.zim_manager.library_view + PackageNaming:LibraryListItem.kt$package org.kiwix.kiwixmobile.zim_manager.library_view.adapter + PackageNaming:LibraryViewHolder.kt$package org.kiwix.kiwixmobile.zim_manager.library_view.adapter + PackageNaming:NetworkState.kt$package org.kiwix.kiwixmobile.zim_manager + PackageNaming:None.kt$package org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects + PackageNaming:OpenFile.kt$package org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects + PackageNaming:SectionsPagerAdapter.kt$package org.kiwix.kiwixmobile.zim_manager + PackageNaming:ShareFiles.kt$package org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects + PackageNaming:SimplePageChangeListener.kt$package org.kiwix.kiwixmobile.zim_manager + PackageNaming:SimpleTextListener.kt$package org.kiwix.kiwixmobile.zim_manager + PackageNaming:StartMultiSelection.kt$package org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects + PackageNaming:ZimFileSelectFragment.kt$package org.kiwix.kiwixmobile.zim_manager.fileselect_view + PackageNaming:ZimManageActivity.kt$package org.kiwix.kiwixmobile.zim_manager + PackageNaming:ZimManageViewModel.kt$package org.kiwix.kiwixmobile.zim_manager + ReturnCount:LanguageActivity.kt$LanguageActivity$override fun onOptionsItemSelected(item: MenuItem): Boolean + ReturnCount:LibraryFragment.kt$LibraryFragment$private fun onBookItemClick(item: BookItem) + SpreadOperator:LanguageAdapter.kt$LanguageAdapter$(*delegates) + SpreadOperator:LibraryAdapter.kt$LibraryAdapter$( *delegates ) + SpreadOperator:ZimManageViewModel.kt$ZimManageViewModel$( *createLibrarySection( booksUnfilteredByLanguage.filter { activeLanguageCodes.contains(it.language) }, fileSystemState, R.string.your_languages, Long.MAX_VALUE ), *createLibrarySection( booksUnfilteredByLanguage.filterNot { activeLanguageCodes.contains(it.language) }, fileSystemState, R.string.other_languages, Long.MIN_VALUE ) ) + SpreadOperator:ZimManageViewModel.kt$ZimManageViewModel$( DividerItem(sectionId, context.getString(sectionStringId)), *toBookItems(books, fileSystemState) ) + SpreadOperator:ZimManageViewModel.kt$ZimManageViewModel$(*disposables()) + TooGenericExceptionCaught:Fat32Checker.kt$Fat32Checker$e: Exception + TooGenericExceptionCaught:KiwixMainActivity.kt$KiwixMainActivity$e: Exception + TooGenericExceptionThrown:LibraryViewHolder.kt$LibraryViewHolder.LibraryBookViewHolder$throw RuntimeException("impossible invalid state: ${item.fileSystemState}") + TooGenericExceptionThrown:SectionsPagerAdapter.kt$SectionsPagerAdapter$throw RuntimeException("No matching fragment for position: $position") + TooGenericExceptionThrown:SectionsPagerAdapter.kt$SectionsPagerAdapter$throw RuntimeException("No matching title for position: $position") + TooGenericExceptionThrown:ZimManageViewModel.kt$ZimManageViewModel$throw RuntimeException("Impossible state") + TooManyFunctions:KiwixActivityComponent.kt$KiwixActivityComponent$KiwixActivityComponent + TooManyFunctions:KiwixMainActivity.kt$KiwixMainActivity$KiwixMainActivity + TooManyFunctions:LibraryFragment.kt$LibraryFragment$LibraryFragment + TooManyFunctions:ZimHostActivity.kt$ZimHostActivity$ZimHostActivity + TooManyFunctions:ZimManageViewModel.kt$ZimManageViewModel$ZimManageViewModel + + diff --git a/build.gradle.kts b/build.gradle.kts index 6d89b561d..29d4115f0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,6 +8,7 @@ buildscript { classpath(Libs.kotlin_gradle_plugin) classpath(Libs.ktlint_gradle) classpath(Libs.jacoco_android) + classpath(Libs.detekt_gradle_plugin) // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 671a43c07..8e99d9356 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { implementation("com.dicedmelon.gradle:jacoco-android:0.1.4") implementation("org.jlleitschuh.gradle:ktlint-gradle:8.2.0") implementation("com.google.apis:google-api-services-androidpublisher:v3-rev129-1.25.0") + implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.2.2") implementation(gradleApi()) implementation(localGroovy()) diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index 227b9a550..1c554bc47 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -48,6 +48,36 @@ object Libs { */ const val retrofit: String = "com.squareup.retrofit2:retrofit:" + Versions.com_squareup_retrofit2 + /** + * https://kotlinlang.org/ + */ + const val kotlin_android_extensions: String = "org.jetbrains.kotlin:kotlin-android-extensions:" + + Versions.org_jetbrains_kotlin + + /** + * https://kotlinlang.org/ + */ + const val kotlin_android_extensions_runtime: String = + "org.jetbrains.kotlin:kotlin-android-extensions-runtime:" + Versions.org_jetbrains_kotlin + + /** + * https://kotlinlang.org/ + */ + const val kotlin_annotation_processing_gradle: String = + "org.jetbrains.kotlin:kotlin-annotation-processing-gradle:" + Versions.org_jetbrains_kotlin + + /** + * https://kotlinlang.org/ + */ + const val kotlin_gradle_plugin: String = "org.jetbrains.kotlin:kotlin-gradle-plugin:" + + Versions.org_jetbrains_kotlin + + /** + * https://kotlinlang.org/ + */ + const val kotlin_stdlib_jdk7: String = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:" + + Versions.org_jetbrains_kotlin + /** * https://github.com/google/dagger */ @@ -192,41 +222,18 @@ object Libs { "com.github.triplet.play:com.github.triplet.play.gradle.plugin:" + Versions.com_github_triplet_play_gradle_plugin - /** - * https://kotlinlang.org/ - */ - const val kotlin_annotation_processing_gradle: String = - "org.jetbrains.kotlin:kotlin-annotation-processing-gradle:" + - Versions.kotlin_annotation_processing_gradle - - /** - * https://kotlinlang.org/ - */ - const val kotlin_android_extensions_runtime: String = - "org.jetbrains.kotlin:kotlin-android-extensions-runtime:" + - Versions.kotlin_android_extensions_runtime - - /** - * https://kotlinlang.org/ - */ - const val kotlin_android_extensions: String = "org.jetbrains.kotlin:kotlin-android-extensions:" + - Versions.kotlin_android_extensions - const val multidex_instrumentation: String = "androidx.multidex:multidex-instrumentation:" + Versions.multidex_instrumentation + const val detekt_gradle_plugin: String = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:" + + Versions.detekt_gradle_plugin + /** * http://jcp.org/en/jsr/detail?id=250 */ const val javax_annotation_api: String = "javax.annotation:javax.annotation-api:" + Versions.javax_annotation_api - /** - * https://kotlinlang.org/ - */ - const val kotlin_gradle_plugin: String = "org.jetbrains.kotlin:kotlin-gradle-plugin:" + - Versions.kotlin_gradle_plugin - /** * https://github.com/square/okhttp */ @@ -236,12 +243,6 @@ object Libs { const val ink_page_indicator: String = "com.pacioianu.david:ink-page-indicator:" + Versions.ink_page_indicator - /** - * https://kotlinlang.org/ - */ - const val kotlin_stdlib_jdk7: String = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:" + - Versions.kotlin_stdlib_jdk7 - /** * http://github.com/square/leakcanary/ */ diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index fccae58e4..416d73a47 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,3 +1,4 @@ +import kotlin.String import org.gradle.plugin.use.PluginDependenciesSpec import org.gradle.plugin.use.PluginDependencySpec @@ -13,7 +14,9 @@ import org.gradle.plugin.use.PluginDependencySpec object Versions { const val androidx_test_espresso: String = "3.1.1" // available: "3.2.0" - const val com_squareup_retrofit2: String = "2.5.0" // available: "2.6.2" + const val com_squareup_retrofit2: String = "2.5.0" // available: "2.7.0" + + const val org_jetbrains_kotlin: String = "1.3.61" const val com_google_dagger: String = "2.21" // available: "2.25.2" @@ -29,7 +32,7 @@ object Versions { const val android_arch_lifecycle_extensions: String = "1.1.1" - const val com_android_tools_build_gradle: String = "3.5.2" + const val com_android_tools_build_gradle: String = "3.5.2" // available: "3.5.3" const val androidx_test_runner: String = "1.2.0" @@ -41,24 +44,16 @@ object Versions { const val com_github_triplet_play_gradle_plugin: String = "2.5.0" // available: "2.6.1" - const val kotlin_annotation_processing_gradle: String = "1.3.61" - - const val kotlin_android_extensions_runtime: String = "1.3.61" - - const val kotlin_android_extensions: String = "1.3.61" - const val multidex_instrumentation: String = "2.0.0" - const val javax_annotation_api: String = "1.3.2" + const val detekt_gradle_plugin: String = "1.2.2" - const val kotlin_gradle_plugin: String = "1.3.61" + const val javax_annotation_api: String = "1.3.2" const val logging_interceptor: String = "3.12.1" // available: "4.2.2" const val ink_page_indicator: String = "1.3.0" - const val kotlin_stdlib_jdk7: String = "1.3.61" - const val leakcanary_android: String = "2.0" const val constraintlayout: String = "1.1.3" @@ -85,7 +80,7 @@ object Versions { const val orchestrator: String = "1.1.0" // available: "1.2.0" - const val lint_gradle: String = "26.5.2" + const val lint_gradle: String = "26.5.2" // available: "26.5.3" const val testing_ktx: String = "1.1.1" @@ -105,7 +100,7 @@ object Versions { const val core_ktx: String = "1.1.0" - const val kiwixlib: String = "8.2.1" + const val kiwixlib: String = "8.2.1" // available: "8.2.2" const val material: String = "1.1.0-beta02" @@ -123,7 +118,7 @@ object Versions { const val rxjava: String = "2.2.5" // available: "2.2.15" - const val aapt2: String = "3.5.2-5435860" + const val aapt2: String = "3.5.2-5435860" // available: "3.5.3-5435860" const val junit: String = "1.1.1" @@ -141,4 +136,4 @@ object Versions { */ val PluginDependenciesSpec.buildSrcVersions: PluginDependencySpec inline get() = - id("de.fayard.buildSrcVersions").version(Versions.de_fayard_buildsrcversions_gradle_plugin) + id("de.fayard.buildSrcVersions").version(Versions.de_fayard_buildsrcversions_gradle_plugin) diff --git a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt index 738faf9ec..c79d43ecc 100644 --- a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt +++ b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt @@ -21,6 +21,7 @@ package plugin import Config import Libs import com.android.build.gradle.BaseExtension +import io.gitlab.arturbosch.detekt.extensions.DetektExtension import org.gradle.api.Project import org.gradle.api.tasks.testing.Test import org.gradle.kotlin.dsl.KotlinClosure1 @@ -39,6 +40,7 @@ class AllProjectConfigurer { target.plugins.apply("kotlin-kapt") target.plugins.apply("jacoco-android") target.plugins.apply("org.jlleitschuh.gradle.ktlint") + target.plugins.apply("io.gitlab.arturbosch.detekt") } fun configureBaseExtension(target: Project, path: String) { @@ -134,6 +136,10 @@ class AllProjectConfigurer { configureExtension { isExperimental = true } configureExtension { toolVersion = "0.8.3" } configureExtension { android.set(true) } + configureExtension { + baseline = project.file("detekt_baseline.xml") + } + } } diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml new file mode 100644 index 000000000..3545f2f29 --- /dev/null +++ b/config/detekt/detekt.yml @@ -0,0 +1,580 @@ +build: + maxIssues: 10 + weights: + # complexity: 2 + # LongParameterList: 1 + # style: 1 + # comments: 1 + +config: + validation: true + # when writing own rules with new properties, exclude the property path e.g.: "my_rule_set,.*>.*>[my_property]" + excludes: "" + +processors: + active: true + exclude: + # - 'DetektProgressListener' + # - 'FunctionCountProcessor' + # - 'PropertyCountProcessor' + # - 'ClassCountProcessor' + # - 'PackageCountProcessor' + # - 'KtFileCountProcessor' + +console-reports: + active: true + exclude: + # - 'ProjectStatisticsReport' + # - 'ComplexityReport' + # - 'NotificationReport' + # - 'FindingsReport' + - 'FileBasedFindingsReport' + # - 'BuildFailureReport' + +comments: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + CommentOverPrivateFunction: + active: false + CommentOverPrivateProperty: + active: false + EndOfSentenceFormat: + active: false + endOfSentenceFormat: ([.?!][ \t\n\r\f<])|([.?!:]$) + UndocumentedPublicClass: + active: false + searchInNestedClass: true + searchInInnerClass: true + searchInInnerObject: true + searchInInnerInterface: true + UndocumentedPublicFunction: + active: false + UndocumentedPublicProperty: + active: false + +complexity: + active: true + ComplexCondition: + active: true + threshold: 4 + ComplexInterface: + active: false + threshold: 10 + includeStaticDeclarations: false + ComplexMethod: + active: true + threshold: 15 + ignoreSingleWhenExpression: false + ignoreSimpleWhenEntries: false + ignoreNestingFunctions: false + nestingFunctions: run,let,apply,with,also,use,forEach,isNotNull,ifNull + LabeledExpression: + active: false + ignoredLabels: "" + LargeClass: + active: true + threshold: 600 + LongMethod: + active: true + threshold: 60 + LongParameterList: + active: true + threshold: 6 + ignoreDefaultParameters: false + MethodOverloading: + active: false + threshold: 6 + NestedBlockDepth: + active: true + threshold: 4 + StringLiteralDuplication: + active: false + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + threshold: 3 + ignoreAnnotation: true + excludeStringsWithLessThan5Characters: true + ignoreStringsRegex: '$^' + TooManyFunctions: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + thresholdInFiles: 11 + thresholdInClasses: 11 + thresholdInInterfaces: 11 + thresholdInObjects: 11 + thresholdInEnums: 11 + ignoreDeprecated: false + ignorePrivate: false + ignoreOverridden: 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 + ignoreOverriddenFunctions: 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: false + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + NotImplementedDeclaration: + active: false + PrintStackTrace: + active: false + RethrowCaughtException: + active: false + ReturnFromFinally: + active: false + ignoreLabeled: false + SwallowedException: + active: false + ignoredExceptionTypes: 'InterruptedException,NumberFormatException,ParseException,MalformedURLException' + allowedExceptionNameRegex: "^(_|(ignore|expected).*)" + ThrowingExceptionFromFinally: + active: false + ThrowingExceptionInMain: + active: false + ThrowingExceptionsWithoutMessageOrCause: + active: false + exceptions: 'IllegalArgumentException,IllegalStateException,IOException' + ThrowingNewInstanceOfSameException: + active: false + TooGenericExceptionCaught: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + exceptionNames: + - ArrayIndexOutOfBoundsException + - Error + - Exception + - IllegalMonitorStateException + - NullPointerException + - IndexOutOfBoundsException + - RuntimeException + - Throwable + allowedExceptionNameRegex: "^(_|(ignore|expected).*)" + TooGenericExceptionThrown: + active: true + exceptionNames: + - Error + - Exception + - Throwable + - RuntimeException + +formatting: + active: true + android: false + autoCorrect: true + AnnotationOnSeparateLine: + active: false + autoCorrect: true + ChainWrapping: + active: true + autoCorrect: true + CommentSpacing: + active: true + autoCorrect: true + Filename: + active: true + FinalNewline: + active: true + autoCorrect: true + ImportOrdering: + active: false + autoCorrect: true + Indentation: + active: false + autoCorrect: true + indentSize: 4 + continuationIndentSize: 4 + MaximumLineLength: + active: true + maxLineLength: 120 + ModifierOrdering: + active: true + autoCorrect: true + MultiLineIfElse: + active: true + autoCorrect: true + NoBlankLineBeforeRbrace: + active: true + autoCorrect: true + NoConsecutiveBlankLines: + active: true + autoCorrect: true + NoEmptyClassBody: + active: true + autoCorrect: true + NoLineBreakAfterElse: + active: true + autoCorrect: true + NoLineBreakBeforeAssignment: + active: true + autoCorrect: true + NoMultipleSpaces: + active: true + autoCorrect: true + NoSemicolons: + active: true + autoCorrect: true + NoTrailingSpaces: + active: true + autoCorrect: true + NoUnitReturn: + active: true + autoCorrect: true + NoUnusedImports: + active: true + autoCorrect: true + NoWildcardImports: + active: true + PackageName: + active: true + autoCorrect: true + ParameterListWrapping: + active: true + autoCorrect: true + indentSize: 4 + SpacingAroundColon: + active: true + autoCorrect: true + SpacingAroundComma: + active: true + autoCorrect: true + SpacingAroundCurly: + active: true + autoCorrect: true + SpacingAroundDot: + active: true + autoCorrect: true + SpacingAroundKeyword: + active: true + autoCorrect: true + SpacingAroundOperators: + active: true + autoCorrect: true + SpacingAroundParens: + active: true + autoCorrect: true + SpacingAroundRangeOperator: + active: true + autoCorrect: true + StringTemplate: + active: true + autoCorrect: true + +naming: + active: true + ClassNaming: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + classPattern: '[A-Z$][a-zA-Z0-9$]*' + ConstructorParameterNaming: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + parameterPattern: '[a-z][A-Za-z0-9]*' + privateParameterPattern: '[a-z][A-Za-z0-9]*' + excludeClassPattern: '$^' + ignoreOverridden: true + EnumNaming: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + enumEntryPattern: '^[A-Z][_a-zA-Z0-9]*' + ForbiddenClassName: + active: false + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + forbiddenName: '' + FunctionMaxLength: + active: false + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + maximumFunctionNameLength: 30 + FunctionMinLength: + active: false + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + minimumFunctionNameLength: 3 + FunctionNaming: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' + excludeClassPattern: '$^' + ignoreOverridden: true + FunctionParameterNaming: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + parameterPattern: '[a-z][A-Za-z0-9]*' + excludeClassPattern: '$^' + ignoreOverriddenFunctions: true + InvalidPackageDeclaration: + active: false + rootPackage: '' + MatchingDeclarationName: + active: true + MemberNameEqualsClassName: + active: true + ignoreOverriddenFunction: true + ObjectPropertyNaming: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + constantPattern: '[A-Za-z][_A-Za-z0-9]*' + propertyPattern: '[A-Za-z][_A-Za-z0-9]*' + privatePropertyPattern: '(_)?[A-Za-z][_A-Za-z0-9]*' + PackageNaming: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + packagePattern: '^[a-z]+(\.[a-z][A-Za-z0-9]*)*$' + TopLevelPropertyNaming: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + 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 + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + maximumVariableNameLength: 64 + VariableMinLength: + active: false + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + minimumVariableNameLength: 1 + VariableNaming: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + variablePattern: '[a-z][A-Za-z0-9]*' + privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' + excludeClassPattern: '$^' + ignoreOverridden: true + +performance: + active: true + ArrayPrimitive: + active: true + ForEachOnRange: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + SpreadOperator: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + UnnecessaryTemporaryInstantiation: + active: true + +potential-bugs: + active: true + Deprecation: + active: false + DuplicateCaseInWhenExpression: + active: true + EqualsAlwaysReturnsTrueOrFalse: + active: true + EqualsWithHashCodeExist: + active: true + ExplicitGarbageCollectionCall: + active: true + HasPlatformType: + active: false + ImplicitDefaultLocale: + active: false + InvalidRange: + active: true + IteratorHasNextCallsNextMethod: + active: true + IteratorNotThrowingNoSuchElementException: + active: true + LateinitUsage: + active: false + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludeAnnotatedProperties: "" + ignoreOnClassesPattern: "" + MissingWhenCase: + active: true + RedundantElseInWhen: + active: true + UnconditionalJumpStatementInLoop: + active: false + UnreachableCode: + active: true + UnsafeCallOnNullableType: + active: true + UnsafeCast: + active: false + UselessPostfixExpression: + active: false + WrongEqualsTypeParameter: + active: true + +style: + active: true + CollapsibleIfStatements: + active: false + DataClassContainsFunctions: + active: false + conversionFunctionPrefix: 'to' + DataClassShouldBeImmutable: + active: false + EqualsNullCall: + active: true + EqualsOnSignatureLine: + active: false + ExplicitItLambdaParameter: + active: false + ExpressionBodySyntax: + active: false + includeLineWrapping: false + ForbiddenComment: + active: true + values: 'TODO:,FIXME:,STOPSHIP:' + allowedPatterns: "" + ForbiddenImport: + active: false + imports: '' + forbiddenPatterns: "" + ForbiddenVoid: + active: false + ignoreOverridden: false + ignoreUsageInGenerics: false + FunctionOnlyReturningConstant: + active: true + ignoreOverridableFunction: true + excludedFunctions: 'describeContents' + excludeAnnotatedFunction: "dagger.Provides" + LibraryCodeMustSpecifyReturnType: + active: true + LoopWithTooManyJumpStatements: + active: true + maxJumpCount: 1 + MagicNumber: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + ignoreNumbers: '-1,0,1,2' + ignoreHashCodeFunction: true + ignorePropertyDeclaration: false + ignoreLocalVariableDeclaration: false + ignoreConstantDeclaration: true + ignoreCompanionObjectPropertyDeclaration: true + ignoreAnnotation: false + ignoreNamedArgument: true + ignoreEnums: false + ignoreRanges: false + MandatoryBracesIfStatements: + active: false + MaxLineLength: + active: true + maxLineLength: 120 + excludePackageStatements: true + excludeImportStatements: true + excludeCommentStatements: false + MayBeConst: + active: true + ModifierOrder: + active: true + NestedClassesVisibility: + active: false + NewLineAtEndOfFile: + active: true + NoTabs: + active: false + OptionalAbstractKeyword: + active: true + OptionalUnit: + active: false + OptionalWhenBraces: + active: false + PreferToOverPairSyntax: + active: false + ProtectedMemberInFinalClass: + active: true + RedundantExplicitType: + active: false + RedundantVisibilityModifierRule: + active: false + ReturnCount: + active: true + max: 2 + excludedFunctions: "equals" + excludeLabeled: false + excludeReturnFromLambda: true + excludeGuardClauses: false + SafeCast: + active: true + SerialVersionUIDInSerializableClass: + active: false + SpacingBetweenPackageAndImports: + active: false + ThrowsCount: + active: true + max: 2 + TrailingWhitespace: + active: false + UnderscoresInNumericLiterals: + active: false + acceptableDecimalLength: 5 + UnnecessaryAbstractClass: + active: true + excludeAnnotatedClasses: "dagger.Module" + UnnecessaryApply: + active: false + UnnecessaryInheritance: + active: true + UnnecessaryLet: + active: false + UnnecessaryParentheses: + active: false + UntilInsteadOfRangeTo: + active: false + UnusedImports: + active: false + UnusedPrivateClass: + active: true + UnusedPrivateMember: + active: false + allowedNames: "(_|ignored|expected|serialVersionUID)" + UseArrayLiteralsInAnnotations: + active: false + UseCheckOrError: + active: false + UseDataClass: + active: false + excludeAnnotatedClasses: "" + allowVars: false + UseIfInsteadOfWhen: + active: false + UseRequire: + active: false + UselessCallOnNotNull: + active: true + UtilityClassWithPublicConstructor: + active: true + VarCouldBeVal: + active: false + WildcardImport: + active: true + excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludeImports: 'java.util.*,kotlinx.android.synthetic.*' diff --git a/core/detekt_baseline.xml b/core/detekt_baseline.xml new file mode 100644 index 000000000..e3997015e --- /dev/null +++ b/core/detekt_baseline.xml @@ -0,0 +1,62 @@ + + + + + ConstructorParameterNaming:KiwixTag.kt$KiwixTag.Companion.YesNoValueTag$_value: String + EmptyFunctionBlock:BooksOnDiskViewHolder.kt$BookOnDiskViewHolder.BookViewHolder${ } + EmptyFunctionBlock:FetchDownloadMonitor.kt$FetchDownloadMonitor.<no name provided>${} + MagicNumber:ArticleCount.kt$ArticleCount$1000.0 + MagicNumber:ArticleCount.kt$ArticleCount$3 + MagicNumber:CoreSplashActivity.kt$CoreSplashActivity$10 + MagicNumber:DownloadItem.kt$DownloadItem$1000L + MagicNumber:DownloaderModule.kt$DownloaderModule$5 + MagicNumber:FetchDownloadNotificationManager.kt$FetchDownloadNotificationManager$100 + MagicNumber:FetchDownloadRequester.kt$10 + MagicNumber:FileUtils.kt$FileUtils$3 + MagicNumber:KiloByte.kt$KiloByte$1024.0 + MagicNumber:MainMenu.kt$MainMenu$99 + MagicNumber:Seconds.kt$Seconds$24 + MagicNumber:Seconds.kt$Seconds$60 + MagicNumber:Seconds.kt$Seconds$60.0 + NestedBlockDepth:FileUtils.kt$FileUtils$deleteZimFile + NestedBlockDepth:ImageUtils.kt$ImageUtils$getBitmapFromView + NestedBlockDepth:StorageDeviceUtils.kt$StorageDeviceUtils$canWrite + PackageNaming:ArticleCount.kt$package org.kiwix.kiwixmobile.core.zim_manager.fileselect_view + PackageNaming:BookOnDiskDelegate.kt$package org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter + PackageNaming:BooksOnDiskAdapter.kt$package org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter + PackageNaming:BooksOnDiskListItem.kt$package org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter + PackageNaming:BooksOnDiskViewHolder.kt$package org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter + PackageNaming:KiloByte.kt$package org.kiwix.kiwixmobile.core.zim_manager + PackageNaming:KiwixTag.kt$package org.kiwix.kiwixmobile.core.zim_manager + PackageNaming:Language.kt$package org.kiwix.kiwixmobile.core.zim_manager + PackageNaming:SelectionMode.kt$package org.kiwix.kiwixmobile.core.zim_manager.fileselect_view + PackageNaming:TagsView.kt$package org.kiwix.kiwixmobile.core.zim_manager + ReturnCount:FileUtils.kt$FileUtils$@JvmStatic fun getAllZimParts(book: Book): List<File> + ReturnCount:FileUtils.kt$FileUtils$@JvmStatic fun getLocalFilePathByUri( context: Context, uri: Uri ): String? + ReturnCount:FileUtils.kt$FileUtils$@JvmStatic fun hasPart(file: File): Boolean + ReturnCount:FileUtils.kt$FileUtils$@Synchronized private fun deleteZimFileParts(path: String): Boolean + ReturnCount:ImageUtils.kt$ImageUtils$private fun getBitmapFromView(width: Int, height: Int, viewToDrawFrom: View): Bitmap? + SpreadOperator:AlertDialogShower.kt$AlertDialogShower$(dialog.message, *bodyArguments(dialog)) + SpreadOperator:BooksOnDiskAdapter.kt$BooksOnDiskAdapter$( *delegates ) + SpreadOperator:FileSearch.kt$FileSearch$(*zimFileExtensions) + TooGenericExceptionThrown:AbstractContentProvider.kt$AbstractContentProvider$throw RuntimeException("Operation not supported") + TooGenericExceptionThrown:AdapterDelegateManager.kt$AdapterDelegateManager$throw RuntimeException("No delegate registered for $item") + TooGenericExceptionThrown:Bytes.kt$Bytes$throw RuntimeException("impossible value $size") + TooGenericExceptionThrown:CursorExtensions.kt$throw RuntimeException("$columnName not found in $columnNames") + TooGenericExceptionThrown:CursorExtensions.kt$throw RuntimeException("Unexpected return type ${T::class.java.simpleName}") + TooGenericExceptionThrown:NightModeConfig.kt$NightModeConfig.Mode.Companion$throw RuntimeException("Invalid night mode $nightMode") + TooGenericExceptionThrown:NightModeConfig.kt$NightModeConfig.UiMode.Companion$throw RuntimeException("Invalid night mode $uiMode") + TooManyFunctions:CoreComponent.kt$CoreComponent$CoreComponent + TooManyFunctions:FetchDownloadMonitor.kt$FetchDownloadMonitor$<no name provided> : FetchListener + TooManyFunctions:FileUtils.kt$FileUtils$FileUtils + TooManyFunctions:Repository.kt$Repository$Repository + TooManyFunctions:ZimFileReader.kt$ZimFileReader$ZimFileReader + TooManyFunctions:ZimReaderContainer.kt$ZimReaderContainer$ZimReaderContainer + TopLevelPropertyNaming:Bytes.kt$const val Eb = Pb * 1024 + TopLevelPropertyNaming:Bytes.kt$const val Gb = Mb * 1024 + TopLevelPropertyNaming:Bytes.kt$const val Kb = 1 * 1024L + TopLevelPropertyNaming:Bytes.kt$const val Mb = Kb * 1024 + TopLevelPropertyNaming:Bytes.kt$const val Pb = Tb * 1024 + TopLevelPropertyNaming:Bytes.kt$const val Tb = Gb * 1024 + + diff --git a/custom/detekt_baseline.xml b/custom/detekt_baseline.xml new file mode 100644 index 000000000..12a61cae6 --- /dev/null +++ b/custom/detekt_baseline.xml @@ -0,0 +1,9 @@ + + + + + LongParameterList:DownloadCustom.kt$DownloadCustom$( id: String = "", title: String = "", description: String = "", language: String = "", creator: String = "", publisher: String = "", date: String = "", url: String = "", articleCount: String = "", mediaCount: String = "", size: String = "", name: String = "", favIcon: String = "" ) + MagicNumber:CustomDownloadActivity.kt$CustomDownloadActivity$3 + TooManyFunctions:CustomMainActivity.kt$CustomMainActivity$CustomMainActivity + + diff --git a/team-props/git-hooks/pre-commit.sh b/team-props/git-hooks/pre-commit.sh index ae77f216e..2d9c99055 100644 --- a/team-props/git-hooks/pre-commit.sh +++ b/team-props/git-hooks/pre-commit.sh @@ -2,7 +2,7 @@ echo "Running lint..." -./gradlew ktlintCheck app:lintDebug core:lintDebug custom:lintCustomexampleDebug --daemon +./gradlew ktlintCheck detekt app:lintDebug core:lintDebug custom:lintCustomexampleDebug --daemon status=$?