Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ruby Code Analisis
Search
Dmitry Zhlobo
October 27, 2012
Programming
7
820
Ruby Code Analisis
Tools and practices make your ruby app clear.
Dmitry Zhlobo
October 27, 2012
Tweet
Share
More Decks by Dmitry Zhlobo
See All by Dmitry Zhlobo
Growing Rails Apps
dimazhlobo
1
140
Rails: The Good Parts
dimazhlobo
2
110
Ethereum Smart Contracts For Developers
dimazhlobo
0
93
Cross-origin resource sharing
dimazhlobo
1
74
Elasticsearch Introduction
dimazhlobo
0
730
Other Decks in Programming
See All in Programming
Swift Updates - Learn Languages 2025
koher
2
470
JSONataを使ってみよう Step Functionsが楽しくなる実践テクニック #devio2025
dafujii
1
520
為你自己學 Python - 冷知識篇
eddie
1
350
Compose Multiplatform × AI で作る、次世代アプリ開発支援ツールの設計と実装
thagikura
0
140
Flutter with Dart MCP: All You Need - 박제창 2025 I/O Extended Busan
itsmedreamwalker
0
150
さようなら Date。 ようこそTemporal! 3年間先行利用して得られた知見の共有
8beeeaaat
3
1.4k
TDD 実践ミニトーク
contour_gara
1
290
Ruby×iOSアプリ開発 ~共に歩んだエコシステムの物語~
temoki
0
270
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
330
AI Coding Agentのセキュリティリスク:PRの自己承認とメルカリの対策
s3h
0
200
FindyにおけるTakumi活用と脆弱性管理のこれから
rvirus0817
0
490
2025 年のコーディングエージェントの現在地とエンジニアの仕事の変化について
azukiazusa1
22
12k
Featured
See All Featured
Practical Orchestrator
shlominoach
190
11k
What's in a price? How to price your products and services
michaelherold
246
12k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
111
20k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
Producing Creativity
orderedlist
PRO
347
40k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
Agile that works and the tools we love
rasmusluckow
330
21k
Building Applications with DynamoDB
mza
96
6.6k
Visualization
eitanlees
148
16k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
A better future with KSS
kneath
239
17k
Transcript
Tools and Practices Ruby Code Analysis
None
Well known smells • long methods and large classes
Well known smells • long methods and large classes •
duplicated code
Well known smells • long methods and large classes •
duplicated code • too many parameters
Well known smells • long methods and large classes •
duplicated code • too many parameters • conditional complexity
Well known smells • long methods and large classes •
duplicated code • too many parameters • conditional complexity • etc...
None
None
ruby -w
$ ruby -w script.rb ruby -w
$ ruby -w script.rb enables verbose mode of ruby interpreter
ruby -w
$ ruby -w script.rb enables verbose mode of ruby interpreter
script.rb:4: warning: assigned but unused variable - file script.rb:11: warning: mismatched indentations at 'end' with 'def' at 7 ruby -w
ruby -w What about ?
ruby -w $ RUBYOPT=-w rails server 2>&1 | grep appname/app
ruby -w $ RUBYOPT=-w rails server 2>&1 | grep errbit/app
errbit/app/models/issue_trackers/github_issues_tracker.rb:38: warning: assigned but unused variable - options errbit/app/models/notice.rb:138: warning: shadowing outer local variable - h errbit/app/models/user.rb:6: warning: `*' interpreted as argument prefix errbit/app/models/watcher.rb:16: warning: method redefined; discarding old watcher_type errbit/app/controllers/apps_controller.rb:90: warning: mismatched indentations at 'end' with 'def' at 83 errbit/app/helpers/notices_helper.rb:72: warning: assigned but unused variable - file http://tinyurl.com/shelrtv-errbit-ruby-verbose
flog
$ flog app.rb flog
$ flog app.rb 311.4: flog total 13.6: flog/method average 73.4:
App#none 65.9: App#notify app.rb:124 42.1: App#attributes app.rb:142 flog
$ flog app.rb 311.4: flog total 13.6: flog/method average 73.4:
App#none 65.9: App#notify app.rb:124 42.1: App#attributes app.rb:142 flog
$ flog app.rb 311.4: flog total 13.6: flog/method average 73.4:
App#none 65.9: App#notify app.rb:124 42.1: App#attributes app.rb:142 flog
$ flog app.rb 311.4: flog total 13.6: flog/method average 73.4:
App#none 65.9: App#notify app.rb:124 42.1: App#attributes app.rb:142 flog
flog $ flog -g appname/app or $ flog -g appname/app/models
flog $ flog -g errbit/app/models 1690.0: flog total 11.1: flog/method
average 219.3: App total 88.4: App#none 60.5: App#notification_recipients errbit/app/models/app.rb:144 48.8: App#copy_attributes_from errbit/app/models/app.rb:153 21.7: App#check_issue_tracker errbit/app/models/app.rb:178 http://tinyurl.com/shelrtv-errbit-flog
flay analyzes code for similarities
$ flay app.rb flay
$ flay app.rb Total score (lower is better) = 266
1) IDENTICAL code found in :iter (mass*2 = 152) app.rb:16 app.rb:31 2) Similar code found in :defn (mass = 114) app.rb:74 app.rb:83 flay
None
None
brakeman warning types • Command Injection `ls #{params[:file]}`
brakeman warning types • Command Injection • SQL Injection username=params[:user][:name].downcase
password=params[:user][:password] User.first.where("username = '" + username + "' AND password = '" + password + "'")
brakeman warning types • Command Injection • SQL Injection •
Mass Assignment
brakeman warning types • Command Injection • SQL Injection •
Mass Assignment • Default Routes match ':controller(/:action(/:id(.:format)))'
brakeman warning types • Command Injection • SQL Injection •
Mass Assignment • Default Routes • File Access File.open("/tmp/#{cookie[:file]}")
brakeman warning types • Command Injection • SQL Injection •
Mass Assignment • Default Routes • File Access • Dangerous Send method = params[:method] @result = User.send(method.to_sym)
brakeman warning types • Command Injection • SQL Injection •
Mass Assignment • Default Routes • File Access • Dangerous Send See more in documentation.
$ brakeman shelr.tv -o report.html
rails-brakeman.com
rails_best_practices
rails-bestpractices.com
rails-bestpractices.com advices • Protect mass assignment • Not use time_ago_in_words
• Remove empty helpers • Always add DB index • Use Observer • Remove trailing whitespace
None
railsbp.com
What else • performance • tests and code coverage •
codeclimate
Resume ruby -w + flog + flay + brakeman =
Thank you @proghat github.com/proghat
[email protected]