Skip to content

Commit

Permalink
improve scripts to prevent some incorrect rule ID anchors.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrop committed Aug 10, 2018
1 parent f11f3d2 commit 002c666
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rm -rf ${BUILD_DIR}
mkdir ${BUILD_DIR}
docker pull asciidoctor/docker-asciidoctor

./check_uniqueness_of_rule_ids.sh
./check_rule_ids.sh

docker run -v ${SCRIPT_DIR}:/documents/ asciidoctor/docker-asciidoctor asciidoctor -D /documents/output index.adoc
docker run -v ${SCRIPT_DIR}:/documents/ asciidoctor/docker-asciidoctor asciidoctor-pdf -D /documents/output index.adoc
Expand Down
20 changes: 20 additions & 0 deletions check_rule_ids.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# This script checks if any rule id has been used more than once; can be also used as a pre-commit git hook ;)

CONTENT_DIR=chapters

duplicated_ids=`grep -r -o -E '\[#[0-9]+]' ${CONTENT_DIR} | sort |uniq -d`

if [ -n "$duplicated_ids" ]; then
echo "Duplicated Rule IDs: `echo ${duplicated_ids} | tr -d '\n'`"
echo "Please make sure the Rule ID anchors are unique"
exit 1
fi

incorrect_ids=`grep -r -n -E '.*(\[[0-9]+\]|\[ +#?[0-9]+ +\]).*' ${CONTENT_DIR}`

if [ -n "${incorrect_ids}" ]; then
echo -e "Incorrect Rule IDs:\n ${incorrect_ids}"
echo "Please make sure that the Rule ID anchors conform to '\[#[0-9]+\]'"
exit 1
fi
14 changes: 0 additions & 14 deletions check_uniqueness_of_rule_ids.sh

This file was deleted.

0 comments on commit 002c666

Please sign in to comment.