Skip to content

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

Merged
merged 18 commits into from
Nov 17, 2024

Conversation

LuisUrrutia
Copy link
Contributor

@LuisUrrutia LuisUrrutia commented Nov 16, 2024

PR Checklist

Overview

ESLint v9.15.0 introduces default options using the meta.defaultOptions property. This PR updates the rules to add defaultOptions property to meta object, and retains the previous defaultOptions placement to ensure backward compatibility.

@typescript-eslint
Copy link
Contributor

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.

Copy link

netlify bot commented Nov 16, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 0537ef6
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/673965bc1e8ea90008217d3a
😎 Deploy Preview https://deploy-preview-10339--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: 98 (🔴 down 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.

Copy link

nx-cloud bot commented Nov 16, 2024

☁️ Nx Cloud Report

CI 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 targets

Sent with 💌 from NxCloud.

Copy link
Member

@bradzacher bradzacher left a 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!

Comment on lines 72 to 73

defaultOptions?: Options;
Copy link
Member

Choose a reason for hiding this comment

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

All properties need JSDoc!

Suggested change
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;

Copy link
Contributor Author

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.

Comment on lines 65 to 76
defaultOptions,
meta,
name,
...rule
}: Readonly<
RuleWithMetaAndName<Options, MessageIds, PluginDocs>
>): RuleModule<MessageIds, Options, PluginDocs> {
return createRule<Options, MessageIds, PluginDocs>({
defaultOptions,
meta: {
...meta,
defaultOptions,
Copy link
Member

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[],
Copy link
Member

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 []

@bradzacher bradzacher added bug Something isn't working awaiting response Issues waiting for a reply from the OP or another party labels Nov 16, 2024
@LuisUrrutia LuisUrrutia changed the title fix(utils): add defaultOptions to meta fix(utils): add defaultOptions to meta in rule Nov 16, 2024
Copy link

codecov bot commented Nov 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.69%. Comparing base (57d343b) to head (0537ef6).
Report is 12 commits behind head on main.

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     
Flag Coverage Δ
unittest 86.69% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...kages/eslint-plugin/src/rules/consistent-return.ts 93.75% <100.00%> (+0.13%) ⬆️
packages/eslint-plugin/src/rules/dot-notation.ts 96.66% <100.00%> (+0.11%) ⬆️
...kages/eslint-plugin/src/rules/init-declarations.ts 100.00% <ø> (ø)
packages/eslint-plugin/src/rules/max-params.ts 94.44% <ø> (ø)
...s/eslint-plugin/src/rules/no-dupe-class-members.ts 100.00% <ø> (ø)
...kages/eslint-plugin/src/rules/no-empty-function.ts 91.42% <100.00%> (+0.25%) ⬆️
...ackages/eslint-plugin/src/rules/no-invalid-this.ts 100.00% <100.00%> (ø)
packages/eslint-plugin/src/rules/no-loop-func.ts 93.93% <ø> (ø)
...es/eslint-plugin/src/rules/no-loss-of-precision.ts 100.00% <ø> (ø)
...ckages/eslint-plugin/src/rules/no-magic-numbers.ts 84.72% <ø> (ø)
... and 5 more

... and 11 files with indirect coverage changes

@LuisUrrutia
Copy link
Contributor Author

@bradzacher I made the requested changes, but now I will add the defaultOptions to other rules.

@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Nov 16, 2024
@bradzacher
Copy link
Member

bradzacher commented Nov 17, 2024

Sorry about the commit spam.
I tested your PR against 9.15 and found that it introduced some unexpected breakages.
You had applied the defaultOptions refactoring to every extension rule.
But this broke certain rules (eg prefer-destructuring) due to their more complex schemas!

I just reverted some of the changes you made to limit them to exactly the rules touched in eslint/eslint#17656

Copy link
Member

@bradzacher bradzacher left a 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!

@bradzacher bradzacher merged commit f5e23e2 into typescript-eslint:main Nov 17, 2024
62 checks passed
EduardoAC added a commit to EduardoAC/snap-components that referenced this pull request Nov 17, 2024
EduardoAC added a commit to EduardoAC/snap-components that referenced this pull request Nov 17, 2024
* 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
@pavelkornev
Copy link

When do you plan to release this fix?

@bradzacher
Copy link
Member

Please see the issue linked in the OP

@typescript-eslint typescript-eslint locked and limited conversation to collaborators Nov 18, 2024
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: [no-unused-expressions, no-empty-functions, possibly others...] extension rules crash with eslint v9.15.0
3 participants