-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): refactor schemas that use $ref
#6896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the PR, @bradzacher! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
arrays: { $ref: '#/items/0/$defs/valueWithIgnore' }, | ||
objects: { $ref: '#/items/0/$defs/valueWithIgnore' }, | ||
imports: { $ref: '#/items/0/$defs/valueWithIgnore' }, | ||
exports: { $ref: '#/items/0/$defs/valueWithIgnore' }, | ||
functions: { $ref: '#/items/0/$defs/valueWithIgnore' }, | ||
enums: { $ref: '#/items/0/$defs/valueWithIgnore' }, | ||
generics: { $ref: '#/items/0/$defs/valueWithIgnore' }, | ||
tuples: { $ref: '#/items/0/$defs/valueWithIgnore' }, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arrays: { $ref: '#/items/0/$defs/valueWithIgnore' }, | |
objects: { $ref: '#/items/0/$defs/valueWithIgnore' }, | |
imports: { $ref: '#/items/0/$defs/valueWithIgnore' }, | |
exports: { $ref: '#/items/0/$defs/valueWithIgnore' }, | |
functions: { $ref: '#/items/0/$defs/valueWithIgnore' }, | |
enums: { $ref: '#/items/0/$defs/valueWithIgnore' }, | |
generics: { $ref: '#/items/0/$defs/valueWithIgnore' }, | |
tuples: { $ref: '#/items/0/$defs/valueWithIgnore' }, | |
}, | |
arrays: { $ref: '#/$defs/valueWithIgnore' }, | |
objects: { $ref: '#/$defs/valueWithIgnore' }, | |
imports: { $ref: '#/$defs/valueWithIgnore' }, | |
exports: { $ref: '#/$defs/valueWithIgnore' }, | |
functions: { $ref: '#/$defs/valueWithIgnore' }, | |
enums: { $ref: '#/$defs/valueWithIgnore' }, | |
generics: { $ref: '#/$defs/valueWithIgnore' }, | |
tuples: { $ref: '#/$defs/valueWithIgnore' }, | |
}, |
Hey, just wanted to flag that I saw this limitation in ESLint when looking around there to understand how the schema logic worked and was considering contributing to ESLint to remove this limitation altogether: so the $refs are just hoisted to the top level schema. Not sure if that would be accepted, but given their docs I don't think it would be a breaking change (as consumers are suppoesd to expect that $refs don't work with array types). In any case, if we're using an undocumented feature of eslint we should probably have contract tests around eslint that it does validate these as expected, in case that logic does change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Would normally request changes on using Prettier for defaultOptions
too but I trust you 😄 and think it's fine as a followup.
@@ -34,6 +34,59 @@ function nodeIsParent(node: unist.Node<unist.Data>): node is unist.Parent { | |||
return 'children' in node; | |||
} | |||
|
|||
const prettierConfig = resolveConfig.sync(__dirname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Checklist
simple-array
should be disallowed by the schema #6852Overview
Updates rule schemas that use $ref to use an array-based schema instead of an object-based one and updates the doc gen to match.
ESLint will wrap an array schema in an array object:
[schema] -> { type: 'array', items: [schema] }
, so we can use that knowledge to reference the$defs
with#/items/0/$defs/...
.This saves us manually recreating the tuple validation that ESLint already does for us.
It does require us to rewrite the
$ref
for our doc gen because we reference the schema object directly (eg#/items/0/$defs/... -> #/$defs/...