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

ミスを少なくする明日からのCustom Lint Rules

B8f695167d115eef9f32399b1c9261df?s=47 Yuki Mima
January 20, 2017

ミスを少なくする明日からのCustom Lint Rules

B8f695167d115eef9f32399b1c9261df?s=128

Yuki Mima

January 20, 2017
Tweet

Transcript

  1. ϛεΛগͳ͘͢Δ໌೔͔Βͷ Custom Lint Rules kyobashi.dex #4 @amyu_san

  2. About me ▸ Name : Yuki Mima ▸ Twitter :

    @amyu_san
  3. Lint Rulesͱ͸ ▸ ੩తղੳπʔϧ ▸ ./gradlew lint Ͱ࣮ߦͰ͖Δ ▸ ࣮ߦ݁Ռ͸DefaultͰ


    /app/build/outputs/lint-results-yourFlavor.xml
 /app/build/outputs/lint-results-yourFlavor.html
  4. TEXT Custom Lint Ruleͷ࡞੒खॱ ▸ Detector : ΦϦδφϧͷ੩తղੳΛߦ͏߲໨ͷࢦఆ ▸ DetectorTest

    : DetectorͷTest ▸ Registry : DetectorΛొ࿥?͢Δ
  5. Detector ▸ LayoutDetector ▸ app/src/hoge/res/layout Λର৅ ▸ JavaScanner ▸ Java

    Code Λର৅ ▸ ClassScanner ▸ Java class files Λର৅
  6. AccessibilityDetector ▸ layout xmlʹ͋ΔTag໊͕ImageView·ͨ͸ImageButton͕ଘࡏ͢ΔTag͕ ੩తղੳର৅ ▸ contentDescriptionଐੑͷValue͕ۭจࣈ͔”TODO”ͷΈࢦఆ͞Ε͍ͯΔ ৔߹ʹܯࠂ͞ΕΔ ▸ contentDescriptionଐੑͱimportantForAccessibilityଐੑ͕྆ํଘࡏ͠

    ͳ͍৔߹ʹܯࠂ͞ΕΔ ▸ android:contentDescriptionଐੑ͕ଘࡏ͢ΔTag͕੩తղੳର৅ ▸ contentDescriptionଐੑͱhintଐੑ͕ಉ࣌ʹҰͭͷTag಺ʹଘࡏ͢Δͱ͖ ܯࠂ͞ΕΔ
  7. None
  8. getApplicableElementsʹ૸͍ࠪͨ͠Tag(View)໊Λฦ ͢
 visitElements(…)ʹTag৘ใ͕ؼͬͯ͘Δ ImageView·ͨ͸ImageButtonͷTag໊Λ࣋ͭTag͕૸ ࠪͷର৅ʹͳΔ

  9. getApplicableAttributesʹ૸͍ࠪͨ͠ଐੑΛฦ͢
 visitAttributes(…)ʹTag৘ใ͕ؼͬͯ͘Δ android:contentDescriptionଐੑΛ࣋ͭTag͕૸ࠪͷର ৅ʹͳΔ

  10. Tag(View)ʹcontentDescriptionଐੑ͕ଘࡏ͢Δͱ͖
 android:hintଐੑ΋ಉ࣌ʹએݴ͍ͯͨ͠৔߹͸ܯࠂΛग़ ͢ getApplicableAttributesʹࢦఆͨ͠૸͍ࠪͨ͠Tag͕ Callback͞ΕΔ contentDescriptionଐੑΛ࣋ͭTagͷ৘ใ͕ೖͬͯΔ
 ↓

  11. getApplicableElementsʹࢦఆͨ͠૸͍ࠪͨ͠ Tag͕Callback͞ΕΔ Tag(View)໊͕ImageView·ͨ͸ImageButtonͷͱ͖
 - android:contentDescriptionଐੑͱandroid:importantForAccessibilityଐੑ͕ͳ͍৔߹ܯࠂΛग़͢
 - android:contentDescriptionଐੑ͕ଘࡏ͠Ŋvalueʹۭจࣈ·ͨ͸TODOͱ͍͏จࣈͷ৔߹ܯࠂΛग़͢ ↑
 |
 |

    
 ImageView·ͨ͸ImageButtonͷTagΛ࣋ͭTagͷ৘ใ͕ೖͬͯΔ
  12. Tag໊Λࢦఆ͠੩తղੳ

  13. ଐੑΛࢦఆ͠੩తղੳ

  14. ஌ݟʹͳΔLint ▸ DeprecationDetector https://android.googlesource.com/platform/tools/base/+/master/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/DeprecationDetector.java?autodive=0%2F ▸ editableଐੑͳͲDeprecatedʹͳͬͨଐੑΛ࢖༻͢Δͱ ܯࠂग़ͯ͘͠ΕΔ ▸ ToastDetector https://android.googlesource.com/platform/tools/base/+/master/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ToastDetector.java?autodive=0%2F

    ▸ ToastΛ࢖༻࣌ʹshow͕ݺ͹Ε͍ͯͳ͍ͱܯࠂͯ͘͠ΕΔ
  15. Ͱ͖ͳ͔ͬͨ͜ͱ ࠔͬͯΔ͜ͱ ▸ ͳΜ͔KotlinͰॻ͜͏ͱͨ͠ΒΤϥʔग़ͯॻ͚ͳ͔ͬͨ ▸ ୭͔΍Γํڭ͍͑ͯͩ͘͞ ▸ CircleCIͰ./gradlew lint Λ࣮ߦ͕ͨ͠ŊSeverity͕Errorͳ΋

    ͷΛWarningʹมߋ͞ΕͯΔΑ͏ͳؾ͕ͨ͠ ▸ ୭͔ڭ͍͑ͯͩ͘͞ ▸ ࠓ͸࣮ߦ݁ՌͷxmlΛParseͯ͠CIΛFailͤͯ͞Δ
  16. ࢀߟࢿྉ ▸ Custom Lint Rules ▸ http://qiita.com/hotchemi/items/9364d54a0e024a5e6275 ▸ ϛεΛগͳ͘͢Δ໌೔͔ΒͷCustom Lint

    Rules ▸ http://qiita.com/amyu_san/items/b6b674693eefaae2b4bc ▸ طଘͷιʔε ▸ https://android.googlesource.com/platform/tools/base/+/ master/lint/libs/lint-checks/src/main/java/com/android/tools/ lint/checks?autodive=0/