From 64d31f48d276aa491976fa7b0a8b1eddf9347ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Niew=C3=B6hner?= Date: Fri, 9 Apr 2021 16:26:32 +0200 Subject: [PATCH] lint: MAINTAINERS: check path matches to not only cover the directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gerrit is able to add reviewers based on entries in the `MAINTAINERS` file. For inclusion and exclusion matches either paths or regular expressions can be used. The syntax is described in the header of the file. When matching a path, there are two sensible possibilities: - `path/to/file` matches a file. - `path/to/dir/` matches a folder including its contents recursively. - `path/to/dir/*` matches all files in that folder, without recursing into its subfolders. The trailing slash in the second example is essential. Without it, only the directory entry itself matches when, for example, the folder gets deleted, renamed or its permissions get modified. Reviewers in the list won't get added to changes of any files or directories below that path. Thus, add a linter script to ensure a path match on a directory always ends with `/` or `/*` as shown above. Change-Id: I9873184c0df4a0b4455f803828e2719887e545db Signed-off-by: Michael Niewöhner Reviewed-on: https://review.coreboot.org/c/coreboot/+/52210 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber Reviewed-by: Angel Pons Reviewed-by: Patrick Georgi --- util/lint/lint-stable-027-maintainers-syntax | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 util/lint/lint-stable-027-maintainers-syntax diff --git a/util/lint/lint-stable-027-maintainers-syntax b/util/lint/lint-stable-027-maintainers-syntax new file mode 100755 index 0000000000..85245d1247 --- /dev/null +++ b/util/lint/lint-stable-027-maintainers-syntax @@ -0,0 +1,22 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0-or-later +# +# DESCR: Check that path patterns in MAINTAINERS have trailing slash + +use strict; +use warnings; + +open( my $file, "<", "MAINTAINERS" ) or die "Error: could not open file 'MAINTAINERS'\n"; + +while ( my $line = <$file> ) { + if ( $line =~ /^[FX]:\s+([^\s]*[^*\/\s])\s+$/ ) { # path patterns not ending with / or * + my $path = $1; + + if ( -d $path ) { + print "MAINTAINERS:$. missing trailing slash for directory match "; + print "`$path`\n"; + } + } +} + +close($file);