question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support the `default` JSON Schema keyword

See original GitHub issue

Would be nice to be able to specify default values for the rule options in the schema.

See: https://github.com/epoberezkin/ajv#assigning-defaults

I think all you have to do is to set the useDefaults: true option in https://github.com/eslint/eslint/blob/2af94466fe8f87058fad4bd168958d2a7612a79d/lib/util/ajv.js#L18-L23

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Sep 14, 2018

This issue was accepted in the 2018/09/13 TSC meeting.

(Edit: Also, I noted that ajv’s validate method does mutate the argument passed in once useDefaults: true is enabled. So we’ll want to make sure we’re defensively cloning user options or otherwise avoiding problems as best we can)

1reaction
platinumazurecommented, Sep 12, 2018

TSC Summary:

JSON Schema supports a “default” keyword which allows schema authors to specify default values for optional properties in an object schema (among other cases). By allowing schemas to have defaults (a 1-line change in the ajv wrapper code), both core rules and custom rules could have default values in schemas.

Additionally (although maybe as a separate proposal), we could write some generic code when creating rule instances which would hydrate default values for any rule options not provided by the user, which would allow us to remove some code in all rules related to option defaults. There shouldn’t be any impact to users because the default keyword only has its semantic meaning as a keyword outside of property lists (i.e., rules with a “default” named option should not be affected).

TSC Question: Should we enable use of “default” keyword in rule schemas?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generic keywords — Understanding JSON Schema 2020-12 ...
The default keyword specifies a default value. This value is not used to fill in missing values during the validation process. Non-validation tools...
Read more >
Default value | Opis JSON Schema
You can specify a default value for an item using the default keyword. When a data doesn't have a corresponding value, the value...
Read more >
Supported JSON Schema Keywords - Swagger
default – the default value must conform to the specified schema. allOf – the subschemas must be OpenAPI schemas and not standard JSON...
Read more >
How to specify defaults conditionally with JSON Schema
The default key word in JSON Schema is an annotation key word. Annotation key words are used to denote information, however they have...
Read more >
Generic Keywords - JSON Schema
First, the "$schema" keyword specifies that the current schema follows the specification of the version 3 of JSON Schema. We can provide different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found