RuboCopã®ABC Sizeãã§ãã¯ã«ã¤ãã¦èª¿ã¹ã
æ¦è¦
â»ãã®è¨äºã¯RuboCop v0.28.0ã対象ã§ãã
https://github.com/bbatsov/rubocop/tree/v0.28.0
Assignment Branch Condition size for method_name is too high. [15.33/15]
RuboCopã使ã£ã¦ãã¦ããããªè¦åãåºã¦å°ã£ãã®ã§èª¿ã¹ãçµæãã¾ã¨ãã¾ããã
ããã¯ABC Size
ã¨ãããã§ãã¯é
ç®ã§ãããã¤ã¾ãã¨
- Assignment : å¤æ°ã¸ã®ä»£å ¥
- Branch : ã¡ã½ããå¼ã³åºã
- Condition : æ¡ä»¶æ
ä¸è¨3é
ç®ã®åè¨ãã¤ã³ããRuboCopåãè¨ç®ãã¦ãåºæºå¤ãè¶
ããã¨è¦åãåºããã¨ããä»çµã¿ã
RuboCopãRubyç¹æã®ãã§ãã¯ã§ã¯ãªããAbc Metricã¨ãã£ã¦æãããããã®ãããã
ã¡ãªã¿ã«ãããããã®é æåãã¨ã£ã¦ABC
ã¨ã®ãã¨ã
åºæºå¤
ããã©ã«ãã¯15ãã¤ã³ãã
Metrics/AbcSize: # The ABC size is a calculated magnitude, so this number can be a Fixnum or # a Float. Max: 15
https://github.com/bbatsov/rubocop/blob/v0.28.0/config/default.yml#L539
.rubocop.yml
ã§ãã§ãã¯æç¡ã¨åºæºå¤ã®è¨å®å¤æ´å¯è½ã
Max: 0
ã§é©ç°ã®ãMè¨å®ã«ã
ãã¡ããMax: 20
ã¨ãã«ãã¦ç·©ããããã¨ãã§ããã
Metrics/AbcSize: Enabled: true Max: 0
è¨ç®æ¹æ³
â»a, b, cã¯ããããã®ãã§ãã¯é ç®å ã§å¼ã£ããã£ãæ°
Math.sqrt(a**2 + b**2 + c**2).round(2)
https://github.com/bbatsov/rubocop/blob/v0.28.0/lib/rubocop/cop/metrics/abc_size.rb#L22
åãã§ãã¯é ç®ã«ã¤ãã¦
(A)ssignment : å¤æ°ã¸ã®ä»£å ¥
å¤æ°ã¸ã®ä»£å ¥ç®æã®æ°ããã§ãã¯ããã
ãã§ãã¯å¯¾è±¡é ç® | ä¾ |
---|---|
ãã¼ã«ã«å¤æ°ã¸ã®ä»£å ¥ | var = 10 |
ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã¸ã®ä»£å ¥ | @var = 10 |
ã¯ã©ã¹å¤æ°ã¸ã®ä»£å ¥ | @@var = 10 |
ã°ãã¼ãã«å¤æ°ã¸ã®ä»£å ¥ | $var = 10 |
å®æ°ã¸ã®ä»£å ¥ | Bar::Foo = 10 |
å¤éä»£å ¥ | foo, bar = 1, 2 |
èªå·±ä»£å ¥ | a += 1 ,a -= 1 |
èªå·±ä»£å ¥(è«çæ¼ç®å) | a ||= 1 ,a &&= 1 |
(B)ranch : ã¡ã½ããå¼ã³åºã
ä¾:
Math.new Math.sqrt(3)
(C)ondition : æ¡ä»¶æ
ä¸è¨ãã¼ã¯ã¼ãã対象:
if
,while
,until
,for
,rescue
,when
,and
,or
åè
http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Operators