查看: 2940|回复: 8

[胡扯] 拿 Rubocop 对着 RGSS3 默认脚本玩了玩~

[复制链接]

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2014-11-16 14:09:14 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 taroxd 于 2014-11-16 14:21 编辑

Rubycop 是一个可以让强迫症发现 Ruby 代码的不规范之处的东西。

然后我就对着英文的默认脚本扫了一遍(因为如果用中文的,由于注释的原因必定有更多的问题)

扫描结果超过10000行,500KB。现截取 BattleManager 的扫描结果如下:
点击展开/收起
Inspecting 110 files
WCCCCWCCWWWWCWCCCWWWWCCWCCCCCCWWCCCCCWCCCWCCCCCCCCCCCCCCCCCCCCCCCCWCCCWCCCCCCCWCCCCCWCCCCCCCCCCWCWCWCCCCWCCCWC

Offenses:

BattleManager.rb:1:1: C: Use snake_case for source file names.
#==============================================================================
^
BattleManager.rb:1:1: C: Missing space after #.
#==============================================================================
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
BattleManager.rb:5:1: C: Missing space after #.
#==============================================================================
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
BattleManager.rb:7:1: C: Missing top-level module documentation comment.
module BattleManager
^^^^^^
BattleManager.rb:13:5: C: Do not introduce global variables.
    $game_troop.setup(troop_id)
    ^^^^^^^^^^^
BattleManager.rb:21:3: C: Method has too many lines. [11/10]
  def self.init_members
  ^^^
BattleManager.rb:45:5: C: Do not introduce global variables.
    $game_party.rate_preemptive($game_troop.agi)
    ^^^^^^^^^^^
BattleManager.rb:45:33: C: Do not introduce global variables.
    $game_party.rate_preemptive($game_troop.agi)
                                ^^^^^^^^^^^
BattleManager.rb:51:5: C: Do not introduce global variables.
    $game_party.rate_surprise($game_troop.agi)
    ^^^^^^^^^^^
BattleManager.rb:51:31: C: Do not introduce global variables.
    $game_party.rate_surprise($game_troop.agi)
                              ^^^^^^^^^^^
BattleManager.rb:64:5: C: Do not introduce global variables.
    $game_system.battle_bgm.play
    ^^^^^^^^^^^^
BattleManager.rb:71:5: C: Do not introduce global variables.
    $game_system.battle_end_me.play
    ^^^^^^^^^^^^
BattleManager.rb:77:28: C: Do not introduce global variables.
    @map_bgm.replay unless $BTEST
                           ^^^^^^
BattleManager.rb:78:28: C: Do not introduce global variables.
    @map_bgs.replay unless $BTEST
                           ^^^^^^
BattleManager.rb:84:33: C: Do not introduce global variables.
    @escape_ratio = 1.5 - 1.0 * $game_troop.agi / $game_party.agi
                                ^^^^^^^^^^^
BattleManager.rb:84:51: C: Do not introduce global variables.
    @escape_ratio = 1.5 - 1.0 * $game_troop.agi / $game_party.agi
                                                  ^^^^^^^^^^^
BattleManager.rb:107:3: C: Use attr_reader to define trivial reader methods.
  def self.can_escape?
  ^^^
BattleManager.rb:114:25: C: Do not introduce global variables.
    @actor_index >= 0 ? $game_party.members[@actor_index] : nil
                        ^^^^^^^^^^^
BattleManager.rb:129:41: C: Do not introduce global variables.
        return false if @actor_index >= $game_party.members.size
                                        ^^^^^^^^^^^
BattleManager.rb:131:9: W: Use Kernel#loop with break rather than begin/end/until(or while).
    end until actor.inputable?
        ^^^^^
BattleManager.rb:132:5: C: Redundant return detected.
    return true
    ^^^^^^
BattleManager.rb:143:9: W: Use Kernel#loop with break rather than begin/end/until(or while).
    end until actor.inputable?
        ^^^^^
BattleManager.rb:144:5: C: Redundant return detected.
    return true
    ^^^^^^
BattleManager.rb:149:3: C: Use attr_writer to define trivial writer methods.
  def self.event_proc=(proc)
  ^^^
BattleManager.rb:155:3: C: Use attr_writer to define trivial writer methods.
  def self.method_wait_for_message=(method)
  ^^^
