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类
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,603评论 25 709
  • 一、异同对比选择1、Python和ruby的相同点: * 都强调语法简单,都具有更一般的表达方式。python是缩...
    沃伦盖茨阅读 9,626评论 2 24
  • 时间:2017年8月14日 地点:天津公寓 作者:阮博杰 【我怎么如此幸运】 一.我怎么如此幸运,面对古哥的质问,...
    阮博杰阅读 1,384评论 0 1
  • 树叶如雪,霜满西楼。 妃白袍如月,长袖飘飘,舞弄春秋。 战鼓低吼,军士静默, 孩童手提银钩。 我轻咳,城外铁甲洪流...
    忘苏阅读 3,077评论 0 0