Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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 onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedApr 12, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site settings. |
nx-cloudbot commentedApr 12, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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. |
Uh oh!
There was an error while loading.Please reload this page.
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 fordefaultOptions
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/...