浏览代码

Meta: Add a script that makes sure files end in a newline.

This script checks .html, .css, .js, .cpp, .h, .gml and .sh files.

It also makes sure that there are no black lines at the end of the
files checked.
Emanuele Torre 4 年之前
父节点
当前提交
f9f571aa7f
共有 2 个文件被更改,包括 43 次插入0 次删除
  1. 42 0
      Meta/check-newlines-at-eof.sh
  2. 1 0
      Meta/lint-ci.sh

+ 42 - 0
Meta/check-newlines-at-eof.sh

@@ -0,0 +1,42 @@
+#!/bin/bash
+
+script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
+cd "$script_path/.." || exit 1
+
+MISSING_NEWLINE_AT_EOF_ERRORS=()
+MORE_THAN_ONE_NEWLINE_AT_EOF_ERRORS=()
+
+while IFS= read -r f; do
+    [ -s "$f" ] || continue
+
+    if [ "$(tail -n 1 "$f" | wc -l)" != 1 ]; then
+        MISSING_NEWLINE_AT_EOF_ERRORS+=( "$f" )
+    elif [[ "$(tail -n 1 "$f")" =~ ^[[:space:]]*$ ]]; then
+        MORE_THAN_ONE_NEWLINE_AT_EOF_ERRORS+=( "$f" )
+    fi
+done < <(git ls-files -- \
+    '*.cpp' \
+    '*.h' \
+    '*.gml' \
+    '*.html' \
+    '*.js' \
+    '*.css' \
+    '*.sh' \
+    ':!:Base' \
+    ':!:Kernel/FileSystem/ext2_fs.h' \
+    ':!:Libraries/LibC/getopt.cpp' \
+    ':!:Libraries/LibCore/puff.h' \
+    ':!:Libraries/LibCore/puff.cpp' \
+    ':!:Libraries/LibELF/exec_elf.h' \
+)
+
+exit_status=0
+if (( ${#MISSING_NEWLINE_AT_EOF_ERRORS[@]} )); then
+    echo "Files with no newline at the end: ${MISSING_NEWLINE_AT_EOF_ERRORS[*]}"
+    exit_status=1
+fi
+if (( ${#MORE_THAN_ONE_NEWLINE_AT_EOF_ERRORS[@]} )); then
+    echo "Files that have blank lines at the end: ${MORE_THAN_ONE_NEWLINE_AT_EOF_ERRORS[*]}"
+    exit_status=1
+fi
+exit "$exit_status"

+ 1 - 0
Meta/lint-ci.sh

@@ -16,6 +16,7 @@ set +e
 for cmd in \
         Meta/check-ak-test-files.sh \
         Meta/check-debug-flags.sh \
+        Meta/check-newlines-at-eof.sh \
         Meta/check-style.sh \
         Meta/lint-executable-resources.sh \
         Meta/lint-ipc-ids.sh \