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

platoを使ったコードメトリクス生成

usagi-f
April 13, 2017

 platoを使ったコードメトリクス生成

usagi-f

April 13, 2017
Tweet

More Decks by usagi-f

Other Decks in Programming

Transcript

  1. p l a t o Λ ࢖ ͬ ͨ ί

    ʔ υϝ τ Ϧ Ϋ ε ੜ ੒ 2 0 1 7 . 0 4 . 1 3 ੴ ڮ ܒ ଠ
  2. ࣗ ݾ ঺ հ • ੴڮܒଠʢishibashi keitaʣ • 29ࡀʢ5݄຤Ͱࡾे࿏ʂʣ •

    ਆಸ઒ݝੜ·Ε • DMM.com Labo 2014/5ʙ • ݩ͸σβΠφʔ • JSྺͦΖͦΖ3೥ • ͏͗͞ͷΞΠίϯΛ࢖͏ • ΞΠυϧ͕޷͖Ͱ͢
  3. ٙ ໰ ͕ ͨ ͘ ͞ Μ ͋ Δ Α

    Ͷ • ͳʹ͕ྑ͘ͳͬͨʁ • ͲΕ͚ͩྑ͘ͳͬͨʁ • ୹͘ॻ͚͹͍͍ͷ͔ʁ • ͲͷϑΝΠϧΛ༏ઌతʹͳ͓͢΂͖ʁ • ໨ඪ͸Ͳ͜ʹ͋Δͷ͔ʁ
  4. e s - a n a l y s i

    s / p l a t o
  5. J a v a S c r i p t

    s o u rc e c o d e v i s u a l i z a t i o n , s t a t i c a n a l y s i s , a n d c o m p l e x i t y t o o l
  6. ݟ ͯ Έ Α ͏ h t t p :

    / / e s - a n a l y s i s . g i t h u b . i o / p l a t o / e x a m p l e s / h a p i /
  7. େ ͖ ͘ 6 ͭ ͷ Τ Ϧ Ξ ͕

    ͋ Δ • Summary • Maintainability • Lines of code • Estimated errors in implementation • Lint errors • Files
  8. S u m m a r y Ҏ ߱ ͭ

    Βͭ Β ͱ ॻ ͍ͯ ͋ Δ σ ʔ λ ͷ ཁ ໿ ෦ ෼ ɻ To t a l / Av e r a g e L i n e s = શ ମ ͷ ߦ ਺ / ฏ ۉ ߦ ਺ Av e r a g e M a i n t a i n a b i l i t y = ฏ ۉ ϝ ϯ ς φ ϯε ੑ
  9. M a i n t a i n a b

    i l i t y ϑ ΝΠϧ ୯ Ґ ͷ ϝ ϯ ς φ ϯε ੑ ਺ ஋ ͕ ߴ ͍ ΄ Ͳ ༏ Εͯ ͍ Δ ʢ ޙ ड़ ͠ · ͢ɻ ʣ
  10. L i n e s o f c o d

    e ι ʔε ί ʔ υ ͷ ߦ ਺ ʢ L O C ʣ Ұ ֓ ʹ ͸ ݴ ͑ ͳ ͍ ͕ɺ গ ͳ ͍ ํ ͕ ྑ ͍ ܏ ޲
  11. E s t i m a t e d e

    r ro r s i n i m p l e m e n t a t i o n ݟ ੵ ΋ Γ Τϥ ʔ ਺ ࢖ ༻ ͞ Εͯ ͍ Δ ԋ ࢉ ࢠ ͳ Ͳ ͔ Β ɺ Τϥ ʔ ͕ ى ͖ Δ જ ࡏ ஋ Λ ࢉ ग़
  12. L i n t e r ro r s j

    s h i n t o r e s l i n t ͷ L i n t Τϥ ʔ ਺
  13. F i l e s ͜ ͜ · Ͱ ͷ

    ਺ ஋ Λ ݩ ʹ ϑ ΝΠϧ ୯ Ґ Ͱ Ұ ཡ Խ c o m p l e x i t y = ෳ ࡶ ੑ s l o c = S o u rc e L O C
  14. M a i n t a i n a b

    i l i t y I n d e x ʢ อ क ༰ қ ੑ ࢦ ਺ ʣ Maintainability Index = MAX(0,(171 - 5.2 * ln(Halstead Volume) - 0.23 * (Cyclomatic Complexity) - 16.2 * ln(Lines of Code))*100 / 171) • Halstead Volume • Cyclomatic Complexity • Lines of Code ࢉ ग़ ࣜ ʢ 0 [ B a d ] ʙ 1 0 0 [ G o o d ] ʣ
  15. H a l s t e a d Vo l

    u m e • ԋࢉࢠͷछྨɾग़ݱස౓ɾ࢖͍ํͳͲ͔Βग़͞ΕΔ • ࢛ଇԋࢉ͕૿͑ΔͱѱԽ // A if (foo) return null // B if (!foo) return null // Bͷํ͕είΞ͕མͪͨʢൺֱԋࢉࢠʣ
  16. C y c l o m a t i c

    C o m p l e x i t y • ίʔυ಺ͷ࣮ߦܦ࿏਺ • ϢχοτςετΛߦΘͳ͚Ε͹ͳΒͳ͍ճ਺ • ifจͳͲ͕૿͑ΔͱѱԽ͢Δ if (foo) { if (bar) return null; if (baz) { return null; } else { return null; } }
  17. ओ ͳ O p t i o n s •

    -x • আ֎ϑΝΠϧࢦఆ • -l, -e • jshintrc / eslintrc ఆٛϑΝΠϧͰLint࣮ߦ • -r • ࠶ؼతʹσΟϨΫτϦΛݕࡧ • Լ૚σΟϨΫτϦͷϑΝΠϧ΋ର৅ʹͯ͘͠ΕΔ • -n • empty LineΛεΩοϓͯ͠ܭଌ
  18. S c r i p t const plato = require('plato');

    const files = './src'; const outputDir = './report'; const options = { recurse: true }; const callback = (report) => { report.forEach((value) => { // ϑΝΠϧ୯ҐͰMaintainabilityͷ਺஋Λݟͯΰχϣΰχϣ΋Ͱ͖Δ console.log(value.complexity.maintainability); }); }; plato.inspect(files, outputDir, options, callback); • scriptΛॻ͍ͯcallbackΛ౉͢͜ͱ΋Ͱ͖Δ
  19. C a l l b a c k MethodAverage {

    cyclomatic: 1, cyclomaticDensity: 100, halstead: HalsteadAverage { bugs: 0.007, difficulty: 1.917, effort: 62.418, length: 9, time: 3.468, vocabulary: 3.5, volume: 19.575, operands: [Object], operators: [Object] }, params: 0, sloc: { logical: 1, physical: 6.5 } }, • cbͰϑΝΠϧ୯Ґͷreport਺஋͕؆୯ʹऔΕΔ
  20. • npm scriptͰ௚઀ୟ͘ͷ͕ࠓ෩͔΋ • gulp-plato͸Deprecated. • CIπʔϧͱͷ૊Έ߹Θͤਪ঑ • ᮢ஋Λ௒͍͑ͯͨΒSlackʹ௨஌͢Δ •

    1ϑΝΠϧͷ࠷େߦ਺ΛܾΊͯɺ௒͑ͯͨΒςετΛམͱ͢ • lintఆٛϑΝΠϧΛྲྀ༻Ͱ͖ΔͷͰɺ.eslintrcΛ࡞͓ͬͯ͘ͱ ྑ͍͔΋
  21. σϝ Ϧ ο τ ʢ ͱ ͍ ͏ ͔ ؾ

    Λ ͭ ͚Δ ΂ ͖ ͜ ͱ ʣ • platoͷείΞվળ ʹ ඞͣྑ͍ίʔυʹͳΔͱ͸ݶΒͳ͍ • ͋ͳͨ͸LOCΛݮΒͨ͢Ίʹɺྑ࣭ͳίϝϯτΛফ͠·͔͢ʁ