Skip to content

Commit

Permalink
check-metadata.sh: ensure uniquness of key-value pairs
Browse files Browse the repository at this point in the history
Script "maintenance/check-metadata.sh" checks the presence of various
key-value pairs in metadata of userscripts [1] and userstyles [2].
However, it doesn't check the number of occurrences, which makes it
possible to have two `@license`s for example.

Upgrade the script check-metadata.sh to ensure that every key-value
pair/tag in metadata of userscripts and userstyles is present exactly
once.  Because functions has_namespace and has_homepageURL also check
correctness of the value, add extra checks without the value, so that
the script "check-metadata.sh" would complain about same key with
different values.

Closes #16

[1] https://violentmonkey.github.io/api/metadata-block/
[2] https://github.com/openstyles/stylus/wiki/Writing-UserCSS#metadata
  • Loading branch information
rybak committed Dec 30, 2023
1 parent 41657ad commit 96a1bd2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions maintenance/check-metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error () {
has_metadata_entry () {
# .user.jss files have slashes and spaces at the start of the line,
# but .user.css files do not
grep -q -E "^[/ ]*@${1}" "${2}"
test "$(grep -c -E "^[/ ]*@${1}" "${2}")" = 1
}

has_version () {
Expand All @@ -32,10 +32,12 @@ has_namespace () {
# have https://github.com/rybak, without the repository name
# both are fine
has_metadata_entry 'namespace *https://github.com/rybak' "$1"
has_metadata_entry 'namespace ' "$1"
}

has_homepageURL () {
has_metadata_entry 'homepageURL *https://github.com/rybak/atlassian-tweaks' "$1"
has_metadata_entry 'homepageURL ' "$1"
}

check () {
Expand All @@ -51,10 +53,10 @@ GITHUB_URL=https://github.com/rybak/atlassian-tweaks
res=true
for f in *.user.js *.user.css
do
check has_version "$f" "File '$f' is missing @version"
check has_license "$f" "File '$f' is missing @license"
check has_namespace "$f" "File '$f' is missing @namespace $GITHUB_URL"
check has_homepageURL "$f" "File '$f' is missing @homepageURL $GITHUB_URL"
check has_version "$f" "File '$f': invalid or missing @version"
check has_license "$f" "File '$f': invalid or missing @license"
check has_namespace "$f" "File '$f': invalid or missing @namespace $GITHUB_URL"
check has_homepageURL "$f" "File '$f' invalid or missing @homepageURL $GITHUB_URL"
done

$res

0 comments on commit 96a1bd2

Please sign in to comment.