rubocop 风格检查结果分析

rubocop 作为ruby代码检查工具,对规范代码风格有很强的作用。使用 -D 参数会显示错误类型,方便总结归类。 下面总结我遇到的一些问题及对策,也许还需要不断更新,也很希望能对大家有帮助,有问题也欢迎和我探讨。

message meaning
Style/UnneededInterpolation: Prefer to_s over string interpolation. 需要使用 to_s 来进行字符串插值,#中包含的内容要用to_s 转换。
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols 如果没有字符串插值,则使用单引号
Style/HashSyntax: Use the new Ruby 1.9 hash syntax. 使用ruby 1.9 的hash 语法 my_hash = { :key => 'value' }之类的 变成 my_hash =
Lint/UselessAssignment: Useless assignment to variable - iteration. 不必要的变量定义
Lint/AssignmentInCondition: Assignment in condition - you probably meant to use == 需要使用条件的地方,使用了赋值语句。while line = STDIN.gets {block } 会报错
Style/GlobalVars: Do not introduce global variables. 不要使用全局变量,尽量吧
Metrics/AbcSize: Assignment Branch Condition size for xxx is too high 某个函数的条件太复杂了
Metrics/CyclomaticComplexity: Cyclomatic complexity for xxx is too high 某个函数的圈复杂度太高了
Metrics/MethodLength: Method has too many lines. 某个方法定义的太长了
Metrics/PerceivedComplexity: Perceived complexity for function is too high 某个方法的感知复杂度太高了
Lint/HandleExceptions: Do not suppress exceptions. 不要禁止异常
Lint/RescueException: Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?
Lint/ScriptPermission: Script file array_2d.rb doesn't have execute permission. 某个文件没有执行权限 设置gitconfig 中 Filemode
Lint/StringConversionInInterpolation: Redundant use of Object#to_s in interpolation.
Shadowing outer local variable 代码块中,作为参数的变量名在代码块外出现过
Lint/UnreachableCode: Unreachable code detected. 检测到了不能到达的代码段
Lint/LiteralInCondition: Literal true appeared in a condition. 条件中不能包含字符串
Lint/NonLocalExitFromIterator: Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred 在非正常退出迭代器时,return 之后没有值
Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression. 圆括号会被解释为分组表达式 ,函数和参数括号之间不能有空格
Lint/RescueException: Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError? 希望不用Exception类

你可能感兴趣的:(rubocop 风格检查结果分析)