# RepChain_Linter **Repository Path**: BTAJL/RepChain_Linter ## Basic Information - **Project Name**: RepChain_Linter - **Description**: 基于Linter开发的RepChain代码静态分析工具 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2019-06-12 - **Last Updated**: 2022-03-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # RepChain_Linter ## 1. 介绍   由中国科学院软件研究所基于Linter开发的RepChain代码静态分析工具 ## 2. 软件架构 #### 1. 错误及错误说明 错误名|错误说明 -|- UnextendedSealedTrait | sealed trait从来没有被继承过,sealed规定修饰的trait只能在当前文件里面被继承 UnlikelyEquality | 两个比较的对象类型不一样 UseLog1p | 使用math.log1p(x)取代math.log(1+x) UseLog10 | 使用math.log10(x)取代log(x)/log(10) UseExpm1 | 使用math.expm1取代math.exp(x)-1 UseHypot | 使用math.hypot取代sqrt(x^2+y^2) UseCbrt | 使用math.cbrt(x)取代pow(x,1/3) UseSqrt | 使用math.sqrt(x)取代pow(x,1/2) SuspicioutPow | pow中的幂不正确 UseExp | 使用math.exp(x)取代pow(E,x) UseAbsNotSqrtSquare | 使用math.abs(x)取代math.sqrt(x^2) UseIsNanNotSelfComparison | 使用x.isNan取代x和自己比较 UseIsNanNotNanComparison | 使用x.isNan,Nan==Nan返回false UseSignum | 是否在这里使用符号函数 BigDecimalNumberFormat | BigDecimal构造器可能会抛出NumberFormatException BigDecimalPrecisionLoss | 可能会损失精度 ReflexiveAssignment | 自己给自己赋值 CloseSourceFile | 文件流在使用后需要关闭 JavaConverters | 使用collection.JavaConverters取代collection.JavaConversions ContainsTypeMismatch | a.contains(b)中,a包含的类型和b不同 NumberInstanceOf | 使用toType取代asInstanceOf进行类型转换 PatternMatchConstant | 对常量进行类型匹配 PerferIfToBooleanMatch | 对布尔类型使用if取代类型匹配 IdenticalCaseBodies | 两个case内的代码一样,可以被合并 IdenticalCaseConditions | 两个case的匹配内容一样 ReflexiveComparson | compare的两个表达式一样 YodaConditions | yoda表达式,那常量和变量比较,提倡的是变量和常量比较 UseConditionDirectly | 在条件语句中直接使用布尔变量,而不使用if(Boolean == false/true) UseIfExpression | 直接将if语句的返回值赋给变量 UnnecessaryElseBranch | 一条分支永远不可达 DuplicateIfBranches | if语句的两个分支中表达式相同 IdenticalIfElseCondition | 这种情况在之前的if-else中出现过,在这个分支中不会出现 MergeNestedIfs | 这两个嵌套的if语句可以合并为一个 VariableAssignedUnusedValue | 在这次赋值之前,这个变量中的值没有被使用过 MalFormedSwap | 交换两个变量的值 IdenticalIfCondition | 两个连续的if语句有相同的判断条件 IdenticalStatements | 两个连续的相同的表达式 IndexingWithNegativeNumber | 对集合使用了负值索引 OptionOfOption | Option中嵌套Option UndesirableTypeInference | 这个类型推断可能出错 AssigningOptionToNull | 赋值可能是None而不是null WrapNullWithOption | 用Option替换if,Option将null包装为None AvoidOptionStringSize | 获取Option中string的长度 AvoidOptionCollectionSize | 获取Option中collection的大小 UseGetOrElseOnOption | 对于Option,使用getgetOrElse而不是orElse UseOptionOrNumm | 对于Option,orNull或者getOrElse取代get else null UseExistsNotFindIsDefined | 取代isDefined UseExistsNotFilterIsEmpty | map中使用case取代filter UseFindNotFilterHead | 使用filter取代find UseContainsNotExistsEquals | 使用contains取代.exist(val1 == val2) UseQuantifierFuncNotFold | var.func可以被var.method替换 UseFuncNotReduce | 使用var.f替换var.func UseFuncNotFold | 使用var.f替换var.func MergeMaps | 合并两个map操作 FuncFirstThenMap | 先使用method再使用map FilterFirstThenSort | 先过滤再排序 UseMinOrMaxNorSort | 使用最大最小值而不是排序 UseMapNotFlatMap | 使用Map取代flagMap UseFilterNotFlatMap | 使用filter取代FlatMap AvoidOptionMethod | 避免Option.method TransformNotMap | 使用transform取代map DuplicateKeyInMap | 这个键已经在map中,添加会覆盖之前的值 InefficientUseOfListSize | 对于表用其它方法更快 OnceEvaluatedStatementsInBlockReturningFuction | 你传递了一个返回值为函数的block,除了最后一个语句,其他语句只会被执行一次 IntDivisionAssignedToFloat | 整数除法的值被赋值给浮点数 UseFlattenNotFilterOption | 使用flatten取代var.func.map UseCountNotFilterLength | 使用count取代filter().func UseExistsNotCountCompare | 使用exists取代.count.compare PassPartialFunctionDirectly | 可以传递部分函数 UnitImplicitOrdering | 这个函数永远返回第一个元组 RegexWarning | 正则表达式有误 InvariantCondition | 表达式恒为真/假 DecomposingEmptyCollection | 空集合操作 InvariantExrema | 永远返回极值 UnecessaryMethodCall | 方法是冗余代码 ProducesEmptyCollecion | 永远产生空集合 OperationAlwaysProducesZero | 这个操作永远产生0 ModuloByOne | 模1返回0 DivideByOne | 除以1返回自己 DivideByZero | 除数为0 ZeroDivideBy | 被除数为0 UseUntilNotToMinusOne | 使用low until high取代low to high-1 InvalidParamToRandomNextInt | .nextInt可能低于1 UnusedForLoopIteratorValue | Iterator没有在循环中使用 StringMultiplicationByNonPositive | string乘以0将返回空string LikelyIndexOutofBounds | 可能越界 UnecessaryReturn | 不需要使用return InvariantReturn | 这一段永远返回相同值 UnusedParameter | parameter没有在方法中使用 InvalidStringFormat | string format 会抛出异常 InvalidStringConversion | string conversion 可能会失败 UnecessaryStringNonEmpty | string从来不会为空 UnecessaryStringIsEmpty | string永远为空 PossibleLossOfPrecision | 可能会损失精度 UnsafeAbs | 使用abs不安全 TypeToType | toType和原类型相同 EmptyStringInterpolator | 字符串插值没有参数 UnlikelyToString | toString可能没有被定义 UnthrowException | 可能需要抛出异常 SuspicioutMatches | 匹配可能错误 PassingNullIntoOption | 在Option中加入Null可能是错误 IfDoWhile | if和do-while循环条件一样,可以使用while FloatingPointNumbericRange | 数字范围不使用float UseInitNotReverseTailReverse | init取代reverse.tail.reverse UseTakeRightNotReverseTakeReverse | takeRight取代reverse.take.reverse UseLastNotReverseHead | last取代reverse.head UseFuncNotReverse | reverse(func)取代reverse.func UseHeadNotApply | head取代var(0) UseLastNotApply | last取代var(var.length-1) UseHeadOptionNotIf | var.headOption取代Some var.head else None UseLastOptionNotIf | var.lastOption取代Some var.last else None UseZipWithIndexNotZipIndices | var.zipWithIdex取代var.zip(var.indices) UseGetOrElseNotPatMatch | getOrElse取代match{Smoe(x) => x; None => exp} UseOptionFlatMapNotPatMatch | flatMap(expr)取代match{Smoe(x) => Some(x); None => exp} UseOptionMapNotPatMatch | map取代match{Smoe(x) => exp; None => None} UseOptionFlattenNotPatMatch | flattne取代match{Smoe(x) => x; None => None} UseOptionForeachNotPatMatch | foreach取代match{Smoe(x) => exp; None => {}} UseOptionIsDefinedNotPatMatch | isDefined取代match{Some(x) => true; None => false} UseOptionIsEmptyNotPatMatch | isEmpty取代match{Some(x) => false; None => true} UseOptionForallNotPatMatch | forall取代match{Some(x) => true; None => $expr} UseOptionExistsNotPatMatch | exists取代match{Some(x) => false; None => $expr} UseNoAbsolutePath | 对方法和静态类的调用需要全路径或者全路径导入 UseLocalTimeOrRandomInIcontract | 在继承了Icontract中使用了本地时间或者随机数 InheritBesidesIcontract | 继承了Icontract外还继承了其它接口 UseAnyTypeInCaseClass | 在case class中使用了any类型 CaseClassInIContract | 不能在合约类中定义而不使用case class NotDefineInIContract | 在合约类中使用的case class没有在合约类中定义 ## 3. 安装教程   参考博客 https://blog.csdn.net/leo3070/article/details/80040400   1. 安装jdk和scala开发环境。   2. 安装sbt插件,并根据需要修改代理仓库。   3. sbt shell使用命令进行构建。 ## 4. 使用说明   1. 在项目的build.sbt中加入。其中,Xplugin后填写linter.jar的路径。 ``` scalacOptions += "-Xplugin:absolutePath\\RepChainLinter.jar" ```   2. 编译整个项目。