-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix: allow packageDir and readPkgUp logic to play nice #1104
base: main
Are you sure you want to change the base?
Conversation
@benmosher @ljharb This is a fix to what was missed in #1085 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide some tests that would fail without this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed with @ljharb, need tests that would otherwise fail without this so that we know it's working. though it is good to know (though a bit weird?) that it doesn't impact any existing tests. wasn't paying close enough attention, it did break existing tests, so the real question is whether it is the new ones for the last release
@benmosher @ljharb So, I think this test is actually incorrect. With my fix, this test fails (succeeds where expected to fail). I think that particular test should instead be: test({
code: 'import leftPad from "left-pad";',
filename: path.join(packageDirMonoRepoWithNested, 'foo.js'),
errors: [{
ruleId: 'no-extraneous-dependencies',
message: '\'left-pad\' should be listed in the project\'s dependencies. Run \'npm i -S left-pad\' to add it',
}],
}), Because, react is available via That covers the "invalid" use case. To cover the valid one, I am thinking to add this as one of the test({
code: 'import leftPad from "left-pad";',
filename: path.join(packageDirMonoRepoWithNested, 'foo.js'),
options: [{packageDir: packageDirMonoRepoRoot}],
}), Make sense? |
I've updated this pr to reflect my last comment. |
243487a
to
d633420
Compare
@@ -243,24 +248,23 @@ ruleTester.run('no-extraneous-dependencies', rule, { | |||
options: [{packageDir: packageDirMonoRepoWithNested}], | |||
errors: [{ | |||
ruleId: 'no-extraneous-dependencies', | |||
message: "'left-pad' should be listed in the project's dependencies. Run 'npm i -S left-pad' to add it", | |||
message: '\'left-pad\' should be listed in the project\'s dependencies. Run \'npm i -S left-pad\' to add it', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are all these quotes changes necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb Yea, oddly enough - they were actually failing lint for me...Strings must use singlequote. (quotes)
. So, I just made it consistent with the rest of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, strange. the linter should be ignoring cases where it minimizes escaping backslashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea.. shouldn't it prefer backticks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if there's interpolations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still seems like it should be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb https://github.com/hulkish/eslint-plugin-import/blob/2e41085228ddd026ac7735eff36247b7f4d53d61/tests/src/rules/no-extraneous-dependencies.js as u can see, this change is consistent with the rest of the file. It actually fails lint without this change for me with the existing (in master).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, i can see now this was corrected in master, so ill revert.
}], | ||
}), | ||
test({ | ||
code: 'import react from "react";', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this test case is supposed to pass, let's move it to "valid"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I solved this by:
- keeping this test. since it's also good to be checking
- added exact original test to valid, here https://github.com/benmosher/eslint-plugin-import/pull/1104/files#diff-05140578b7a943405919d8a058934d1dR97
context.report({ | ||
message: 'The package.json file could not be parsed: ' + e.message, | ||
loc: { line: 0, column: 0 }, | ||
}) | ||
} else { | ||
throw e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb Thought I should make note of this.. We were swallowing "all else" errors before. I thought that was a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing these errors will crash eslint - I'm not sure if that's better than silently logging them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, what if its a permission error? Shouldn't that crash eslint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it perhaps should warn on the line, but not crash eslint altogether
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What way should i do that? I'm thinking:
} else {
context.report({
message: e.message,
loc: { line: 0, column: 0 },
})
}
Atlhough, I think this is an error related to the package.json loading/parsing in this instance, and should probably somehow be attached to that instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is updated. @ljharb, @benmosher anything else?
Just wanted to check in on this PR and see if there's any additional changes that need to be made for it to be merged. |
…ated filename instead of context.getFilename()
@dmk255 I think this is all - unless there's more req changes. |
@benmosher ok i think all concerns mentioned above are resolved, now. No more changes planned from me, unless requested. |
Might fix #1109 |
Hey guys, any update on this one? Will it be merged/released soonish? :) Thank you. |
Just chiming in given that there's been a bit of time since the last comment - any chance this may be merged soonish? Thank you! |
@benmosher any update on this? I don't think it's understood that the |
After thinking about this and discussing offline with @hulkish, it kind of seems to me like the current packageDir option is actually not useful. Perhaps instead of "fixing" it with this new merging behavior, we should add a per-category packageDir option that has the new behavior? Something like this: 'import/no-extraneous-dependencies': [2, {
dependencies: false, // or true
optionalDependencies: ['pattern/*/1', 'pattern/**/2'],
peerDependencies: {
patterns: ['pattern/*/1', 'pattern/**/2'],
additionalPackageDirs: ['../', 'somewhere else'],
},
}] Thoughts? |
@ljharb In your example snippet, I'm assuming |
@hulkish it would be the same value that's currently already supported in the schema i indicated under "optionalDependencies". |
I'm a little confused as to the use of Also, as a user of a monorepo, my root package.json doesn't contain "peerDependencies" in the traditional sense but rather devDependencies that are shared across my packages. I would find having the following valuable:
Presently this PR fixes the first point. I've been able to use it by forking @hulkish's repo and importing that in my package.json. I'm entirely not sure what benefits @ljharb's proposal will grant though I definitely could be missing something. |
@dmk255 with my suggestion, you'd configure eslint to allow devDeps to be declared in the root, but regular deps to only be declared in the subproject's package.json. |
@ljharb That sounds great - would you be able to give an example of the syntax you're considering to be able to do that? I don't immediately see how it fits into the example above. |
@dmk255 'import/no-extraneous-dependencies': [2, {
dependencies: true,
devDependencies: {
additionalPackageDirs: ['.'],
},
}] This would require that deps be in the closest package.json, but devDeps could be there OR in the current dir's package.json. |
Hey, let me ask as well. Here is our use case:
Will proposed solution be able to handle that case? (e.g. eslint to lookup dependencies in root package.json when linting subproject with empty deps). P.S> we usually run eslint from root, like: Thank you. |
@dvsekhvalnov yes, since it's "additional" - it merges - both this PR and my suggestion would address your use case. |
Ok, sounds good. Any update on when any of proposed fixes can be released? :) |
@dvsekhvalnov I am going to refactor this pr a bit to meet the functionality described in From there, I think the plan is to merge that functionality (assuming all is well). Since, currently the packageDir option doesn't quite fit the need. |
What is remaining on this PR? Anything I can do to help get this merged? |
@benmosher and all, i have use case for this change, can try to test if you can explain how i can get workable copy of non-released version. |
@dvsekhvalnov I think you should be able to check out @hulkish branch and then link it in your project. Something like:
Then try running the linter. That should hopefully have it so that your project's eslint-plugin-import is actually linked to @hulkish 's version |
I cloned @hulkish 's fork and this seems to fix my monorepo woes. |
I would merge but it's not clear to me why there are conflicts nor how to resolve them for the issues you are all facing. @hulkish are you able to resolve? |
is the PR not in a testable state? I cloned @hulkish's fork and attempted seeing if this would resolve our monorepo lint issues particular to eslint-plugin-import and it did not... as I was about to post I realized that the pr comments are from 2018 but there are referenced from 2 days ago so the conflicts are probably real |
ping @hulkish - any interest in rebasing this PR? |
Fixes #1103, #1109