8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

flutter_lints とは

Flutter が推奨する Lint をまとめている公式パッケージで、Flutter のテンプレートプロジェクトでも利用されています。

なぜ変更点を追いたいのか

私が pub.dev に公開している blendthink_lints というパッケージが flutter_lints に依存しているからです。

flutter_lints の変更点とは

あくまで現状では、以下の3つのファイルの変更点と考えて問題なさそうです。

  • flutter_lints の flutter.yaml
  • lints の recommended.yaml
  • lints の core.yaml

それぞれのファイルの中身
flutter.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_flutter
    - 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_flutter_colors
    - use_key_in_widget_constructors
recommended.yaml
include: package:lints/core.yaml

linter:
  rules:
    - always_require_non_null_named_parameters
    - annotate_overrides
    - avoid_function_literals_in_foreach_calls
    - avoid_init_to_null
    - avoid_null_checks_in_equality_operators
    - avoid_renaming_method_parameters
    - avoid_return_types_on_setters
    - avoid_returning_null_for_void
    - avoid_single_cascade_in_expression_statements
    - constant_identifier_names
    - control_flow_in_finally
    - empty_constructor_bodies
    - empty_statements
    - exhaustive_cases
    - implementation_imports
    - library_names
    - library_prefixes
    - library_private_types_in_public_api
    - no_leading_underscores_for_library_prefixes
    - no_leading_underscores_for_local_identifiers
    - null_closures
    - overridden_fields
    - package_names
    - prefer_adjacent_string_concatenation
    - prefer_collection_literals
    - prefer_conditional_assignment
    - prefer_contains
    - prefer_equal_for_default_values
    - prefer_final_fields
    - prefer_for_elements_to_map_fromIterable
    - prefer_function_declarations_over_variables
    - prefer_if_null_operators
    - prefer_initializing_formals
    - prefer_inlined_adds
    - prefer_interpolation_to_compose_strings
    - prefer_is_not_operator
    - prefer_null_aware_operators
    - prefer_spread_collections
    - prefer_void_to_null
    - recursive_getters
    - slash_for_doc_comments
    - type_init_formals
    - unnecessary_brace_in_string_interps
    - unnecessary_const
    - unnecessary_constructor_name
    - unnecessary_getters_setters
    - unnecessary_late
    - unnecessary_new
    - unnecessary_null_aware_assignments
    - unnecessary_null_in_if_null_operators
    - unnecessary_nullable_for_final_variable_declarations
    - unnecessary_string_escapes
    - unnecessary_string_interpolations
    - unnecessary_this
    - use_function_type_syntax_for_parameters
    - use_rethrow_when_possible
core.yaml
linter:
  rules:
    - avoid_empty_else
    - avoid_relative_lib_imports
    - avoid_shadowing_type_parameters
    - avoid_types_as_parameter_names
    - await_only_futures
    - camel_case_extensions
    - camel_case_types
    - curly_braces_in_flow_control_structures
    - depend_on_referenced_packages
    - empty_catches
    - file_names
    - hash_and_equals
    - iterable_contains_unrelated_type
    - list_remove_unrelated_type
    - no_duplicate_case_values
    - non_constant_identifier_names
    - null_check_on_nullable_type_parameter
    - package_prefixed_library_names
    - prefer_generic_function_type_aliases
    - prefer_is_empty
    - prefer_is_not_empty
    - prefer_iterable_whereType
    - prefer_typing_uninitialized_variables
    - provide_deprecation_message
    - unnecessary_overrides
    - unrelated_type_equality_checks
    - valid_regexps
    - void_checks

どのように変更点を追うのか

もっと良い方法がある気もしますが、私は以下のようにしてみました。

  1. 各ファイルの現状のバージョンをリポジトリ内に保存
  2. Dependabot で pub の更新通知を受信
  3. flutter_lints の更新があるか確認
  4. 更新があれば pub-cache から各ファイルの新しいバージョンをリポジトリ内にコピー
  5. Dependabot で作られたブランチに向けてプルリクエストを作成

1. 各ファイルの現状のバージョンをリポジトリ内に保存

GitHub 上でパッと差分を確認したかったということもあり、tool/lints 配下に保存しました。

差分をどんな形でも良いから確認したいということであれば、リポジトリ内に保存する必要はなく、以前のバージョンと新しいバージョンのファイルを毎回取得して差分を確認すれば良さそうです。

2. Dependabot で pub の更新通知を受信

.github/dependabot.yaml を作成して、週に1度 pub の更新チェックを走らせ、更新があった場合、自動的にプルリクが作成されるようにしました。

dependabot.yaml
version: 2
enable-beta-ecosystems: true
updates:
  - package-ecosystem: "pub"
    directory: "/"
    schedule:
      interval: "weekly"

詳しくは、下記の公式ブログの記事をご覧ください。
pub beta support for Dependabot version updates

3. flutter_lints の更新があるか確認

プルリクエスト時に発火する GitHub Action の workflow を作成して、 そこで、pubspec.yaml の中に flutter_lints の差分があるかをチェックするようにしました。

なお、コマンド実行部分は grinder というパッケージを利用して Dart で記述しています。
git diff などのコマンドの実行結果を Dart でゴニョゴニョできるのは非常に便利なのでおすすめです。

4. 更新があれば pub-cache から各ファイルの新しいバージョンをリポジトリ内にコピー

dart pub get を実行すると、どうやら $PUB_CACHE/hosted/pub.dartlang.org/ 配下に各パッケージのキャッシュが保存される仕様のようで、そこから flutter_lints と lints のパッケージを検索して対象のファイルをコピーしました。

5. Dependabot で作られたブランチに向けてプルリクエストを作成

peter-evans/create-pull-request という GitHub Action を利用しています。感謝 :pray:

デモ

無事に動きました :sunglasses:

8
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?