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

🚀 Feature: Rule to flag empty arrays/objects that do nothing #683

Closed
3 tasks done
JoshuaKGoldberg opened this issue Dec 6, 2024 · 6 comments · Fixed by #741
Closed
3 tasks done

🚀 Feature: Rule to flag empty arrays/objects that do nothing #683

JoshuaKGoldberg opened this issue Dec 6, 2024 · 6 comments · Fixed by #741
Labels
status: accepting prs Please, send a pull request to resolve this! type: feature New enhancement or request

Comments

@JoshuaKGoldberg
Copy link
Owner

JoshuaKGoldberg commented Dec 6, 2024

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Overview

Quite a few package entries do nothing if they're an empty array or object. Some top-of-mind examples:

  • dependencies/devDependencies/peerDependencies
  • files
  • scripts

It'd be nice to have a lint rule that reports on them & autofixes them away.

Additional Info

This is similar on the surface to eslint/json#54, in that it's a rule for blank/empty entries. The difference here is that eslint-plugin-package-json is for a specific JSON schema. @eslint/json is general to all JSON.

Putting as status: in discussion for a bit because I suspect this might already exist somewhere else. Maybe one of the equivalents mentioned in #42? This feels like it should exist already...

This issue prompted by seeing a very nice cleanup by @crutchcorn in https://github.com/TryGhost/Ghost/pull/21818/files#r1873314451. Thanks Corbin! 😄

💖

@JoshuaKGoldberg JoshuaKGoldberg added type: feature New enhancement or request status: in discussion Not yet ready for implementation or a pull request labels Dec 6, 2024
@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Please, send a pull request to resolve this! and removed status: in discussion Not yet ready for implementation or a pull request labels Dec 31, 2024
@chouchouji
Copy link
Contributor

@JoshuaKGoldberg I want to ask a question about this lint rule. If the dependency fled is {}, how to fix it? Should we just remove dependency filed?

@JoshuaKGoldberg
Copy link
Owner Author

JoshuaKGoldberg commented Jan 17, 2025

By "dependency" do you mean dependencies? If so, yes: removing the field is what I'm suggesting.

{
   "name": "my-example",
-  "dependencies": {},
   "version": "0.1.2"
}

Same with devDependencies, peerDependencies, and several other fields.

Them being set to {} doesn't do anything for you or change the meaning of the package.json at all. So it's just a wasted extra line.

@chouchouji
Copy link
Contributor

By "dependency" do you mean dependencies? If so, yes: removing the field is what I'm suggesting.

{
"name": "my-example",

Them being set to {} doesn't do anything for you or change the meaning of the package.json at all. So it's just a wasted extra line.

Sorry, it is typo. I think I can have a try to complete it. Can you assign this issue to me?

@JoshuaKGoldberg
Copy link
Owner Author

I don't use any kind of issue assignment system, go ahead and send a PR. Thanks for offering! 🚀

@chouchouji
Copy link
Contributor

I don't use any kind of issue assignment system, go ahead and send a PR. Thanks for offering! 🚀

Thx

JoshuaKGoldberg pushed a commit that referenced this issue Jan 23, 2025
<!-- 👋 Hi, thanks for sending a PR to eslint-plugin-package-json! 💖.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

-   [x] Addresses an existing open issue: fixes #683
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

<!-- Description of what is changed and how the code change does that.
-->
Copy link

🎉 This is included in version v0.21.0 🎉

The release is available on:

Cheers! 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! type: feature New enhancement or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants