Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

[package-json-lint] Add new rule require-dependencies-declared-at-appropriate-level #710

Merged
merged 15 commits into from
Oct 8, 2021

Conversation

pranav300
Copy link
Contributor

Summary

This PR adds a new rule require-no-unnecessary-dependency.
This rule doesn't allow unnecessary dependencies/peerDependencies, that can be shifted to devDependendies.

This rule is not applicable on devModule.

Closes #695

Additional Details

@cerner/terra

@pranav300 pranav300 self-assigned this Sep 28, 2021
@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 September 28, 2021 08:10 Inactive
@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 September 28, 2021 08:14 Inactive
@@ -0,0 +1,131 @@
const devDependencySet = [
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 have taken this set from devDependencies in packages in terra-toolkit and terra-core.
Please let me know if there are any packages that need to be added or removed.
Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

can we have a separate file for this ? as the list might grow.

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 don't think that is required as later many rules may have large sets. And having a different file for each of them and maintaining them seems unnecessary.

Let me know if you think otherwise?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to a separate file, but I'd rather start small and grow it as we run into issues that teams typically have been doing. I think the @babel, @cerner ones below are fine. Then maybe enzyme*, jest, postcss, and webpack*?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a seperate file dev-dependency-set.json here 71a07f7.

@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 September 29, 2021 10:44 Inactive
@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 October 1, 2021 18:11 Inactive
'svgo',
'terra-application',
'terra-button',
'terra-disclosure-manager',
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason that these terra components, lodash, commander, etc must be a dev dependency? I would think many consumers are currently have these as regular dependencies.

Copy link
Contributor Author

@pranav300 pranav300 Oct 5, 2021

Choose a reason for hiding this comment

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

I had run a script to get dev and peer dependencies from the mono-repo's. And in that some packages have these as both dependencies and devDependencies. I will go through them once and remove the unneeded dependencies from the set.

Edit: I have removed some of the packages from the set here d8f833e.

}
}
},
peerDependencies: (peerDependencies) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Both dependencies and peerDependencies do pretty much the same thing. Is it possible to consolidate their implementations to make it more reusable for both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated here d8f833e.

@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 October 5, 2021 05:32 Inactive
@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 October 5, 2021 05:33 Inactive
@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 October 5, 2021 06:07 Inactive
'bufferutil',
'chai',
'check-installed-dependencies',
'core-js',
Copy link
Contributor

Choose a reason for hiding this comment

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

I would think core-js can be a regular dependency. There are several other dependencies here that I'm not familiar with but ones like glob and postcss should be allowed as a regular dependency right?

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 have updated the set and kept only @babel, @cerner, and jest dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for going back and forth on this list. I think it is safe to keep the ones that we know with certainty that should be a dev dependencies, especially ones used for testing. For example, chai, sinon, mocha, lerna, gh-pages. I have seen projects adding wdio-mocha-framework as a regular dependency so anything wdio-* should be a dev dependency.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just saw Ryan's comment above. We can start small for now and add as go.

@@ -2,6 +2,9 @@

## Unreleased

* Added
* Added new rule `require-no-unnecessary-dependency`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this rule? require-dependencies-declared-at-appropriate-level? Something like that would be a little clearer i think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed the rule here 71a07f7

@ryanthemanuel ryanthemanuel had a problem deploying to terra-toolki-add-rule-r-r6ja94 October 7, 2021 17:24 Failure
@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 October 8, 2021 12:01 Inactive
@pranav300 pranav300 changed the title [package-json-lint] Add new rule require-no-unnecessary-dependency [package-json-lint] Add new rule require-dependencies-declared-at-appropriate-level Oct 8, 2021
@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 October 8, 2021 18:15 Inactive
@ryanthemanuel ryanthemanuel temporarily deployed to terra-toolki-add-rule-r-r6ja94 October 8, 2021 18:24 Inactive
@ryanthemanuel ryanthemanuel merged commit 16a9842 into main Oct 8, 2021
@ryanthemanuel ryanthemanuel deleted the add-rule-require-no-unnecessary-dependencies branch October 8, 2021 19:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants