Skip to content

Consider reporting only the most specific error(s)? #278

@jenseng

Description

@jenseng

It would be great if only the most specific error(s) were reported. For example, given this GitHub Actions workflow file:

name: Push
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - runn: npm install # <-- whoopsie, a typo!
      - rn: npm run build # <-- uhoh, another one!
      - run: npm run test
      - run: npm run lint

You get the following errors:

   4:3  error  "jobs.test" must have required property 'uses'               json-schema-validator/no-invalid
   4:3  error  "jobs.test" must match exactly one schema in oneOf           json-schema-validator/no-invalid
   5:5  error  Unexpected property "jobs.test["runs-on"]"                   json-schema-validator/no-invalid
   6:5  error  Unexpected property "jobs.test.steps"                        json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must have required property 'uses'      json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must have required property 'run'       json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must match exactly one schema in oneOf  json-schema-validator/no-invalid
  12:9  error  Unexpected property "jobs.test.steps[2].runn"                json-schema-validator/no-invalid
  13:9  error  "jobs.test.steps[3]" must have required property 'uses'      json-schema-validator/no-invalid
  13:9  error  "jobs.test.steps[3]" must have required property 'run'       json-schema-validator/no-invalid
  13:9  error  "jobs.test.steps[3]" must match exactly one schema in oneOf  json-schema-validator/no-invalid
  13:9  error  Unexpected property "jobs.test.steps[3].rn"                  json-schema-validator/no-invalid

This can cause some confusion/churn; ideally just the Unexpected property "jobs.test.steps[2].runn" and Unexpected property "jobs.test.steps[3].rn" would get reported. I tried setting ajv's allErrors: false to reduce the noise, but that's worse (although the run error provides a good hint for the first typo, the second typo is not reported):

   4:3  error  "jobs.test" must have required property 'uses'               json-schema-validator/no-invalid
   4:3  error  "jobs.test" must match exactly one schema in oneOf           json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must have required property 'uses'      json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must have required property 'run'       json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must match exactly one schema in oneOf  json-schema-validator/no-invalid

I haven't dug into the code too deeply, but it seems like it should be possible to just keep the most specific errors (i.e. for each error we encounter, discard any errors from ancestor nodes). Perhaps this could be opt-in to start, WDYT? I'd be happy to create a PR if you're interested in this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions