check-whitespace.sh 1.0 KB

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # check-whitespace.sh — check that files end with an empty line and there are no trailing whitespaces
  12. set -euo pipefail
  13. cd "$(dirname "$0")/../../../.."
  14. . misc/shlib/shlib.bash
  15. files=$(git_files "$@")
  16. # Only binary files are permitted to omit a trailing newline. If you're here to
  17. # exclude a text file that is missing its trailing newline, like an SVG, add
  18. # a trailing newline to the text file instead.
  19. newline_files=$(grep -vE '(_scratch|\.(png|jpe?g|pb|avro|ico|so))$' <<< "$files")
  20. try xargs misc/lint/trailing-newline.sh <<< "$newline_files"
  21. try xargs git --no-pager diff --check "$(git_empty_tree)" <<< "$newline_files"
  22. try_status_report