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

Dart/Flutterのための静的コード解析

 Dart/Flutterのための静的コード解析

dartanalyzerを使った、Dart/Flutterの静的コード解析についての発表です。
CircleCI上でdartanalyzerを実行し、Github Pull Requestにコメントを入れる手順まで紹介しています。

Flutter勉強会 in 福岡 #3 & Fukuoka.dart #1 - connpass
https://flat-lab.connpass.com/event/113785/

flutter/flutterの公式analysis_options.yaml
https://github.com/flutter/flutter/blob/stable/analysis_options.yaml

```.circleci/config.yml
version: 2
jobs:
lint:
docker:
- image: kuronekomichael/flutter:stable
steps:
- checkout
- run: 'flutter packages get'
- run: 'dartcop . | reviewdog -f=checkstyle -name=dartcop -reporter=github-pr-review'
workflows:
version: 2
build_and_test:
jobs:
- lint
```

1. dartanalyzerのラッパー「dartcop」
https://github.com/kuronekomichael/dartcop

2. Dart/Flutter用のdockerイメージ「kuronekomichael/flutter」
https://hub.docker.com/r/kuronekomichael/flutter/dockerfile

Necco Michael

January 23, 2019
Tweet

More Decks by Necco Michael

Other Decks in Programming

Transcript

  1. ϧʔϧͷΧελϚΠζ΋؆୯ ΧϨϯτσΟϨΫτϦʹʮanalysis_options.yamlʯΛஔ͚ͩ͘ʂ analyzer: strong-mode: implicit-dynamic: false errors: # treat missing

    required parameters as a warning (not a hint) missing_required_param: warning # treat missing returns as a warning (not a hint) missing_return: warning # allow having TODOs in the code todo: ignore exclude: - 'bin/cache/**' # the following two are relative to the stocks example and the flutter package respectively # see https://github.com/dart-lang/sdk/issues/28463 - 'lib/i18n/stock_messages_*.dart' - 'lib/src/http/**' linter: rules: # these rules are documented on and in the same order as # the Dart Lint rules page to make maintenance easier # https://github.com/dart-lang/linter/blob/master/example/all.yaml - always_declare_return_types - always_put_control_body_on_new_line # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/ flutter/issues/10219 - always_require_non_null_named_parameters - always_specify_types
  2. STEP 2 CircleCIͷઃఆϑΝΠϧΛίϛοτ͢Δ .circleci/config.yml version: 2 jobs: lint: docker: -

    image: kuronekomichael/flutter:stable steps: - checkout - run: 'flutter packages get' - run: 'dartcop . | reviewdog -f=checkstyle -name=dartcop -reporter=github-pr-review' workflows: version: 2 build_and_test: jobs: - lint
  3. STEP 3 CircleCIΛઃఆ͢Δ ▸ Point1. reviewdog͔ΒPull RequestʹίϝϯτͰ͖ΔΑ͏ɺ ؀ڥม਺ʹGitHubͷAPIτʔΫϯΛઃఆͯ͋͛͠Δ
 REVIEWDOG_GITHUB_API_TOKEN ▸

    Point2. Pull Request͚ͩδϣϒΛ૸ΒͤΔΑ͏ઃఆ
 [Settings]-[Advanced Settings]-[Only build pull requests]
 •On