60 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright (C) 2023 WYATT GROUP
# Please see the AUTHORS file for details.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
basename=$(basename "$0")
basepath=$(dirname "$0")
# Check for dependencies.
if ! command -v yq &>/dev/null; then
echo "yq could not be found. Please install it and try again."
echo "https://github.com/mikefarah/yq"
exit 1
fi
# Check for arguments, if no arguments read latest version from pubspec.yaml.
if [ $# -eq 0 ]; then
wyatt_analysis_version=$(yq eval '.version' "${basepath}/../pubspec.yaml")
else
wyatt_analysis_version=$1
fi
# Check if the version of the Wyatt Analysis ruleset is valid by checking if the file exists.
if [ ! -f "$basepath/../lib/analysis_options.$wyatt_analysis_version.yaml" ]; then
echo "Wyatt Analysis version $wyatt_analysis_version could not be found."
exit 1
fi
echo "Found Wyatt Analysis version $wyatt_analysis_version"
echo "Sorting rules..."
# Sort the rules in "lint.rules" alphabetically.
yq eval '.linter.rules |= sort_by(.)' "$basepath/../lib/analysis_options.$wyatt_analysis_version.yaml" >"$basepath/../lib/analysis_options.$wyatt_analysis_version.yaml.tmp"
cp -f "$basepath/../lib/analysis_options.$wyatt_analysis_version.yaml.tmp" "$basepath/../lib/analysis_options.$wyatt_analysis_version.yaml"
rm -f "$basepath/../lib/analysis_options.$wyatt_analysis_version.yaml.tmp"
# Sort the rules in "lint.rules" alphabetically.
yq eval '.linter.rules |= sort_by(.)' "$basepath/../lib/analysis_options.flutter.$wyatt_analysis_version.yaml" >"$basepath/../lib/analysis_options.flutter.$wyatt_analysis_version.yaml.tmp"
cp -f "$basepath/../lib/analysis_options.flutter.$wyatt_analysis_version.yaml.tmp" "$basepath/../lib/analysis_options.flutter.$wyatt_analysis_version.yaml"
rm -f "$basepath/../lib/analysis_options.flutter.$wyatt_analysis_version.yaml.tmp"
exit 0