Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

About me ▸ Name : Yuki Mima ▸ Twitter : @amyu_san

Slide 3

Slide 3 text

Lint Rulesͱ͸ ▸ ੩తղੳπʔϧ ▸ ./gradlew lint Ͱ࣮ߦͰ͖Δ ▸ ࣮ߦ݁Ռ͸DefaultͰ
 /app/build/outputs/lint-results-yourFlavor.xml
 /app/build/outputs/lint-results-yourFlavor.html

Slide 4

Slide 4 text

TEXT Custom Lint Ruleͷ࡞੒खॱ ▸ Detector : ΦϦδφϧͷ੩తղੳΛߦ͏߲໨ͷࢦఆ ▸ DetectorTest : DetectorͷTest ▸ Registry : DetectorΛొ࿥?͢Δ

Slide 5

Slide 5 text

Detector ▸ LayoutDetector ▸ app/src/hoge/res/layout Λର৅ ▸ JavaScanner ▸ Java Code Λର৅ ▸ ClassScanner ▸ Java class files Λର৅

Slide 6

Slide 6 text

AccessibilityDetector ▸ layout xmlʹ͋ΔTag໊͕ImageView·ͨ͸ImageButton͕ଘࡏ͢ΔTag͕ ੩తղੳର৅ ▸ contentDescriptionଐੑͷValue͕ۭจࣈ͔”TODO”ͷΈࢦఆ͞Ε͍ͯΔ ৔߹ʹܯࠂ͞ΕΔ ▸ contentDescriptionଐੑͱimportantForAccessibilityଐੑ͕྆ํଘࡏ͠ ͳ͍৔߹ʹܯࠂ͞ΕΔ ▸ android:contentDescriptionଐੑ͕ଘࡏ͢ΔTag͕੩తղੳର৅ ▸ contentDescriptionଐੑͱhintଐੑ͕ಉ࣌ʹҰͭͷTag಺ʹଘࡏ͢Δͱ͖ ܯࠂ͞ΕΔ

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

getApplicableElementsʹ૸͍ࠪͨ͠Tag(View)໊Λฦ ͢
 visitElements(…)ʹTag৘ใ͕ؼͬͯ͘Δ ImageView·ͨ͸ImageButtonͷTag໊Λ࣋ͭTag͕૸ ࠪͷର৅ʹͳΔ

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Tag໊Λࢦఆ͠੩తղੳ

Slide 13

Slide 13 text

ଐੑΛࢦఆ͠੩తղੳ

Slide 14

Slide 14 text

஌ݟʹͳΔ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͕ݺ͹Ε͍ͯͳ͍ͱܯࠂͯ͘͠ΕΔ

Slide 15

Slide 15 text

Ͱ͖ͳ͔ͬͨ͜ͱ ࠔͬͯΔ͜ͱ ▸ ͳΜ͔KotlinͰॻ͜͏ͱͨ͠ΒΤϥʔग़ͯॻ͚ͳ͔ͬͨ ▸ ୭͔΍Γํڭ͍͑ͯͩ͘͞ ▸ CircleCIͰ./gradlew lint Λ࣮ߦ͕ͨ͠ŊSeverity͕Errorͳ΋ ͷΛWarningʹมߋ͞ΕͯΔΑ͏ͳؾ͕ͨ͠ ▸ ୭͔ڭ͍͑ͯͩ͘͞ ▸ ࠓ͸࣮ߦ݁ՌͷxmlΛParseͯ͠CIΛFailͤͯ͞Δ

Slide 16

Slide 16 text

ࢀߟࢿྉ ▸ 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/