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
Handle Slim Safety
Search
ydah
September 09, 2023
Technology
0
670
Handle Slim Safety
大阪Ruby会議03 LT 「Handle Slim Safety」のスライド
https://regional.rubykaigi.org/osaka03/
#osrb03
ydah
September 09, 2023
Tweet
Share
More Decks by ydah
See All by ydah
作って理解する RDBMSのしくみ
ydah
21
5.8k
How does Lrama make the Ruby parser grammar G.O.A.T.?
ydah
2
130
The Sequel to a Dream of Ruby Parser's Grammar
ydah
1
260
Kaigi Effect
ydah
0
66
Does Ruby Parser dream of highly expressive grammar?
ydah
3
1.2k
Extracting from rubocop-rspec
ydah
0
100
Ruby Parser Basics
ydah
0
210
Menhir is here!
ydah
1
5.5k
ほんとにあった怖い話「slimに棲むもの」
ydah
0
1.3k
Other Decks in Technology
See All in Technology
Windows Autopilot Deployment by OSD Guy
tamaiyutaro
0
370
音声×Copilot オンコパの世界
kasada
1
120
ジョブマッチングサービスにおける相互推薦システムの応用事例と課題
hakubishin3
3
650
20241108_CS_LLMMT
shigashiyama
0
260
メールサーバ管理者のみ知る話
hinono
1
110
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
150
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
140
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
2
1.1k
B2B SaaS × AI機能開発 〜テナント分離のパターン解説〜 / B2B SaaS x AI function development - Explanation of tenant separation pattern
oztick139
0
110
Lexical Analysis
shigashiyama
1
140
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
27
7.2k
利きプロセススケジューラ
sat
PRO
4
2.7k
Featured
See All Featured
Facilitating Awesome Meetings
lara
50
6.1k
Done Done
chrislema
181
16k
Speed Design
sergeychernyshev
24
610
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Visualization
eitanlees
145
15k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Bash Introduction
62gerente
608
210k
YesSQL, Process and Tooling at Scale
rocio
168
14k
Why Our Code Smells
bkeepers
PRO
334
57k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Code Reviewing Like a Champion
maltzj
520
39k
Transcript
Yudai Takada Osaka RubyKaigi 03 2023.09.09 (Sat) Handle Slim Safety
ɾName: Yudai Takada ɾGitHub: @ydah ɾX: @ydah_ ɾMember of RuboCop
RSpec team ɾSoftware Engineer at ANDPAD, Inc. self.inspect
Handle Slim Safety
What is Slim?
4MJN3BJMTҎ߱ʹରԠͨ͠ߴ ܰྔͳςϯϓϨʔτΤϯδϯͰ͢ɻओ ཁͳ3VCZͷ࣮શͯͰ͔ͬ͠Γςετ͞Ε͍ͯ·͢ɻࢲͨͪܧଓతΠϯ ςάϨʔγϣϯΛ࠾༻͍ͯ͠·͢ɻ HJUIVCBDUJPOT 4MJNͷ֩ͱͳΔߏจͭͷߟ͑ʹΑͬͯಋ͔Ε͍ͯ·͢͜ͷಈ࡞Λߦ͏ ͨΊʹ࠷ݶඞཁͳͷԿ͔ɻଟ͘ͷਓʑͷ4MJNͷߩݙʹΑͬͯ ൴Β ͕͏)BNM+BEFͷӨڹΛड͚ߏจͷՃ͕ߦΘΕ͍ͯ·͢ɻ4MJNͷ
։ൃνʔϜඒݟΔਓͷͷதʹ͋Δ͜ͱΛ͍ͬͯΔͷͰɺ͜͏͍ͬͨ ՃʹΦʔϓϯͰ͢ɻ 4MJNߏจղੳίϯύΠϧʹ5FNQMFΛ͍5JMUʹΈࠐ·Ε·͢ɻ͜Ε ʹΑΓ4JOBUSBϓϨʔϯͳ3BDLͱҰॹʹ͑·͢ɻ
doctype html html head title My Slim Template body ruby:
message = "Slim!" h1 Welcome to #{ message} p This is a simple example. ͜͏͍͏ͭ
҆શʹ͔͋ͭ͏
doctype html html head title My Slim Template body ruby:
message = "Slim!" h1 Welcome to #{ message} p This is a simple example. ࠓͷλʔήοτ ˡ͜͜
͜ΕԿʁ Embedded engines: Tiltͷ͓͔͛ͰɺSlim ଞͷςϯ ϓϨʔτΤϯδϯͷຒΊࠐΈʹݟࣄʹ ରԠ͍ͯ͠·͢ɻ Ruby,JavaScript,css,sass…etc
҆શʹ͔͋ͭ͏
ຒΊࠐΈͷίϝϯτ doctype html html head title My Slim Template body
h1 Welcome to Slim! javascript: // comment alert("Hello, World!");
ίϯύΠϧޙ <!DOCTYPE html> <html> <head> <title>My Slim Template </ title>
< / head> : </ html> <script> / / mecha kimitsu joho alert("Hello, World!"); </ script> ݟΒΕͨ͘ͳ͍ίϝϯτ ݟΒΕͯ͠·͏
ࢼߦࡨޡ %BOHFS4FNHSFQͰܯࠂ͢Δʁ ⭕ϧʔϧΛՃ͢Δ͚ͩͰྑ͍ ❌ίϝϯτॻ͚ͩ͘ͰܯࠂͭΒͦ͏ ❌ܯࠂΛݟམͱ͞ΕΔͱҙຯ͕ͳ͍
ͭͬͨ͘ ZEBITMJNFNCFEEFENJOJGZ
slim-embedded-minify module Slim class Embedded < Filter class TagEngine <
Engine prepend Minify::Tag end class JavaScriptEngine < TagEngine prepend Minify::Javascript end ennd
slim-embedded-minify module Slim class Embedded < Filter module Minify module
Javascript include Tag def on_slim_embedded(engine, body, attrs) mini fi ed_body = minify(body) super(engine, mini fi ed_body, attrs) end ennnnd
slim-embedded-minify ⭕ίϝϯτ͕ࣗ༝ʹॻ͚Δ ⭕Ճআ͔ΜͨΜ ⭕ίϯύΠϧ݁ՌΛൺֱͯ͠ίϝϯτ ͷΈ͕ফ͍͑ͯΔ͔ʹΑͬͯ֬ೝՄ
Its safe now
੩తղੳʹ͍ͭͯ
3VCP$PQͰղੳෆՄ 4MJN3VCZͰͳ͍ͷͰɺ 4ZOUBY&SSPSʹͳΔ ͦΕͦ͏ spec/f i xtures/dummy.slim:1 : 5 :
F : Lint/ Syntax: unexpected token tCOLON (Using Ruby 2.7 parser; conf i gure using TargetRubyVersion parameter, under AllCops) ruby: ^
ຒΊࠐΈҎ֎ͷTMJ̼ ੩తղੳπʔϧ͋Γ·͢ •r7kamura/slimcop •r7kamura/rubocop - slim ͕ɺຒΊࠐΜͰ͍ΔRubyίʔυͷ੩త ղੳग़དྷͳ͍
ຒΊࠐΈͷTMJ̼ ੩తղੳπʔϧ͋Γ·͢ •sds/slim - lint ͕ɺautocorrectग़དྷͳ͍
͍ͭͬͨͯ͘Δ ZEBITMJNFNCFEDPQ ❌
slimembedcop html ruby: if File.exists?("foo.txt") message = "Yay!" else message
= "Nooo!" end h1 #{ message} Γग़ͯ͠3VCP$PQʹͯ͠ ղੳͯ͠Β͏
slimembedcop ❯ slimembedcop dummy.slim Inspecting 1 f i le W
Offenses: dummy.slim:3 : 8 : W : [Correctable] Lint/ DeprecatedClassMethods: File.exists? is deprecated in favor of File.exist ?. if File.exists?("foo.txt") ^^^^^^^^^^^^
⭕3VCP$PQͷطଘͷDPQ͕͑Δ ⭕ࣗಈमਖ਼ʹରԠ͍ͯ͠Δ ⭕DPQ͕࡞ΕΔʹTMJNFNCFEDPQͷ DPQ࡞ΕΔ slimembedcop
We got static analysis
ීஈԿؾͳ͍ͬͯ͘Δͷʹվળ ͷ༨ҙ֎ͱ͍ͬͯΔͷͰɺͲΜ ͲΜվળͯ͠ɺͲΜͲΜͤʹͳͬͯ ͍͖·͠ΐ͏ʂʂ ·ͱΊ
end