Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RubyでPrettierを使ってみた

fuqda
December 27, 2020

 RubyでPrettierを使ってみた

Tama.rb #25 年忘れLT会の発表資料です。

fuqda

December 27, 2020
Tweet

More Decks by fuqda

Other Decks in Programming

Transcript

  1. gem ‘prettier’ ΛೖΕΔ Auto correct ίϚϯυɿ bundle exec rbprettier --write

    ‘**/*.rb’ ઃఆͷมߋํ๏ɿ .prettierrc ʹఆٛΛ௥Ճ ※ ͦͷଞ npm / yarnͰ΋ @prettier/plugin-ruby ͷ ϓϥάΠϯͰରԠՄೳ
  2. .prettierrc ͷઃఆ ྫ2) จࣈྻɾγϯϘϧ഑ྻϦςϥϧͷਪ঑ { "rubyArrayLiteral": true } -beatles =

    ["john", "paul", "george", "ringo"] +beatles = %w[john paul george ringo] -nirvana = [:kurt, :kris, :dave] +nirvana = %i[kurt kris dave]
  3. .prettierrc ͷઃఆ ྫ3) ϋογϡϩέοτͷඇਪ঑ { "rubyHashLabel": true } -{ :’radio_name'

    => 'ϋογϡϩέοτେ޷͖' } +{ ‘radio_name’: 'ϋογϡϩέοτେ޷͖' }
  4. ؾʹͳͬͨͱ͜Ζʙͦͷ1ʙ • ↓Auto correctͨ͠ࡍʹίϯιʔϧʹ ࣮ߦ࣌ؒͷΈग़ͯɺԿͷϧʔϧʹҾֻ͔ͬͬͯमਖ਼͞Εͨ ͷ͔ग़ͯ͜ͳ͍఺͸ͪΐͬͱؾʹͳͬͨ… $ bundle exec rbprettier

    --write 'prettier.rb' prettier.rb 370ms • JS༻ͷPrettierΛRubyʹస༻ͨ͠΋ͷͳͷͰ ౰ͨΓલ͚ͩͲRubyʹ޲͚ͨϧʔϧ͕গͳ͍ʁ (RuboCop΄Ͳϧʔϧ͕ॆ࣮ͯ͠ͳ͍)