about summary refs log tree commit diff
diff options
context:
space:
mode:
authorclassabbyamp <dev@placeviolette.net>2022-05-01 23:50:46 -0400
committerLeah Neukirchen <leah@vuxu.org>2022-05-05 15:51:19 +0200
commitdc3688eb4fa1e475dd0ac6906fc16a261d46fafc (patch)
treee4d5269757508a6f1e201dfb034e6df33bc5a5fe
parent9469a0daba9cdf56a390abf18bb7729c7469bc2d (diff)
downloadxtools-dc3688eb4fa1e475dd0ac6906fc16a261d46fafc.tar.gz
xtools-dc3688eb4fa1e475dd0ac6906fc16a261d46fafc.tar.xz
xtools-dc3688eb4fa1e475dd0ac6906fc16a261d46fafc.zip
xlint: deduplicate $pkgname and $version
This is a slightly naïve solution that does not check if $pkgname
matches the template's directory. That would not be very trivial to do
to work with the git index functionality or subpackages, and I'm not
quite sure how to handle that.

Tested by putting two $pkgname and $version in a template.

Before:
```
$ xlint chezmoi
grep: the -P option only supports a single pattern
chezmoi'
chezmoi: 'pkgname' defined more than once
chezmoi: 'version' defined more than once
chezmoi: Place license= after pkgname=
chezmoi: Place maintainer= after version=
chezmoi:1: Header should be: # Template file for 'chezmoi
chezmoi:4: revision does not appear immediately after version
```

After:
```
$ xlint chezmoi
chezmoi: 'pkgname' defined more than once
chezmoi: 'version' defined more than once
chezmoi: Place license= after pkgname=
chezmoi: Place maintainer= after version=
chezmoi:4: revision does not appear immediately after version
```
-rwxr-xr-xxlint4
1 files changed, 2 insertions, 2 deletions
diff --git a/xlint b/xlint
index 7c281e2..2ec7d31 100755
--- a/xlint
+++ b/xlint
@@ -466,8 +466,8 @@ for argument; do
 	scan '^\t*[^ ]*\(\)(|   *){' 'use one space after function parenthesis'
 	scan '^\t*[^ ]*\(\)$' 'do not use a newline before function opening brace'
 	scan 'python_version=.*#[[:space:]]*unverified' 'verify python_version and remove "#unverified"'
-	pkgname=$(grep -Po "^pkgname=\K.*" "$template")
-	version=$(grep -Po "^version=\K.*" "$template")
+	pkgname=$(grep -Po "^pkgname=\K.*" "$template" | once)
+	version=$(grep -Po "^version=\K.*" "$template" | once)
 	scan "distfiles=.*\Q$version\E" 'use ${version} in distfiles instead'
 	scan "system_accounts=.*\b(?!($old_accounts))[a-zA-Z]" 'new accounts should be prefixed with underscore'
 	variables_order