0
1

More than 3 years have passed since last update.

Flutterコードをpushする前に静的解析チェックをする

Last updated at Posted at 2020-04-15

Flutterアプリのリポジトリにflutter analyze, flutter formatをチェックするCIを設定したのでコードpushする前にチェックしておきたい。

.git/hooks/pre-push にこんな感じのスクリプトを置いてpush前にチェックすることにした。

#!/bin/sh

prePush() {
  runFlutterAnalyze
  runFlutterDartFormat
}
runFlutterAnalyze() {
  flutter analyze
  status=$?
  if [[ $status = 0 ]]; then
   echo '[info] Pass flutter analyze'
  else
   echo '[error] Not pass flutter analyze, are you sure to push? [y/N]'
   exec < /dev/tty
   read answer

   case $answer in
    'y' | 'yes') echo '[info] continue to push';;
    * ) echo '[error] stop pushing';exit 1;;
   esac
  fi
}

runFlutterDartFormat() {
  flutter format --set-exit-if-changed --dry-run .
  status=$?
  if [[ $status = 0 ]]; then
   echo '[info] Pass flutter format'
  else
   echo '[error] Not pass flutter format, are you sure to push? [y/N]'
   exec < /dev/tty
   read answer

   case $answer in
    'y' | 'yes') echo '[info] continue to push';;
    * ) echo '[error] stop pushing';exit 1;;
   esac
  fi
}

prePush
exit 0
0
1
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
0
1