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
690
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
たのしいparse.y
ydah
3
120
作って理解する RDBMSのしくみ
ydah
21
6.3k
How does Lrama make the Ruby parser grammar G.O.A.T.?
ydah
2
150
The Sequel to a Dream of Ruby Parser's Grammar
ydah
1
280
Kaigi Effect
ydah
0
84
Does Ruby Parser dream of highly expressive grammar?
ydah
3
1.3k
Extracting from rubocop-rspec
ydah
0
110
Ruby Parser Basics
ydah
0
240
Menhir is here!
ydah
1
5.8k
Other Decks in Technology
See All in Technology
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
250
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
31k
AWS re:Invent 2024 ふりかえり
kongmingstrap
0
130
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
250
C++26 エラー性動作
faithandbrave
2
650
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
510
ガバメントクラウドのセキュリティ対策事例について
fujisawaryohei
0
520
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
150
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
Storage Browser for Amazon S3
miu_crescent
1
110
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
520
39k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
94
Being A Developer After 40
akosma
87
590k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
GraphQLとの向き合い方2022年版
quramy
44
13k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
RailsConf 2023
tenderlove
29
940
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Typedesign – Prime Four
hannesfritz
40
2.4k
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