Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions bin/_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ REPO_DIR="$( cd "${SCRIPT_DIR}/.." && pwd )"

SCHEMA_YAML=${1:-BAD}
YAML_DIR=${2:-BAD}
REF_SCHEMA_YAML=${3:-}
if [ "${SCHEMA_YAML}" = "BAD" ]; then
echo "ERROR: schema file not specified"
echo "Usage: $0 <schema.yaml> <target_dir>"
Expand All @@ -29,6 +30,11 @@ if [ ! -f "${SCHEMA_YAML}" ]; then
exit 1
fi

if [ -n "${REF_SCHEMA_YAML}" ] && [ ! -f "${REF_SCHEMA_YAML}" ]; then
echo "ERROR: ref schema file not found: ${REF_SCHEMA_YAML}"
exit 1
fi

# check that ajv is installed
if ! command -v ajv > /dev/null; then
echo "ERROR: ajv is not installed: try 'npm install -g ajv-cli'"
Expand All @@ -39,11 +45,20 @@ echo "INFO: validation starting at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"

for YAML_FILE in "${YAML_DIR}"/*.yaml; do
echo "INFO: validating ${YAML_FILE}"
ajv validate \
--errors=text \
--spec=draft2020 \
-s "${SCHEMA_YAML}" \
-d "${YAML_FILE}"
if [ -z "${REF_SCHEMA_YAML}" ]; then
ajv validate \
--errors=text \
--spec=draft2020 \
-s "${SCHEMA_YAML}" \
-d "${YAML_FILE}"
else
ajv validate \
--errors=text \
--spec=draft2020 \
-s "${SCHEMA_YAML}" \
-d "${YAML_FILE}" \
-r "${REF_SCHEMA_YAML}"
fi
done

echo "INFO: validation complete at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
3 changes: 2 additions & 1 deletion bin/validate-configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_DIR="$( cd "${SCRIPT_DIR}/.." && pwd )"

SCHEMA_YAML="${REPO_DIR}/docs/namelint-config-schema.yaml"
REF_SCHEMA_YAML="${REPO_DIR}/docs/namelint-rule-schema.yaml"
YAML_DIR="${REPO_DIR}/config"

"${SCRIPT_DIR}/_validate.sh" "${SCHEMA_YAML}" "${YAML_DIR}"
"${SCRIPT_DIR}/_validate.sh" "${SCHEMA_YAML}" "${YAML_DIR}" "${REF_SCHEMA_YAML}"
3 changes: 2 additions & 1 deletion config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#
dirs: [ "." ]
lints:
- paths:
- lint_id: default
paths:
- "**/*"
rules:
- no-msdos-reserved
Expand Down
3 changes: 2 additions & 1 deletion config/self.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ ignore-dirs:
- "target"
- "_site"
lints:
- paths:
- lint_id: self
paths:
- "**/*"
rules:
- no-msdos-reserved
Expand Down
8 changes: 8 additions & 0 deletions docs/namelint-config-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ properties:
description: Rules to specifically disable
items:
type: string
lint_id:
type: string
paths:
type: array
description: Path patterns to apply these rules to
Expand All @@ -45,11 +47,17 @@ properties:
type: string
anyOf:
- required:
- lint_id
- rulesets
- paths
- required:
- lint_id
- rules
- paths
rules:
$ref: namelint-rule-schema.json#/properties/rules
rulesets:
$ref: namelint-rule-schema.json#/properties/rulesets
required:
- dirs
- lints
5 changes: 5 additions & 0 deletions docs/namelint-rule-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ properties:
type: string
required:
- ruleset_id
anyOf:
- required:
- rules
- required:
- rulesets