BattleManager.rb:167:3: C: Method has too many lines. [12/10]
  def self.battle_start
  ^^^
BattleManager.rb:168:5: C: Do not introduce global variables.
    $game_system.battle_count += 1
    ^^^^^^^^^^^^
BattleManager.rb:169:5: C: Do not introduce global variables.
    $game_party.on_battle_start
    ^^^^^^^^^^^
BattleManager.rb:170:5: C: Do not introduce global variables.
    $game_troop.on_battle_start
    ^^^^^^^^^^^
BattleManager.rb:171:5: C: Do not introduce global variables.
    $game_troop.enemy_names.each do |name|
    ^^^^^^^^^^^
BattleManager.rb:172:7: C: Do not introduce global variables.
      $game_message.add(sprintf(Vocab::Emerge, name))
      ^^^^^^^^^^^^^
BattleManager.rb:172:25: C: Favor format over sprintf.
      $game_message.add(sprintf(Vocab::Emerge, name))
                        ^^^^^^^
BattleManager.rb:175:7: C: Do not introduce global variables.
      $game_message.add(sprintf(Vocab::Preemptive, $game_party.name))
      ^^^^^^^^^^^^^
BattleManager.rb:175:25: C: Favor format over sprintf.
      $game_message.add(sprintf(Vocab::Preemptive, $game_party.name))
                        ^^^^^^^
BattleManager.rb:175:52: C: Do not introduce global variables.
      $game_message.add(sprintf(Vocab::Preemptive, $game_party.name))
                                                   ^^^^^^^^^^^
BattleManager.rb:177:7: C: Do not introduce global variables.
      $game_message.add(sprintf(Vocab::Surprise, $game_party.name))
      ^^^^^^^^^^^^^
BattleManager.rb:177:25: C: Favor format over sprintf.
      $game_message.add(sprintf(Vocab::Surprise, $game_party.name))
                        ^^^^^^^
BattleManager.rb:177:50: C: Do not introduce global variables.
      $game_message.add(sprintf(Vocab::Surprise, $game_party.name))
                                                 ^^^^^^^^^^^
BattleManager.rb:192:33: C: Do not introduce global variables.
      return process_abort   if $game_party.members.empty?
                                ^^^^^^^^^^^
BattleManager.rb:193:33: C: Do not introduce global variables.
      return process_defeat  if $game_party.all_dead?
                                ^^^^^^^^^^^
BattleManager.rb:194:33: C: Do not introduce global variables.
      return process_victory if $game_troop.all_dead?
                                ^^^^^^^^^^^
BattleManager.rb:197:5: C: Redundant return detected.
    return false
    ^^^^^^
BattleManager.rb:205:5: C: Do not introduce global variables.
    $game_message.add(sprintf(Vocab::Victory, $game_party.name))
    ^^^^^^^^^^^^^
BattleManager.rb:205:23: C: Favor format over sprintf.
    $game_message.add(sprintf(Vocab::Victory, $game_party.name))
                      ^^^^^^^
BattleManager.rb:205:47: C: Do not introduce global variables.
    $game_message.add(sprintf(Vocab::Victory, $game_party.name))
                                              ^^^^^^^^^^^
BattleManager.rb:212:5: C: Redundant return detected.
    return true
    ^^^^^^
BattleManager.rb:217:3: C: Method has too many lines. [12/10]
  def self.process_escape
  ^^^
BattleManager.rb:218:5: C: Do not introduce global variables.
    $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
    ^^^^^^^^^^^^^
BattleManager.rb:218:23: C: Favor format over sprintf.
    $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
                      ^^^^^^^
BattleManager.rb:218:51: C: Do not introduce global variables.
    $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
                                                  ^^^^^^^^^^^
BattleManager.rb:225:7: C: Do not introduce global variables.
      $game_message.add('\.' + Vocab::EscapeFailure)
      ^^^^^^^^^^^^^
BattleManager.rb:226:7: C: Do not introduce global variables.
      $game_party.clear_actions
      ^^^^^^^^^^^
BattleManager.rb:229:5: C: Redundant return detected.
    return success
    ^^^^^^
BattleManager.rb:238:5: C: Redundant return detected.
    return true
    ^^^^^^
BattleManager.rb:243:3: C: Method has too many lines. [11/10]
  def self.process_defeat
  ^^^
