Slide 1

Slide 1 text

2022.08.25 ਆݪ ݈Ұ (@korodroid) Flutter LintπʔϧΛ׬શʹཧղͨ͠ ʮʓʓ׬શʹཧղͨ͠ʯTalkɹ#32

Slide 2

Slide 2 text

About me •Mobile App Development •Speeches (e.g. 9 International confs.) •Writings (e.g. 6 Dev Books) •[Of fi cial] Evangelist at NTT TechnoCross •[Private] iplatform.org ਆݪɹ݈Ұ (@korodroid)

Slide 3

Slide 3 text

About my Flutter product (Private works) Sekaiphone Pro(Flutter/Kotlin/Swift) MyToDo(Flutter)

Slide 4

Slide 4 text

Lintπʔϧ(੩తղੳ)Λ׆༻͢ΔϝϦοτ(ྫ) 1. જࡏతͳόάͷݕग़ 2. ϨϏϡʔ࡞ۀͷෛՙܰݮ 3. ΞϓϦͷύϑΥʔϚϯεվળ 


Slide 5

Slide 5 text

Flutter޲͚Lintπʔϧ( fl utter_lints) https://pub.dev/packages/ fl utter_lints

Slide 6

Slide 6 text

Walking through “ fl utter_lints” ↑ඞཁʹԠͯ͡ɺ࠷৽൛ʹߋ৽

Slide 7

Slide 7 text

Walking through “analysis_options.yaml”

Slide 8

Slide 8 text

Walking through “ fl utter.yaml” # Recommended lints for Flutter apps, packages, and plugins. include: package:lints/recommended.yaml linter: rules: - avoid_print - avoid_unnecessary_containers - avoid_web_libraries_in_ fl utter - no_logic_in_create_state - prefer_const_constructors - prefer_const_constructors_in_immutables - prefer_const_declarations - prefer_const_literals_to_create_immutables - sized_box_for_whitespace - sort_child_properties_last - use_build_context_synchronously - use_full_hex_values_for_ fl utter_colors - use_key_in_widget_constructors

Slide 9

Slide 9 text

# Recommended lints for Flutter apps, packages, and plugins. include: package:lints/recommended.yaml linter: rules: - avoid_print - avoid_unnecessary_containers - avoid_web_libraries_in_ fl utter - no_logic_in_create_state - prefer_const_constructors - prefer_const_constructors_in_immutables - prefer_const_declarations - prefer_const_literals_to_create_immutables - sized_box_for_whitespace - sort_child_properties_last - use_build_context_synchronously - use_full_hex_values_for_ fl utter_colors - use_key_in_widget_constructors Walking through “ fl utter.yaml”

Slide 10

Slide 10 text

Walking through “Linter for Dart” https://dart-lang.github.io/linter/lints/ productionίʔυʹ͓͚Δprint཈੍

Slide 11

Slide 11 text

Walking through “ fl utter.yaml” # Recommended lints for Flutter apps, packages, and plugins. include: package:lints/recommended.yaml linter: rules: - avoid_print - avoid_unnecessary_containers - avoid_web_libraries_in_ fl utter - no_logic_in_create_state - prefer_const_constructors - prefer_const_constructors_in_immutables - prefer_const_declarations - prefer_const_literals_to_create_immutables - sized_box_for_whitespace - sort_child_properties_last - use_build_context_synchronously - use_full_hex_values_for_ fl utter_colors - use_key_in_widget_constructors

Slide 12

Slide 12 text

Walking through “recommended.yaml”

Slide 13

Slide 13 text

Walking through “Linter for Dart” ྫ.Collection͕ಛఆཁૉΛؚΉ͔൱͔ͷ൑ఆ ྫ.Πϯελϯεੜ੒ͷͨΊͷnewར༻཈੍

Slide 14

Slide 14 text

Walking through “recommended.yaml”

Slide 15

Slide 15 text

Walking through “core.yaml”

Slide 16

Slide 16 text

Adding Custom Rules https://github.com/ fl utter/samples

Slide 17

Slide 17 text

Walking through “samples/analysis_options.yaml” include: package: fl utter_lints/ fl utter.yaml analyzer: strong-mode: implicit-casts: false implicit-dynamic: false linter: rules: avoid_types_on_closure_parameters: true avoid_void_async: true cancel_subscriptions: true close_sinks: true directives_ordering: true package_api_docs: true package_pre fi xed_library_names: true test_types_in_equals: true throw_in_ fi nally: true unawaited_futures: true unnecessary_statements: true use_super_parameters: true

Slide 18

Slide 18 text

Walking through “samples/analysis_options.yaml” include: package: fl utter_lints/ fl utter.yaml analyzer: strong-mode: implicit-casts: false implicit-dynamic: false linter: rules: avoid_types_on_closure_parameters: true avoid_void_async: true cancel_subscriptions: true close_sinks: true directives_ordering: true package_api_docs: true package_pre fi xed_library_names: true test_types_in_equals: true throw_in_ fi nally: true unawaited_futures: true unnecessary_statements: true use_super_parameters: true

Slide 19

Slide 19 text

Customizing static analysis https://dart.dev/guides/language/analysis-options

Slide 20

Slide 20 text

One more examples… analyzer: errors: avoid_print: error ྫ.avoid_printҧ൓ΛΤϥʔʹ analyzer: exclude: - “**/*.g.dart" - "**/*.freezed.dart" - test/*.dart ྫ.ର৅ύεͷϑΝΠϧΛνΣοΫର৅֎΁

Slide 21

Slide 21 text

·ͱΊ •FlutterΞϓϦ։ൃͰ΋ੵۃతʹLint׆༻ʂ •ެࣜϦϑΝϨϯεͷϓϥΫςΟε΋ࢀߟʹʂ •ඞཁʹԠͯ͡ɺϧʔϧΛదٓΧελϚΠζ

Slide 22

Slide 22 text

Please let me know if you have any requests 
 such as technical speeches, technical writings and so on. Facebook:http://fb.com/kanbara.kenichi Twitter:@korodroid LinkedIn:http://www.linkedin.com/in/korodroid Thank you so much