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

Vue I18n 向けに ESLint プラグインを作った

Vue I18n 向けに ESLint プラグインを作った

kazupon

May 22, 2019
Tweet

More Decks by kazupon

Other Decks in Programming

Transcript

  1. PLAID, inc.
 Vue.js Core Team Member Vue.js Japan User Group

    Organizer Vue I18n Author WebAssembly Love ❤ @kazu_pon kazupon kazupon
  2. i18n ͱ l10n ͷؔ܎ • l10n: localization (ϩʔΧϥΠθʔγϣ ϯ:஍ҬԽ)ͷུশ i18n

    + l10n = g11n (globalization) 11 จࣈ ج൫ ೔ຊޠ ӳޠ தࠃޠ l10n i18n g11n
  3. i18n ରԠ߲໨಺༰ • ςΩετϝοηʔδ • ೔࣌ϑΥʔϚοτ • ਺஋ϑΥʔϚοτ • ը૾ɺಈը

    • จࣈίʔυɺֆจࣈ • ి࿩൪߸ • ॅॴɺ໊લ • ܾࡁॲཧɺ੫ۚ • σʔλϕʔε • UI ϨΠΞ΢τ… ͳͲ
  4. ྫ: ςΩετϝοηʔδͷ i18n Vue ΞϓϦέʔγϣϯ Vue I18n API Locale Messages

    en.json ja.json … ͦͷଞͷݴޠ ಡΈࠐΉ ςϯϓϨʔτ ݴޠΛબ୒ ςΩετ͸ બ୒ͨ͠ݴޠͰදࣔ
  5. ࡞ͬͨϧʔϧ͸શ෦Ͱ5ͭ • Recommended
 Vue I18n ࢖͏ʹ͋ͨͬͯ ඞཁʹͳΔϧʔϧܥ • Best Practices


    ಋೖ͢Δͱ͞Βʹ i18n ର Ԡ͕Α͘ͳΔϕετϧʔ ϧܥ https://kazupon.github.io/eslint-plugin-vue-i18n/
  6. ͲͷΑ͏ͳྲྀΕͰ࡞͍ͬͯͬͨͷ͔ • ϑΣʔζ1: • ESLint ϓϥάΠϯͷ࡞Γํجຊཧղ • ϑΣʔζ2: • ESLint

    ϓϥάΠϯϓϩδΣΫτͷ౔୆ߏங • ϑΣʔζ3: • ESLint ϓϥάΠϯͷ࣮૷
  7. AST ॲཧʹ͍ͭͯཧղͨ͠ • ESLint ͷΧελϜ ϧʔϧͷ࣮૷͸ɺ
 جຊతʹ͸ AST (Abstract Syntax

    Tree) ͷ Node λΠϓ ·ͨ͸ΫΤϦʹϚο ν͢ΔΑ͏ͳ Visitor ؔ਺Ͱ࣮૷͢Δ
  8. ϑΣʔζ3 • ҎԼΛ΍Γͳ͕ΒϓϥάΠϯΛ࣮૷ͨ͠ • eslint-plugin-vue ͷίʔυಡΉ • vue-eslint-parser Λཧղ͢Δ •

    ESLint ެࣜυΩϡϝϯτΛ࠶ಡ͢Δ • ESLint ຊମͷίʔυಡΉ • ෼͔Βͳ͍͜ͱΛESLintதͷਓʹฉ͘
  9. ESLint ຊମͷίʔυΛಡΉ • ESLint ͷಈ࡞͕஌Γͨ ͘ͳͬͨΓ • ESLint ຊମͷίʔυΛ ಡΜͩΓͨ͠

    • Processor ͷHookͷ ݺͼग़͠λΠϛϯά • ESLint Configuration ͷಡΈࠐΈλΠϛϯά • … ͳͲ https://twitter.com/kazu_pon/status/1103998606514696192
  10. ·ͱΊ • Vue I18n ͷ Locale Messages ͷ՝୊ղܾ͢Δ ͨΊʹ ESLint

    ϓϥάΠϯΛ࡞Γ࢝Ίͨ • ֤छ ESLintυΩϡϝϯτɺطʹੈʹ͋Δ ESLint ϓϥάΠϯΛࢀߟʹͭͭ͠ɺͦͯ͠ ESLint தͷਓʹฉ͘͜ͱͰ୹ظؒͰ࣮૷Ͱ͖ ͨ
  11. ײ૝ • ESLint ϓϥάΠϯͱ͍͏ͱɺAST Λۦ࢖ͨ͠ݴޠॲ ཧܥͷͨΊɺ࣮૷ྔ͕൒୺ͳ͘ɺ໘౗͍͘͞ͱ͍͏ Πϝʔδ͕͋Δ • ࣮ࡍʹɺAST ʹରͯ͠

    Visitor ؔ਺Λ࣮૷ͯ͠ΰχϣ ΰχϣ͢Δ͚ͩͰॲཧͰ͖ΔͷͰͦΜͳʹ೉͘͠ͳ ͍͜ͱ͕෼͔ͬͨ • ͦͯ͠ɺԿͱ͍ͬͯ΋ AST ۦ࢖͢Δͷָ͘͠ײͨ͡
  12. AST ೖ໳ͷͨΊͷࢀߟϦιʔε • Visitor ύλʔϯ
 ʮJavaݴޠͰֶͿσβΠϯύλʔϯೖ໳ʯ ݁৓ ߒ (ஶ) •

    JavaScript ASTΛ࢝ΊΔ࠷ॳͷҰา
 https://efcl.info/2016/03/06/ast-first-step/ • ΧδϡΞϧJavaScript AST
 http://azu.github.io/slide/JSojisan/ • ؆୯ʂศརʂJavaScript ASTೖ໳
 https://rabbit-house.tokyo/ast-book-sample-10-16-rev3.pdf • AST Explorer
 https://astexplorer.net/