Skip to content

Commit

Permalink
Add -i option to fix ASF headers to lint scripts. (#10284)
Browse files Browse the repository at this point in the history
* Add -i option to fix ASF headers to lint scripts.

* address driazati comments
  • Loading branch information
areusch authored Feb 18, 2022
1 parent d716c2a commit 783add2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
6 changes: 6 additions & 0 deletions docker/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function run_lint_step() {
;;
asf)
cmd=( tests/lint/check_asf_header.sh --local )
if [ $inplace_fix -eq 1 ]; then
cmd=( "${cmd[@]}" --fix )
fi
;;
clang_format)
if [ $inplace_fix -eq 0 ]; then
Expand Down Expand Up @@ -77,6 +80,9 @@ function run_lint_step() {
echo "error: don't know how to run lint step: $1" >&2
echo "usage: ${SCRIPT_NAME} [-i] <lint_step>" >&2
echo >&2
echo "options:" >&2
echo " -i Fix lint errors in-place where possible (modifies non-compliant files)" >&2
echo >&2
echo "available lint_step: ${DEFAULT_STEPS[@]}" >&2
exit 2
;;
Expand Down
45 changes: 35 additions & 10 deletions tests/lint/check_asf_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# specific language governing permissions and limitations
# under the License.

set -e
set -euo pipefail

rat_tempdir="$(mktemp -d)"

Expand All @@ -27,10 +27,23 @@ trap cleanup EXIT

rat_output="${rat_tempdir}/$$.apache-rat.txt"

fix=0
filter_untracked=0
if [ "$1" == "--local" ]; then
filter_untracked=1
fi
while [ "x${1-}" != "x" ]; do
case "$1" in
--local)
filter_untracked=1
;;
--fix)
fix=1
;;
*)
echo "Unrecognized option: $1"
exit 2
;;
esac
shift
done

java -jar /bin/apache-rat.jar -E tests/lint/rat-excludes -d . | (grep -E "^== File" >"${rat_output}" || true)

Expand All @@ -44,14 +57,26 @@ if [ ${filter_untracked} -eq 1 ]; then
rat_output="${processed_rat_output}"
fi

if grep --quiet -E "File" "${rat_output}"; then
echo "Need to add ASF header to the following files."
grep --quiet -E "File" "${rat_output}" && success=1 || success=0

if [ $success -eq 0 ]; then
echo "No files violate ASF header check"
else
if [ $fix -eq 1 ]; then
python3 tests/lint/add_asf_header.py "${rat_output}"
echo "Ran add_asf_header.py to fix the following files:"
else
echo "Need to add ASF header to the following files."
fi
echo "----------------File List----------------"
cat "${rat_output}"
echo "-----------------------------------------"
echo "Use the following steps to add the headers:"
echo "- Create file_list.txt in your text editor"
echo "- Copy paste the above content in file-list into file_list.txt"
echo "- python3 tests/lint/add_asf_header.py file_list.txt"
if [ $fix -eq 0 ]; then
echo "To fix, run check_asf_header.sh --fix, or use the following manual steps:"
echo "- Create file_list.txt in your text editor"
echo "- Copy paste the above content in file-list into file_list.txt"
echo "- python3 tests/lint/add_asf_header.py file_list.txt"
echo "When running via docker/lint.sh, add -i to automatically fix these problems."
fi
exit 1
fi

0 comments on commit 783add2

Please sign in to comment.