-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [max-params] don't count this: void
parameter
#7696
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
Conversation
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. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
const schema = [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
maximum: { | ||
type: 'integer', | ||
minimum: 0, | ||
}, | ||
max: { | ||
type: 'integer', | ||
minimum: 0, | ||
}, | ||
countVoidThis: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
] as JSONSchema4[]; |
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.
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
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.
Extended rules generally directly go off context.options
, is that what you're looking for?
typescript-eslint/packages/eslint-plugin/src/rules/brace-style.ts
Lines 30 to 32 in ca1abb5
const [style, { allowSingleLine } = { allowSingleLine: false }] = | |
// eslint-disable-next-line no-restricted-syntax -- Use raw options for extended rules. | |
context.options; |
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.
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?
typescript-eslint/packages/eslint-plugin/src/rules/brace-style.ts
Lines 25 to 27 in ca1abb5
hasSuggestions: baseRule.meta.hasSuggestions, | |
schema: baseRule.meta.schema, | |
}, |
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.
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!
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.
Looks great to me! Nice and straightforward, I like it. 🙂
Left a couple of suggestions - what do you think?
const schema = [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
maximum: { | ||
type: 'integer', | ||
minimum: 0, | ||
}, | ||
max: { | ||
type: 'integer', | ||
minimum: 0, | ||
}, | ||
countVoidThis: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
] as JSONSchema4[]; |
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.
Extended rules generally directly go off context.options
, is that what you're looking for?
typescript-eslint/packages/eslint-plugin/src/rules/brace-style.ts
Lines 30 to 32 in ca1abb5
const [style, { allowSingleLine } = { allowSingleLine: false }] = | |
// eslint-disable-next-line no-restricted-syntax -- Use raw options for extended rules. | |
context.options; |
const schema = [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
maximum: { | ||
type: 'integer', | ||
minimum: 0, | ||
}, | ||
max: { | ||
type: 'integer', | ||
minimum: 0, | ||
}, | ||
countVoidThis: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
] as JSONSchema4[]; |
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.
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!
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.
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Closes #7538