BattleManager.rb:244:5: C: Do not introduce global variables.
    $game_message.add(sprintf(Vocab::Defeat, $game_party.name))
    ^^^^^^^^^^^^^
BattleManager.rb:244:23: C: Favor format over sprintf.
    $game_message.add(sprintf(Vocab::Defeat, $game_party.name))
                      ^^^^^^^
BattleManager.rb:244:46: C: Do not introduce global variables.
    $game_message.add(sprintf(Vocab::Defeat, $game_party.name))
                                             ^^^^^^^^^^^
BattleManager.rb:254:5: C: Redundant return detected.
    return true
    ^^^^^^
BattleManager.rb:260:5: C: Do not introduce global variables.
    $game_party.battle_members.each do |actor|
    ^^^^^^^^^^^
BattleManager.rb:271:5: C: Do not introduce global variables.
    $game_party.on_battle_end
    ^^^^^^^^^^^
BattleManager.rb:272:5: C: Do not introduce global variables.
    $game_troop.on_battle_end
    ^^^^^^^^^^^
BattleManager.rb:273:26: C: Do not introduce global variables.
    SceneManager.exit if $BTEST
                         ^^^^^^
BattleManager.rb:281:7: C: Do not introduce global variables.
      $game_party.make_actions
      ^^^^^^^^^^^
BattleManager.rb:282:7: C: Do not introduce global variables.
      $game_troop.make_actions
      ^^^^^^^^^^^
BattleManager.rb:285:5: C: Redundant return detected.
    return !@surprise && $game_party.inputable?
    ^^^^^^
BattleManager.rb:285:26: C: Do not introduce global variables.
    return !@surprise && $game_party.inputable?
                         ^^^^^^^^^^^
BattleManager.rb:293:5: C: Do not introduce global variables.
    $game_troop.increase_turn
    ^^^^^^^^^^^
BattleManager.rb:308:8: C: Do not introduce global variables.
    if $game_troop.exp_total > 0
       ^^^^^^^^^^^
BattleManager.rb:309:14: C: Favor format over sprintf.
      text = sprintf(Vocab::ObtainExp, $game_troop.exp_total)
             ^^^^^^^
BattleManager.rb:309:40: C: Do not introduce global variables.
      text = sprintf(Vocab::ObtainExp, $game_troop.exp_total)
                                       ^^^^^^^^^^^
BattleManager.rb:310:7: C: Do not introduce global variables.
      $game_message.add('\.' + text)
      ^^^^^^^^^^^^^
BattleManager.rb:317:8: C: Do not introduce global variables.
    if $game_troop.gold_total > 0
       ^^^^^^^^^^^
BattleManager.rb:318:14: C: Favor format over sprintf.
      text = sprintf(Vocab::ObtainGold, $game_troop.gold_total)
             ^^^^^^^
BattleManager.rb:318:41: C: Do not introduce global variables.
      text = sprintf(Vocab::ObtainGold, $game_troop.gold_total)
                                        ^^^^^^^^^^^
BattleManager.rb:319:7: C: Do not introduce global variables.
      $game_message.add('\.' + text)
      ^^^^^^^^^^^^^
BattleManager.rb:320:7: C: Do not introduce global variables.
      $game_party.gain_gold($game_troop.gold_total)
      ^^^^^^^^^^^
BattleManager.rb:320:29: C: Do not introduce global variables.
      $game_party.gain_gold($game_troop.gold_total)
                            ^^^^^^^^^^^
BattleManager.rb:328:5: C: Do not introduce global variables.
    $game_troop.make_drop_items.each do |item|
    ^^^^^^^^^^^
BattleManager.rb:329:7: C: Do not introduce global variables.
      $game_party.gain_item(item, 1)
      ^^^^^^^^^^^
BattleManager.rb:330:7: C: Do not introduce global variables.
      $game_message.add(sprintf(Vocab::ObtainItem, item.name))
      ^^^^^^^^^^^^^
BattleManager.rb:330:25: C: Favor format over sprintf.
      $game_message.add(sprintf(Vocab::ObtainItem, item.name))
                        ^^^^^^^
BattleManager.rb:338:5: C: Do not introduce global variables.
    $game_party.all_members.each do |actor|
    ^^^^^^^^^^^
