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

feat(eslint-plugin): [max-params] don't count this: void parameter #7696

Merged
merged 11 commits into from Oct 17, 2023

Conversation

StyleShit
Copy link
Contributor

Closes #7538

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @StyleShit!

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 Sep 27, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit b69113a
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/652e90e056d41c00087fcaed
😎 Deploy Preview https://deploy-preview-7696--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 96 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

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

Comment on lines 19 to 37
const schema = [
{
type: 'object',
properties: {
maximum: {
type: 'integer',
minimum: 0,
},
max: {
type: 'integer',
minimum: 0,
},
countVoidThis: {
type: 'boolean',
},
},
additionalProperties: false,
},
] as JSONSchema4[];
Copy link
Contributor Author

@StyleShit StyleShit Sep 27, 2023

Choose a reason for hiding this comment

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

for some reason, I can't get deepMerge to work properly here.

I've tried adding these lines to add support for array overrides, but I'm not sure why it doesn't work:

 if (isObjectNotArray(firstValue) && isObjectNotArray(secondValue)) {
   // object type
   acc[key] = deepMerge(firstValue, secondValue);
+ } else if (Array.isArray(firstValue)) {
+   // array type
+   acc[key] = Object.values(
+     deepMerge({ ...firstValue }, { ...(secondValue as ObjectLike) }),
+   );
  } else {
   // value type
   acc[key] = secondValue;
 }

seems to work fine when isolated though:
https://tsplay.dev/wX1GLN


Anyway... I should've probably still hard-coded the values here since I don't support passing only a number like the base rule does (maybe I should?)

Base schema:
https://github.com/eslint/eslint/blob/main/lib/rules/max-params.js#L30-L53

Copy link
Member

Choose a reason for hiding this comment

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

Extended rules generally directly go off context.options, is that what you're looking for?

const [style, { allowSingleLine } = { allowSingleLine: false }] =
// eslint-disable-next-line no-restricted-syntax -- Use raw options for extended rules.
context.options;

Copy link
Contributor Author

@StyleShit StyleShit Oct 16, 2023

Choose a reason for hiding this comment

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

Nope, I'm talking about baseRule.meta.schema.
I had some issues when trying to add an option to the base schema, the deepMerge function seems to break it.
Is it OK to keep it hard-coded instead of extending the original schema in runtime?

hasSuggestions: baseRule.meta.hasSuggestions,
schema: baseRule.meta.schema,
},

Copy link
Member

Choose a reason for hiding this comment

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

Ah got it - yeah this is fine. Base rules don't change often and many others already hard-code it (e.g. dot-notation). Thanks for asking!

@StyleShit StyleShit marked this pull request as ready for review September 27, 2023 18:00
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.

Looks great to me! Nice and straightforward, I like it. 🙂

Left a couple of suggestions - what do you think?

packages/eslint-plugin/docs/rules/max-params.md Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/max-params.ts Outdated Show resolved Hide resolved
Comment on lines 19 to 37
const schema = [
{
type: 'object',
properties: {
maximum: {
type: 'integer',
minimum: 0,
},
max: {
type: 'integer',
minimum: 0,
},
countVoidThis: {
type: 'boolean',
},
},
additionalProperties: false,
},
] as JSONSchema4[];
Copy link
Member

Choose a reason for hiding this comment

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

Extended rules generally directly go off context.options, is that what you're looking for?

const [style, { allowSingleLine } = { allowSingleLine: false }] =
// eslint-disable-next-line no-restricted-syntax -- Use raw options for extended rules.
context.options;

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Oct 13, 2023
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Oct 16, 2023
packages/eslint-plugin/src/rules/max-params.ts Outdated Show resolved Hide resolved
Comment on lines 19 to 37
const schema = [
{
type: 'object',
properties: {
maximum: {
type: 'integer',
minimum: 0,
},
max: {
type: 'integer',
minimum: 0,
},
countVoidThis: {
type: 'boolean',
},
},
additionalProperties: false,
},
] as JSONSchema4[];
Copy link
Member

Choose a reason for hiding this comment

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

Ah got it - yeah this is fine. Base rules don't change often and many others already hard-code it (e.g. dot-notation). Thanks for asking!

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.

Looks great, thanks for iterating on this! Great work 🚀

Just a couple of small things that I can touch up before merging.

Woman at computer saying 'oh, hell yes'

packages/eslint-plugin/src/rules/max-params.ts Outdated Show resolved Hide resolved
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
@JoshuaKGoldberg JoshuaKGoldberg merged commit 6398d3f into typescript-eslint:main Oct 17, 2023
46 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Base rule extension: [max-params] don't count this: void
2 participants