Skip to content
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

fix(eslint-plugin): refactor schemas that use $ref #6896

Closed
wants to merge 1 commit into from

Conversation

bradzacher
Copy link
Member

PR Checklist

Overview

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/...

@bradzacher bradzacher added the bug Something isn't working label Apr 12, 2023
@typescript-eslint
Copy link
Contributor

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.

@netlify
Copy link

netlify bot commented Apr 12, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit d317fbc
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/64373d93f1349e000831ca57
😎 Deploy Preview https://deploy-preview-6896--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Comment on lines +70 to 78
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' },
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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' },
},

@domdomegg
Copy link
Contributor

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.

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nitpick] Now we're mixing our style & the default, heh.

Screenshot of array-type mixing single and double apostrophes

@bradzacher
Copy link
Member Author

closing in favour of #6899 and #6894

@bradzacher bradzacher closed this Apr 20, 2023
@bradzacher bradzacher deleted the fix-schemas-20230413 branch April 20, 2023 12:00
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [array-type] the config simple-array should be disallowed by the schema
4 participants