BattleManager.rb:339:22: C: Do not introduce global variables.
      actor.gain_exp($game_troop.exp_total)
                     ^^^^^^^^^^^
BattleManager.rb:348:25: C: Do not introduce global variables.
    @action_battlers += $game_party.members unless @surprise
                        ^^^^^^^^^^^
BattleManager.rb:349:25: C: Do not introduce global variables.
    @action_battlers += $game_troop.members unless @preemptive
                        ^^^^^^^^^^^
BattleManager.rb:350:5: C: Pass &:make_speed as an argument to each instead of a block.
    @action_battlers.each {|battler| battler.make_speed }
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
BattleManager.rb:350:27: C: Space between { and | missing.
    @action_battlers.each {|battler| battler.make_speed }
                          ^^
BattleManager.rb:351:28: C: Space between { and | missing.
    @action_battlers.sort! {|a,b| b.speed - a.speed }
                           ^^
BattleManager.rb:351:31: C: Space missing after comma.
    @action_battlers.sort! {|a,b| b.speed - a.speed }
                              ^
BattleManager.rb:369:3: C: Use attr_reader to define trivial reader methods.
  def self.action_forced_battler
  ^^^


完整的扫描结果见附件: rubycop.rar (45.23 KB, 下载次数: 34)

注:这只是玩玩,并不是要否定预设脚本什么的

评分

参与人数 1星屑 +30 收起 理由
机械守护者 + 30 只看标题还以为是876呢

查看全部评分

梦石
1
星屑
23246
在线时间
9564 小时
注册时间
2012-6-19
回帖
7018

开拓者短篇九导演组冠军

发表于 2014-11-16 14:51:02 | 显示全部楼层
看标题猜楼主系列…………

一片的冗余return啊……

点评

我挺喜欢加个return的,话说,感觉那样好看  发表于 2014-11-16 14:59
一片 global_variable,一片 {|args| args } 左边没加空格 = =  发表于 2014-11-16 14:52
回复

使用道具 举报

梦石
0
星屑
2310
在线时间
5539 小时
注册时间
2011-1-10
回帖
6353

青铜编剧史诗剧作家剧作品鉴家

发表于 2014-11-16 14:52:32 | 显示全部楼层
大触们的世界
回复

使用道具 举报

寒

梦石
0
星屑
1049
在线时间
1391 小时
注册时间
2010-8-9
回帖
3301
发表于 2014-11-16 14:56:47 | 显示全部楼层
竟然还有这东西……
RGSS外置的默认脚本哪里问题?是不是没找到RGSS的内置?

点评

所以Rubocop就是一个强迫症的东西= =  发表于 2014-11-16 15:09
= =那么强迫干哈,,return神马的喜欢就加上也很好的,,反正ruby提供了多种可能  发表于 2014-11-16 15:02
没有问题,只是代码风格不符合强迫症的要求  发表于 2014-11-16 14:59
回复

使用道具 举报

梦石
0
星屑
1691
在线时间
2205 小时
注册时间
2010-6-27
回帖
1259
发表于 2014-11-16 14:58:34 | 显示全部楼层
强迫症去死

于是我也广告下…
回复

使用道具 举报

梦石
0
星屑
122
在线时间
552 小时
注册时间
2012-8-18
回帖
1392
发表于 2014-11-16 15:19:04 | 显示全部楼层
嗯……这玩意可以自己设置如何强迫症吗
我要填坑!我要背单词!我要学日语!我要每天锻炼!
好吧呵呵= =
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

 楼主| 发表于 2014-11-16 15:27:29 | 显示全部楼层
无脑之人 发表于 2014-11-16 15:19
嗯……这玩意可以自己设置如何强迫症吗

貌似可以呢~

https://github.com/bbatsov/rubocop
回复

使用道具 举报

无限の剣制

梦石
0
星屑
10450
在线时间
5019 小时
注册时间
2013-2-28
回帖
4942

开拓者贵宾

发表于 2014-11-16 15:31:44 | 显示全部楼层
原来泥说的做死卖个萌是指这样啊。
回复

使用道具 举报

梦石
0
星屑
9292
在线时间
2504 小时
注册时间
2011-5-20
回帖
14521

开拓者

发表于 2014-11-16 15:53:34 | 显示全部楼层
查错的东西?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部