Skip to content

Commit

Permalink
Install referenced schema in "eslint:validate" task
Browse files Browse the repository at this point in the history
The "eslint:validate" task validates the repository's ESLint configuration file against its JSON schema to catch any
problems with its data format.

In order to avoid duplication of content, JSON schemas may reference other schemas via the `$ref` keyword. The
ESLint configuration file schema was recently updated to share resources with a separate ESLint plugins configuration
schema, which caused the validation to start failing:

schema /tmp/eslintrc-schema-usLlcKrt8g.json is invalid
error: can't resolve reference https://json.schemastore.org/partial-eslint-plugins.json from id https://json.schemastore.org/eslintrc.json#
task: Failed to run task "eslint:validate": exit status 1

The solution is to configure the task to download that schema as well and also to provide its path to the avj-cli
validator via a `-r` flag.
  • Loading branch information
per1234 committed Jan 26, 2024
1 parent cc6f87c commit c972e1a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ tasks:
SCHEMA_URL: https://json.schemastore.org/eslintrc.json
SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="eslintrc-schema-XXXXXXXXXX.json"
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/partial-eslint-plugins.json
PARTIAL_ESLINT_PLUGINS_SCHEMA_URL: https://json.schemastore.org/partial-eslint-plugins.json
PARTIAL_ESLINT_PLUGINS_PATH:
sh: task utility:mktemp-file TEMPLATE="partial-eslint-plugins-schema-XXXXXXXXXX.json"
DATA_PATH: workflow-templates/assets/check-javascript/.eslintrc.yml
# ajv-cli identifies YAML-format data files by their file extension, so renaming is required:
# https://github.com/ajv-validator/ajv-cli/issues/117
Expand All @@ -406,11 +410,13 @@ tasks:
sh: task utility:mktemp-folder TEMPLATE="eslintrc-validate-XXXXXXXXXX"
cmds:
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}
- wget --quiet --output-document="{{.PARTIAL_ESLINT_PLUGINS_PATH}}" {{.PARTIAL_ESLINT_PLUGINS_SCHEMA_URL}}
- |
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
--all-errors \
-s "{{.SCHEMA_PATH}}" \
-r "{{.PARTIAL_ESLINT_PLUGINS_PATH}}" \
-d "{{.PROJECT_FOLDER}}/{{.DATA_PATH}}"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-files-task/Taskfile.yml

Check warning on line 422 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

422:121 [line-length] line too long (127 > 120 characters)

Check warning on line 422 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

422:121 [line-length] line too long (127 > 120 characters)
Expand Down

0 comments on commit c972e1a

Please sign in to comment.