From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 2A2B23875A24; Mon, 25 Jul 2022 13:37:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A2B23875A24 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] binutils-gdb/git: highlight whitespace errors in source files X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: a6e4a48c02acf29d6bec2ff63fc909b57cf4bc78 X-Git-Newrev: f7f904e4fda6fb571d40a3547ed03ec6028e6694 Message-Id: <20220725133701.2A2B23875A24@sourceware.org> Date: Mon, 25 Jul 2022 13:37:01 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2022 13:37:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df7f904e4fda6= fb571d40a3547ed03ec6028e6694 commit f7f904e4fda6fb571d40a3547ed03ec6028e6694 Author: Andrew Burgess Date: Mon Jul 18 15:35:40 2022 +0100 binutils-gdb/git: highlight whitespace errors in source files =20 For a long time I've had this in my ~/.gitconfig: =20 [core] whitespace =3D space-before-tab,indent-with-non-tab,trailing-= space =20 which causes git to show me if I muck up and use spaces instead of tabs, or leave in trailing whitespace. I find this really useful. =20 I recently proposed adding something like this to the .gitattributes files for the GDB sub-directories (gdb, gdbsupport, and gdbserver)[1], however, the question was asked - couldn't this be done at the top level? =20 So, in this commit, I propose to update the top-level .gitattributes file, after this commit, any git diff on a C, C++, Expect, or TCL source file, will highlight the following whitespace errors: =20 (a) Use a space before a tab at the start of a line, =20 (b) Use of spaces where a tab could be used at the start of a line, and =20 (c) Any trailing whitespace. =20 Errors are only highlighted in the diff on new or modified lines, so you don't get spammed for errors on context lines that you haven't modified. =20 The only downside I see to adding this at the top level is if there are any sub-directories that don't follow the tabs/spaces indentation rules very well already, in those directories you'll end up hitting issues any time you edit a line. For GDB we're usually pretty good, so having this highlighting isn't an issue. =20 [1] https://sourceware.org/pipermail/gdb-patches/2022-July/190843.html Diff: --- .gitattributes | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.gitattributes b/.gitattributes index 06d51d28a95..6f7c6d8ba52 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18,3 +18,18 @@ # file gets renamed again ... =20 ChangeLog merge=3Dmerge-changelog + +# Setup whitespace error detection. +# +# (1) Spaces before tabs, +# +# (2) Use of spaces where a tab should be used, +# +# (3) Trailing whitespace, + +*.cxx whitespace=3Dspace-before-tab,indent-with-non-tab,trailing-space +*.cc whitespace=3Dspace-before-tab,indent-with-non-tab,trailing-space +*.cpp whitespace=3Dspace-before-tab,indent-with-non-tab,trailing-space +*.[cChH] whitespace=3Dspace-before-tab,indent-with-non-tab,trailing-space +*.exp whitespace=3Dspace-before-tab,indent-with-non-tab,trailing-space +*.tcl whitespace=3Dspace-before-tab,indent-with-non-tab,trailing-space