mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

The script is modeled after a similar script in the engine (see engine's [format.dart](https://github.com/flutter/engine/blob/main/ci/bin/format.dart)). It identifies the files that have been changed and checks if their formatting is correct. It also offers an option to correct formatting (`--fix`) and an option to check the formatting of all files in the repro (not just changed ones, `--all-files`). When we are enforcing dart format this script will be called as part of presubmit.
38 lines
1.0 KiB
Bash
Executable File
38 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Copyright 2014 The Flutter Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
set -e
|
|
|
|
# Needed because if it is set, cd may print the path it changed to.
|
|
unset CDPATH
|
|
|
|
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
|
|
# link at a time, and then cds into the link destination and find out where it
|
|
# ends up.
|
|
#
|
|
# The function is enclosed in a subshell to avoid changing the working directory
|
|
# of the caller.
|
|
function follow_links() (
|
|
cd -P "$(dirname -- "$1")"
|
|
file="$PWD/$(basename -- "$1")"
|
|
while [[ -h "$file" ]]; do
|
|
cd -P "$(dirname -- "$file")"
|
|
file="$(readlink -- "$file")"
|
|
cd -P "$(dirname -- "$file")"
|
|
file="$PWD/$(basename -- "$file")"
|
|
done
|
|
echo "$file"
|
|
)
|
|
|
|
SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
|
|
FLUTTER_DIR="$(cd "$SCRIPT_DIR/../.."; pwd -P)"
|
|
DART="${FLUTTER_DIR}/bin/dart"
|
|
|
|
cd "$SCRIPT_DIR"
|
|
"$DART" pub get > /dev/null
|
|
"$DART" \
|
|
bin/format.dart \
|
|
"$@"
|