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

feat: add local-dependency rule #11

Merged

Conversation

kendallgassner
Copy link
Collaborator

Basically I keep making a mistake where I case am installing a local dependency using "link" and I mess up the casing:

This:

  "devDependencies": {
         "some-package": "link:../folder",
   }

Should be

  "devDependencies": {
         "some-package": "link:../Folder",
   }

Npm doesn't support link but yarn does. When the path is wrong yarn does not sub out the link when releasing.

@kendallgassner
Copy link
Collaborator Author

Hi @zetlen! Happy new year! Any chance you can take a look at this.

Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Cool, this is definitely useful! Requested a few changes here and there and left some questions/suggestions too. ✨

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
// Rule Definition
//------------------------------------------------------------------------------

function fileExistsWithCaseSync(filepath) {
Copy link
Owner

Choose a reason for hiding this comment

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

[Suggestion] Resolving a path to a package can be pretty tricky 😄. I would think require.resolve would work instead of the body of this function, to avoid a recursive call. Have you tried that?

Note that ESM environments might need https://nodejs.org/api/module.html#modulecreaterequirefilename...

lib/rules/local-dependency.js Outdated Show resolved Hide resolved
lib/rules/local-dependency.js Outdated Show resolved Hide resolved
tests/lib/__fixtures__/local-dependency/package.json Outdated Show resolved Hide resolved
tests/lib/rules/local-dependency.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
lib/rules/local-dependency.js Outdated Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg added the status: waiting for author Needs an action taken by the original poster label Sep 13, 2023
README.md Outdated Show resolved Hide resolved
);

try {
if (!require.resolve(filePath)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the tip @JoshuaKGoldberg! I am not totally following the create resolve comment but it seems like require.resolve is working.

Copy link
Owner

Choose a reason for hiding this comment

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

I was thinking that if & when ESLint supports running rules as ESM, this might crash. But I suppose we can cross that bridge when we get to it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

At some point Node will support https://nodejs.org/api/esm.html#importmetaresolvespecifier so you could do a forward-compatible feature detection here.

@JoshuaKGoldberg JoshuaKGoldberg removed the status: waiting for author Needs an action taken by the original poster label Sep 14, 2023
Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @kendallgassner! I'm not used to coming across three year old PRs and the original author immediately responding to review 😄 this was wonderful.

Will leave open for a bit in case @zetlen wants to give input. Setting myself a reminder to check back in next week.

docs/rules/valid-local-dependency.md Outdated Show resolved Hide resolved
docs/rules/valid-local-dependency.md Outdated Show resolved Hide resolved
lib/index.js Outdated Show resolved Hide resolved
Copy link
Owner

Choose a reason for hiding this comment

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

Heh, this keeps happening to me too. Hoping to get #33 / #39 working Soon™️. I'll try to remember to revert before merge.

For reference, npx npm@6 instead of npm worked on my machine.

lib/rules/valid-local-dependency.js Outdated Show resolved Hide resolved
} catch (e) {
context.report({
node: packageRoot,
message: `The package ${key} does not exist given the specified path: ${value}.`
Copy link
Owner

Choose a reason for hiding this comment

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

[Thoughts] It'd be nice if it used a different, more explicit message if the only difference is casing. But that's probably better as a follow-up issue. I bet it's surprisingly hard to get right 😄 .

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Technically it will catch spelling mistakes and non-existing packages.... but package managers should catches those so the rule is mostly useful for casing errors.

Copy link
Owner

Choose a reason for hiding this comment

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

Good point. I think I'd personally still interpret it for both, since it gives the nice errors before package managers would.

@zetlen
Copy link
Collaborator

zetlen commented Sep 14, 2023

@JoshuaKGoldberg You have my general signoff going forward with this and the rest of the code! Don't hesitate to ask me questions, but don't worry about my rubber stamp.

@JoshuaKGoldberg
Copy link
Owner

Just a heads up @kendallgassner, I changed the license for future versions of the library to MIT in #38. That doesn't impact reviewing this PR at all - I just don't know how changing a license does/should impact existing PRs.

@JoshuaKGoldberg JoshuaKGoldberg changed the title Add local-dependency rule feat: add local-dependency rule Sep 19, 2023
@JoshuaKGoldberg JoshuaKGoldberg merged commit 8b09206 into JoshuaKGoldberg:master Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants