使用detekt改进kotlin项目质量

认识 detekt,一个用于 Kotlin 编程语言的静态代码分析工具。他的功能如下:

  • 为您的 Kotlin 项目进行代码气味分析。
  • 高度可配置的规则集。
  • 生成基线以抑制旧项目的现有问题,同时确保不会引入新问题。
  • 使用批注禁止显示源文件中的问题。@Suppress
  • 支持不同的报告格式:HTML,Markdown,SARIF,XML(Checkstyle)和自定义报告。
  • 使用自定义规则集和报告扩展 detekt。
  • 基于代码行数、圈复杂度和代码异味数量的复杂性报告。
  • 使用我们的 Gradle 插件与 Gradle 进行第一方集成。
  • 一个第三方插件社区,为 detekt 添加了更多规则和功能。

detekt提供了注释,复杂度,协程,空白块,异常,代码格式,库相关,命名,性能,潜在缺陷,代码风格等多个类别的规则,我们整理了其中的246条规则。

使用gui配置工具

使用gui配置工具,可以让配置detekt参数更简单。

在凌鲨(linksaas)的微应用里面可以找到detekt配置助手,快速配置自定义规则。

凌鲨(linksaas)是以开源方式运作的,您可以从linksaas · 极狐GitLab 访问源代码。也可以从 凌鲨 软件研发团队信息枢纽 下载预编译的版本。

附录

