-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(utils): add defaultOptions to meta in rule #10339
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, @LuisUrrutia! 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. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 0537ef6. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
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.
thanks for doing this!
a few comments but it's looking good so far!
packages/utils/src/ts-eslint/Rule.ts
Outdated
|
||
defaultOptions?: 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.
All properties need JSDoc!
defaultOptions?: Options; | |
/** | |
* Specifies default options for the rule. If present, any user-provided options in their config will be merged on top of them recursively. | |
* This merging will be applied directly to `context.options`. | |
* If you want backwards-compatible support for earlier ESLint version; consider using the top-level `defaultOptions` instead. | |
* | |
* @since ESLint 9.15.0 | |
*/ | |
defaultOptions?: 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.
Added, but @since
can't be used with ESLint
word.
defaultOptions, | ||
meta, | ||
name, | ||
...rule | ||
}: Readonly< | ||
RuleWithMetaAndName<Options, MessageIds, PluginDocs> | ||
>): RuleModule<MessageIds, Options, PluginDocs> { | ||
return createRule<Options, MessageIds, PluginDocs>({ | ||
defaultOptions, | ||
meta: { | ||
...meta, | ||
defaultOptions, |
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.
It's worth noting that adding this to this function will fix the bug with base rule extensions because our codebase uses the RuleCreator
function -- but it might leave the broader ecosystem in a weird state.
This will cause all rules to have a different context.options
value when run under ESLint v9.15.0 -- which could cause breakages in the ecosystem.
For reference -- currently we do not modify the context.options
value -- meaning it exactly mirrors the value that a user sets in their config file and we instead pass the "merged options" in via a second argument -- create(context, mergedOptions)
.
So if you pass meta.defaultOptions
automatically then the first part of this behaviour no longer holds true and instead context.options
will represent the "merged options".
For now we should leave this function as-is, and instead update our extension rule implementation to pass defaultOptions
both in the top-level location (for our current rule logic) and in the meta.defaultOptions
location (for ESLint base rule logic).
@@ -13,10 +13,11 @@ export type NamedCreateRuleMetaDocs = Omit<RuleMetaDataDocs, 'url'>; | |||
|
|||
export type NamedCreateRuleMeta< | |||
MessageIds extends string, | |||
Options extends readonly unknown[], |
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.
Adding this new generic in this location is a breaking change.
It changes the meaning of existing code and could introduce type errors.
Instead it must be added after all type parameters AND it must be given a default value of []
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10339 +/- ##
==========================================
+ Coverage 86.63% 86.69% +0.06%
==========================================
Files 433 434 +1
Lines 15202 15227 +25
Branches 4439 4445 +6
==========================================
+ Hits 13170 13201 +31
+ Misses 1675 1670 -5
+ Partials 357 356 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@bradzacher I made the requested changes, but now I will add the |
Sorry about the commit spam. I just reverted some of the changes you made to limit them to exactly the rules touched in eslint/eslint#17656 |
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.
thanks for doing this!
I have tested this against 9.15 and this looks good!
* Setup GitHub Actions for Pull request and main branch * Fix regression caused by typescript-eslint in combination with eslint@9.15.0 Details on: typescript-eslint/typescript-eslint#10339 * Resolve linter issues after updating packages
When do you plan to release this fix? |
Please see the issue linked in the OP |
PR Checklist
Overview
ESLint v9.15.0 introduces default options using the
meta.defaultOptions
property. This PR updates the rules to adddefaultOptions
property tometa
object, and retains the previousdefaultOptions
placement to ensure backward compatibility.