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
650
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
How does Lrama make the Ruby parser grammar G.O.A.T.?
ydah
2
97
The Sequel to a Dream of Ruby Parser's Grammar
ydah
1
230
Kaigi Effect
ydah
0
53
Does Ruby Parser dream of highly expressive grammar?
ydah
3
1.1k
Extracting from rubocop-rspec
ydah
0
86
Ruby Parser Basics
ydah
0
170
Menhir is here!
ydah
1
5.1k
ほんとにあった怖い話「slimに棲むもの」
ydah
0
1.3k
The Labyrinth of How to Write RSpec Pending Reasons
ydah
0
97
Other Decks in Technology
See All in Technology
Create Inquiry via Bedrock / 生成 AI で問い合わせ品質は変わるのか?思いついてぱっと作ったものを供養してみる
kazzpapa3
1
190
Report of JAWS PANKRATION 2024, a global online event using Amazon IVS
yoshimi0227
1
130
AWSへのNIST SP800-171管理策 導入に向けての整備/20240930 Mitsutoshi Matsuo
shift_evolve
0
140
All your memory are belong to… whom?
ennael
PRO
0
510
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
2
200
VS CodeでF1〜12キーつかってますか? / Do you use the F1-12 keys in VS Code?
74th
1
250
GitHub Actions/Docker/Terraform/Renovate で最小限の Monorepo CD パイプラインを作る / Minimalistic Monorepo CD Pipeline with GitHub Actions, Docker, Terraform and Renovate
yuyatakeyama
4
340
RAGの性能を評価しよう
kurahara
1
270
k6を活用した再現性・拡張性の高い負荷試験基盤の構築
biwashi
11
2.8k
【ログ分析勉強会】EDR ログで内部不正を検出できるのか、Copilot に聞いてみた
hssh2_bin
2
260
Understanding and Optimising INP
akshayysharma
0
150
不感対策ソリューション
jtes
0
230
Featured
See All Featured
In The Pink: A Labor of Love
frogandcode
139
22k
Speed Design
sergeychernyshev
22
460
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
354
29k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
27
7.5k
Optimizing for Happiness
mojombo
375
69k
What the flash - Photography Introduction
edds
67
11k
Design by the Numbers
sachag
277
19k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Imperfection Machines: The Place of Print at Facebook
scottboms
263
13k
A Tale of Four Properties
chriscoyier
155
22k
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