规则列表

  • AbsentOrWrongFileLicense
  • CommentOverPrivateFunction
  • CommentOverPrivateProperty
  • DeprecatedBlockTag
  • EndOfSentenceFormat
  • KDocReferencesNonPublicProperty
  • OutdatedDocumentation
  • UndocumentedPublicClass
  • UndocumentedPublicFunction
  • UndocumentedPublicProperty
  • CognitiveComplexMethod
  • ComplexCondition
  • ComplexInterface
  • CyclomaticComplexMethod
  • LabeledExpression
  • LargeClass
  • LongMethod
  • LongParameterList
  • MethodOverloading
  • NamedArguments
  • NestedBlockDepth
  • NestedScopeFunctions
  • ReplaceSafeCallChainWithRun
  • StringLiteralDuplication
  • TooManyFunctions
  • GlobalCoroutineUsage
  • InjectDispatcher
  • RedundantSuspendModifier
  • SleepInsteadOfDelay
  • SuspendFunWithCoroutineScopeReceiver
  • SuspendFunWithFlowReturnType
  • EmptyCatchBlock
  • EmptyClassBlock
  • EmptyDefaultConstructor
  • EmptyDoWhileBlock
  • EmptyElseBlock
  • EmptyFinallyBlock
  • EmptyForBlock
  • EmptyFunctionBlock
  • EmptyIfBlock
  • EmptyInitBlock
  • EmptyKtFile
  • EmptySecondaryConstructor
  • EmptyTryBlock
  • EmptyWhenBlock
  • EmptyWhileBlock
  • ExceptionRaisedInUnexpectedLocation
  • InstanceOfCheckForException
  • NotImplementedDeclaration
  • ObjectExtendsThrowable
  • PrintStackTrace
  • RethrowCaughtException
  • ReturnFromFinally
  • SwallowedException
  • ThrowingExceptionFromFinally
  • ThrowingExceptionInMain
  • ThrowingExceptionsWithoutMessageOrCause
  • ThrowingNewInstanceOfSameException
  • TooGenericExceptionCaught
  • TooGenericExceptionThrown
  • AnnotationOnSeparateLine
  • AnnotationSpacing
  • ArgumentListWrapping
  • BlockCommentInitialStarAlignment
  • ChainWrapping
  • CommentSpacing
  • CommentWrapping
  • DiscouragedCommentLocation
  • EnumEntryNameCase
  • Filename
  • FinalNewline
  • FunKeywordSpacing
  • FunctionReturnTypeSpacing
  • FunctionSignature
  • FunctionStartOfBodySpacing
  • FunctionTypeReferenceSpacing
  • ImportOrdering
  • Indentation
  • KdocWrapping
  • MaximumLineLength
  • ModifierListSpacing
  • ModifierOrdering
  • MultiLineIfElse
  • NoBlankLineBeforeRbrace
  • NoBlankLinesInChainedMethodCalls
  • NoConsecutiveBlankLines
  • NoEmptyClassBody
  • NoEmptyFirstLineInMethodBlock
  • NoLineBreakAfterElse
  • NoLineBreakBeforeAssignment
  • NoMultipleSpaces
  • NoSemicolons
  • NoTrailingSpaces
  • NoUnitReturn
  • NoUnusedImports
  • NoWildcardImports
  • NullableTypeSpacing
  • PackageName
  • ParameterListSpacing
  • ParameterListWrapping
  • SpacingAroundAngleBrackets
  • SpacingAroundColon
  • SpacingAroundComma
  • SpacingAroundCurly
  • SpacingAroundDot
  • SpacingAroundDoubleColon
  • SpacingAroundKeyword
  • SpacingAroundOperators
  • SpacingAroundParens
  • SpacingAroundRangeOperator
  • SpacingAroundUnaryOperator
  • SpacingBetweenDeclarationsWithAnnotations
  • SpacingBetweenDeclarationsWithComments
  • SpacingBetweenFunctionNameAndOpeningParenthesis
  • StringTemplate
  • TrailingCommaOnCallSite
  • TrailingCommaOnDeclarationSite
  • TypeArgumentListSpacing
  • TypeParameterListSpacing
  • UnnecessaryParenthesesBeforeTrailingLambda
  • Wrapping
  • ForbiddenPublicDataClass
  • LibraryCodeMustSpecifyReturnType
  • LibraryEntitiesShouldNotBePublic
  • BooleanPropertyNaming
  • ClassNaming
  • ConstructorParameterNaming
  • EnumNaming
  • ForbiddenClassName
  • FunctionMaxLength
  • FunctionMinLength
  • FunctionNaming
  • FunctionParameterNaming
  • InvalidPackageDeclaration
  • LambdaParameterNaming
  • MatchingDeclarationName
  • MemberNameEqualsClassName
  • NoNameShadowing
  • NonBooleanPropertyPrefixedWithIs
  • ObjectPropertyNaming
  • PackageNaming
  • TopLevelPropertyNaming
  • VariableMaxLength
  • VariableMinLength
  • VariableNaming
  • ArrayPrimitive
  • CouldBeSequence
  • ForEachOnRange
  • SpreadOperator
  • UnnecessaryPartOfBinaryExpression
  • UnnecessaryTemporaryInstantiation
  • AvoidReferentialEquality
  • CastToNullableType
  • Deprecation
  • DontDowncastCollectionTypes
  • DoubleMutabilityForCollection
  • ElseCaseInsteadOfExhaustiveWhen
  • EqualsAlwaysReturnsTrueOrFalse
  • EqualsWithHashCodeExist
  • ExitOutsideMain
  • ExplicitGarbageCollectionCall
  • HasPlatformType
  • IgnoredReturnValue
  • ImplicitDefaultLocale
  • ImplicitUnitReturnType
  • InvalidRange
  • IteratorHasNextCallsNextMethod
  • IteratorNotThrowingNoSuchElementException
  • LateinitUsage
  • MapGetWithNotNullAssertionOperator
  • MissingPackageDeclaration
  • NullCheckOnMutableProperty
  • NullableToStringCall
  • UnconditionalJumpStatementInLoop
  • UnnecessaryNotNullCheck
  • UnnecessaryNotNullOperator
  • UnnecessarySafeCall
  • UnreachableCatchBlock
  • UnreachableCode
  • UnsafeCallOnNullableType
  • UnsafeCast
  • UnusedUnaryOperator
  • UselessPostfixExpression
  • WrongEqualsTypeParameter
  • AlsoCouldBeApply
  • CanBeNonNullable
  • CascadingCallWrapping
  • ClassOrdering
  • CollapsibleIfStatements
  • DataClassContainsFunctions
  • DataClassShouldBeImmutable
  • DestructuringDeclarationWithTooManyEntries
  • EqualsNullCall
  • EqualsOnSignatureLine
  • ExplicitCollectionElementAccessMethod
  • ExplicitItLambdaParameter
  • ExpressionBodySyntax
  • ForbiddenComment
  • ForbiddenImport
  • ForbiddenMethodCall
  • ForbiddenSuppress
  • ForbiddenVoid
  • FunctionOnlyReturningConstant
  • LoopWithTooManyJumpStatements
  • MagicNumber
  • MandatoryBracesIfStatements
  • MandatoryBracesLoops
  • MaxChainedCallsOnSameLine
  • MaxLineLength
  • MayBeConst
  • ModifierOrder
  • MultilineLambdaItParameter
  • MultilineRawStringIndentation
  • NestedClassesVisibility
  • NewLineAtEndOfFile
  • NoTabs
  • NullableBooleanCheck
  • ObjectLiteralToLambda
  • OptionalAbstractKeyword
  • OptionalUnit
  • OptionalWhenBraces
  • PreferToOverPairSyntax
  • ProtectedMemberInFinalClass
  • RedundantExplicitType
  • RedundantHigherOrderMapUsage
  • RedundantVisibilityModifierRule
  • ReturnCount
  • SafeCast
  • SerialVersionUIDInSerializableClass
  • SpacingBetweenPackageAndImports
  • ThrowsCount
  • TrailingWhitespace
  • TrimMultilineRawString
  • UnderscoresInNumericLiterals
  • UnnecessaryAbstractClass
  • UnnecessaryAnnotationUseSiteTarget
  • UnnecessaryApply
  • UnnecessaryBackticks
  • UnnecessaryFilter
  • UnnecessaryInheritance
  • UnnecessaryInnerClass
  • UnnecessaryLet
  • UnnecessaryParentheses
  • UntilInsteadOfRangeTo
  • UnusedImports
  • UnusedPrivateClass
  • UnusedPrivateMember
  • UseAnyOrNoneInsteadOfFind
  • UseArrayLiteralsInAnnotations
  • UseCheckNotNull
  • UseCheckOrError
  • UseDataClass
  • UseEmptyCounterpart
  • UseIfEmptyOrIfBlank
  • UseIfInsteadOfWhen
  • UseIsNullOrEmpty
  • UseOrEmpty
  • UseRequire
  • UseRequireNotNull
  • UseSumOfInsteadOfFlatMapSize
  • UselessCallOnNotNull
  • UtilityClassWithPublicConstructor
  • VarCouldBeVal
  • WildcardImport
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌鲨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值