Slide 1

Slide 1 text

Yudai Takada Osaka RubyKaigi 03 2023.09.09 (Sat) Handle Slim Safety

Slide 2

Slide 2 text

ɾName: Yudai Takada ɾGitHub: @ydah ɾX: @ydah_ ɾMember of RuboCop RSpec team ɾSoftware Engineer at ANDPAD, Inc. self.inspect

Slide 3

Slide 3 text

Handle Slim Safety

Slide 4

Slide 4 text

What is Slim?

Slide 5

Slide 5 text

4MJN͸3BJMTҎ߱ʹରԠͨ͠ߴ଎ ܰྔͳςϯϓϨʔτΤϯδϯͰ͢ɻओ ཁͳ3VCZͷ࣮૷શͯͰ͔ͬ͠Γςετ͞Ε͍ͯ·͢ɻࢲͨͪ͸ܧଓతΠϯ ςάϨʔγϣϯΛ࠾༻͍ͯ͠·͢ɻ HJUIVCBDUJPOT 4MJNͷ֩ͱͳΔߏจ͸ͭͷߟ͑ʹΑͬͯಋ͔Ε͍ͯ·͢͜ͷಈ࡞Λߦ͏ ͨΊʹ࠷௿ݶඞཁͳ΋ͷ͸Կ͔ɻଟ͘ͷਓʑͷ4MJN΁ͷߩݙʹΑͬͯ ൴Β ͕࢖͏)BNM΍+BEFͷӨڹΛड͚ߏจͷ௥Ճ͕ߦΘΕ͍ͯ·͢ɻ4MJNͷ ։ൃνʔϜ͸ඒ͸ݟΔਓͷ໨ͷதʹ͋Δ͜ͱΛ෼͍ͬͯΔͷͰɺ͜͏͍ͬͨ ௥ՃʹΦʔϓϯͰ͢ɻ 4MJN͸ߏจղੳίϯύΠϧʹ5FNQMFΛ࢖͍5JMUʹ૊Έࠐ·Ε·͢ɻ͜Ε ʹΑΓ4JOBUSB΍ϓϨʔϯͳ3BDLͱ΋Ұॹʹ࢖͑·͢ɻ

Slide 6

Slide 6 text

doctype html html head title My Slim Template body ruby: message = "Slim!" h1 Welcome to #{ message} p This is a simple example. ͜͏͍͏΍ͭ

Slide 7

Slide 7 text

҆શʹ͔͋ͭ͏

Slide 8

Slide 8 text

doctype html html head title My Slim Template body ruby: message = "Slim!" h1 Welcome to #{ message} p This is a simple example. ࠓ೔ͷλʔήοτ ˡ͜͜

Slide 9

Slide 9 text

͜Ε͸Կʁ Embedded engines: Tiltͷ͓͔͛ͰɺSlim ͸ଞͷςϯ ϓϨʔτΤϯδϯͷຒΊࠐΈʹݟࣄʹ ରԠ͍ͯ͠·͢ɻ Ruby,JavaScript,css,sass…etc

Slide 10

Slide 10 text

҆શʹ͔͋ͭ͏

Slide 11

Slide 11 text

ຒΊࠐΈ಺ͷίϝϯτ doctype html html head title My Slim Template body h1 Welcome to Slim! javascript: // comment alert("Hello, World!");

Slide 12

Slide 12 text

ίϯύΠϧޙ My Slim Template title> < / head> : html> / / mecha kimitsu joho alert("Hello, World!"); </ script> ݟΒΕͨ͘ͳ͍ίϝϯτ΋ ݟΒΕͯ͠·͏

Slide 13

Slide 13 text

ࢼߦࡨޡ %BOHFS΍4FNHSFQͰܯࠂ͢Δʁ ⭕ϧʔϧΛ௥Ճ͢Δ͚ͩͰྑ͍ ❌ίϝϯτॻ͚ͩ͘Ͱܯࠂ͸ͭΒͦ͏ ❌ܯࠂΛݟམͱ͞ΕΔͱҙຯ͕ͳ͍

Slide 14

Slide 14 text

ͭͬͨ͘ ZEBITMJNFNCFEEFENJOJGZ

Slide 15

Slide 15 text

slim-embedded-minify module Slim class Embedded < Filter class TagEngine < Engine prepend Minify::Tag end class JavaScriptEngine < TagEngine prepend Minify::Javascript end ennd

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

slim-embedded-minify ⭕ίϝϯτ͕ࣗ༝ʹॻ͚Δ ⭕௥Ճ࡟আ΋͔ΜͨΜ ⭕ίϯύΠϧ݁ՌΛൺֱͯ͠ίϝϯτ ͷΈ͕ফ͍͑ͯΔ͔ʹΑͬͯ֬ೝՄ

Slide 18

Slide 18 text

Its safe now

Slide 19

Slide 19 text

੩తղੳʹ͍ͭͯ

Slide 20

Slide 20 text

3VCP$PQͰ͸ղੳෆՄ 4MJN͸3VCZͰ͸ͳ͍ͷͰɺ 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: ^

Slide 21

Slide 21 text

ຒΊࠐΈҎ֎ͷTMJ̼ ੩తղੳπʔϧ͋Γ·͢ •r7kamura/slimcop •r7kamura/rubocop - slim ͕ɺຒΊࠐΜͰ͍ΔRubyίʔυͷ੩త ղੳ͸ग़དྷͳ͍

Slide 22

Slide 22 text

ຒΊࠐΈͷTMJ̼ ੩తղੳπʔϧ͋Γ·͢ •sds/slim - lint ͕ɺautocorrect͸ग़དྷͳ͍

Slide 23

Slide 23 text

͍ͭͬͨͯ͘Δ ZEBITMJNFNCFEDPQ ❌

Slide 24

Slide 24 text

slimembedcop html ruby: if File.exists?("foo.txt") message = "Yay!" else message = "Nooo!" end h1 #{ message} ੾Γग़ͯ͠3VCP$PQʹ౉ͯ͠ ղੳͯ͠΋Β͏

Slide 25

Slide 25 text

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") ^^^^^^^^^^^^

Slide 26

Slide 26 text

⭕3VCP$PQͷطଘͷDPQ͕࢖͑Δ ⭕ࣗಈमਖ਼ʹରԠ͍ͯ͠Δ ⭕DPQ͕࡞ΕΔʹTMJNFNCFEDPQͷ DPQ΋࡞ΕΔ slimembedcop

Slide 27

Slide 27 text

We got static analysis

Slide 28

Slide 28 text

ීஈԿؾͳ͘࢖͍ͬͯΔ΋ͷʹ΋վળ ͷ༨஍͸ҙ֎ͱ຾͍ͬͯΔͷͰɺͲΜ ͲΜվળͯ͠ɺͲΜͲΜ޾ͤʹͳͬͯ ͍͖·͠ΐ͏ʂʂ ·ͱΊ

Slide 29

Slide 29 text

end