eslint-plugin-eslint-plugin icon indicating copy to clipboard operation
eslint-plugin-eslint-plugin copied to clipboard

New Rule: `no-incomplete-schema`

Open bmish opened this issue 3 years ago • 0 comments

or named require-meta-schema-completeness.

This could also potentially be part of eslint-plugin/require-meta-schema but that's probably too much in one rule.

This rule would check for common useless / no-op schemas as discussed in https://github.com/eslint/rfcs/pull/85#discussion_r775144472 such as:

  • {}
  • { type: "array" }
  • etc

And ensure:

  • Objects have additionalProperties: false to ensure all properties are included
  • Does not allow empty strings
  • uniqueItems: true for arrays
  • minItems: 1 for arrays
  • Array item types are specified
  • It looks like z-schema has some related checks

But the challenge is encouraging completeness while still allowing rules to have any valid schema / options format.

There's also strict mode in ajv that is related and that we could take ideas from to enforce. If ESLint ever upgraded ajv, like in the declined ajv v8 upgrade PR, it's worth considering enabling strict mode.

There are also a few other linters targeting JSON Schema:

  • https://github.com/ota-meshi/eslint-plugin-json-schema-validator

bmish avatar Sep 06 '22 18:09 bmish