diff --git a/bin/_validate.sh b/bin/_validate.sh index 331c160..db2e09e 100755 --- a/bin/_validate.sh +++ b/bin/_validate.sh @@ -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 " @@ -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'" @@ -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')" diff --git a/bin/validate-configs.sh b/bin/validate-configs.sh index 6c83937..246a554 100755 --- a/bin/validate-configs.sh +++ b/bin/validate-configs.sh @@ -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}" diff --git a/config/default.yaml b/config/default.yaml index 3a7cf05..2ff64a8 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -3,7 +3,8 @@ # dirs: [ "." ] lints: - - paths: + - lint_id: default + paths: - "**/*" rules: - no-msdos-reserved diff --git a/config/self.yaml b/config/self.yaml index 248db31..48e9df2 100644 --- a/config/self.yaml +++ b/config/self.yaml @@ -8,7 +8,8 @@ ignore-dirs: - "target" - "_site" lints: - - paths: + - lint_id: self + paths: - "**/*" rules: - no-msdos-reserved diff --git a/docs/namelint-config-schema.yaml b/docs/namelint-config-schema.yaml index 41f4554..645c0b3 100644 --- a/docs/namelint-config-schema.yaml +++ b/docs/namelint-config-schema.yaml @@ -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 @@ -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 diff --git a/docs/namelint-rule-schema.yaml b/docs/namelint-rule-schema.yaml index 9329370..cccb8dd 100644 --- a/docs/namelint-rule-schema.yaml +++ b/docs/namelint-rule-schema.yaml @@ -97,3 +97,8 @@ properties: type: string required: - ruleset_id +anyOf: + - required: + - rules + - required: + - rulesets