From ce333d92859c2fbcb506294abf37fb0c9570de94 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 27 Jul 2020 11:58:15 -0700 Subject: [PATCH 1/4] Add script for finding files with unix line terminators --- scripts-dev/check_line_terminators.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 scripts-dev/check_line_terminators.sh diff --git a/scripts-dev/check_line_terminators.sh b/scripts-dev/check_line_terminators.sh new file mode 100755 index 000000000000..ccaf6aaa35d1 --- /dev/null +++ b/scripts-dev/check_line_terminators.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Copyright 2020 The Matrix.org Foundation C.I.C. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This script checks that line terminators in all repository files (excluding +# those in the .git directory) feature unix line terminators. +# +# Usage: +# +# ./check_line_terminators.sh +# +# The script will emit exit code 1 if any files that do not use unix line +# terminators are found, 0 otherwise. + +find . -path './.git/*' -prune -o -type f -print0 | xargs -0 grep -l $'\r$' && ( echo 'found files with CRLF line endings'; exit 1 ) From 07da48b35c662bc1fee3ee8229e1dd9462586879 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 27 Jul 2020 13:44:00 -0700 Subject: [PATCH 2/4] Tell grep to ignore binary files --- scripts-dev/check_line_terminators.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts-dev/check_line_terminators.sh b/scripts-dev/check_line_terminators.sh index ccaf6aaa35d1..8c98d1d251e5 100755 --- a/scripts-dev/check_line_terminators.sh +++ b/scripts-dev/check_line_terminators.sh @@ -24,4 +24,4 @@ # The script will emit exit code 1 if any files that do not use unix line # terminators are found, 0 otherwise. -find . -path './.git/*' -prune -o -type f -print0 | xargs -0 grep -l $'\r$' && ( echo 'found files with CRLF line endings'; exit 1 ) +find . -path './.git/*' -prune -o -type f -print0 | xargs -0 grep -I -l $'\r$' && ( echo 'found files with CRLF line endings'; exit 1 ) From e61042e3ca1a141835a8db3355ed0f15db56f168 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 27 Jul 2020 13:45:46 -0700 Subject: [PATCH 3/4] Add changelog --- changelog.d/7965.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7965.misc diff --git a/changelog.d/7965.misc b/changelog.d/7965.misc new file mode 100644 index 000000000000..ee9f1a7114a8 --- /dev/null +++ b/changelog.d/7965.misc @@ -0,0 +1 @@ +Add a script to detect source code files using non-unix line terminators. \ No newline at end of file From d899fdf1e6014b8f457952ecad8f6633ec9c7c27 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 27 Jul 2020 15:53:51 -0700 Subject: [PATCH 4/4] cd to the root of the repo before running --- scripts-dev/check_line_terminators.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts-dev/check_line_terminators.sh b/scripts-dev/check_line_terminators.sh index 8c98d1d251e5..0f430e83976d 100755 --- a/scripts-dev/check_line_terminators.sh +++ b/scripts-dev/check_line_terminators.sh @@ -24,4 +24,8 @@ # The script will emit exit code 1 if any files that do not use unix line # terminators are found, 0 otherwise. +# cd to the root of the repository +cd `dirname $0`/.. + +# Find and print files with non-unix line terminators find . -path './.git/*' -prune -o -type f -print0 | xargs -0 grep -I -l $'\r$' && ( echo 'found files with CRLF line endings'; exit 1 )