Skip to content

docs: how to author plugins with configs that extend other configs #18753

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 3 commits into from
Aug 7, 2024

Conversation

alecgibson
Copy link
Contributor

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[x] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

It's not immediately clear from the current documentation how authors should migrate configs that extend other configs.

According to the full documentation, an array is actually expected, which isn't clear in the migration documentation.

This change updates the documentation to include an array example, and links back to the full documentation.

Is there anything you'd like reviewers to focus on?

It's not immediately clear from the current documentation how authors
should migrate configs that extend other configs.

According to the [full documentation][1], an array is actually
expected, which isn't clear in the migration documentation.

This change updates the documentation to include an array example, and
links back to the full documentation.

[1]: https://eslint.org/docs/latest/extend/plugins#configs-in-plugins
@alecgibson alecgibson requested a review from a team as a code owner August 5, 2024 15:41
Copy link

linux-foundation-easycla bot commented Aug 5, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@eslint-github-bot eslint-github-bot bot added the documentation Relates to ESLint's documentation label Aug 5, 2024
Copy link

netlify bot commented Aug 5, 2024

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit 8d1c510
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/66b31d31524a260008a72b9c
😎 Deploy Preview https://deploy-preview-18753--docs-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 configuration.

aladdin-add
aladdin-add previously approved these changes Aug 6, 2024
Copy link
Member

@aladdin-add aladdin-add 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 like another review before merging.

@aladdin-add aladdin-add added the accepted There is consensus among the team that this change meets the criteria for inclusion label Aug 6, 2024
Comment on lines 209 to 210
// the config referenced by example/recommended
extendedConfig: [
Copy link
Member

Choose a reason for hiding this comment

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

If this config will be imported as example.configs.recommended it should be named recommended, not extendedConfig. Otherwise, it should be imported as example.configs.extendedConfig in the example file below, and in the legacy config system it would be referenced by example/extendedConfig.

Suggested change
// the config referenced by example/recommended
extendedConfig: [
// the config referenced by example/recommended
recommended: [

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is already imported as example.configs.extendedConfig...?

Copy link
Member

Choose a reason for hiding this comment

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

In that case, can we remove the comment that says referenced by example/recommended since that's a different config in this example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha good catch. Bad copy/paste.

};
```

You should update your documentation so your plugin users know how to reference the exported configs. If your config is an array, consumers will have to spread it:
Copy link
Member

Choose a reason for hiding this comment

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

I'd recommend splitting this into two separate examples, one that shows spreading and one that doesn't, otherwise the last sentence here doesn't lead logically to the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kind of wanted them side-by-side to show that you may have some configs that shouldn't be spread, and some that should. Will tweak the copy, and if you still want it split after that copy tweak I can do that.

 - fix quote style
 - remove stale comment
 - clarify copy on spreading
You should update your documentation so your plugin users know how to reference the exported configs. If your config is an array, consumers will have to spread it:
You should update your documentation so your plugin users know how to reference the exported configs.

If your config is an object, consumers should not spread it; and if it's an array, they should:
Copy link
Member

Choose a reason for hiding this comment

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

This still implies that the following example shows just how to spread, and the verbiage is more confusing. Maybe something like this?

Suggested change
If your config is an object, consumers should not spread it; and if it's an array, they should:
If your exported config is an object, then your users can insert it directly into the config array; if your exported config is an array, then your users should use the spread operator (`...`) to insert the array's items into the config array. Here's an example with both an object config and an array config:

Comment on lines +231 to +234
export default [
example.configs.recommended, // Object, so don't spread
...example.configs.extendedConfig, // Array, so needs spreading
];
Copy link
Member

@fasttime fasttime Aug 7, 2024

Choose a reason for hiding this comment

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

Just a hint that if you use [].concat() to extend the configs, you don't need to care if they are arrays or not.

export default [].concat(
    example.configs.recommended,
    example.configs.extendedConfig,
);

also:

export default [
    example.configs.recommended,
    example.configs.extendedConfig,
].flat();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know, I also mentioned .flat() in my original issue.

It was just unclear to me from these migration docs if a plugin author could expect consumers to have to differentiate between different config styles (object vs array).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, when it's explicitly documented, users don't have to guess or account for both alternatives.

Copy link
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

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

LGTM. Pending @nzakas' review.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@nzakas nzakas merged commit 9fe068c into eslint:main Aug 7, 2024
20 checks passed
@alecgibson alecgibson deleted the plugin-migration-docs branch August 7, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion documentation Relates to ESLint's documentation
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy