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

ESLINTJS-49 Rule no-implicit-dependencies doesn't work #4819

Merged
merged 4 commits into from
Sep 19, 2024

Conversation

ericmorand-sonarsource
Copy link
Contributor

@ericmorand-sonarsource ericmorand-sonarsource commented Sep 17, 2024

Fixes ESLINTJS-49

@ericmorand-sonarsource ericmorand-sonarsource changed the title ESLINTJS-49 Rule S4328 doesn't work ESLINTJS-49 Rule no-implicit-dependencies doesn't work Sep 17, 2024
@ericmorand-sonarsource ericmorand-sonarsource marked this pull request as ready for review September 17, 2024 13:50
@@ -20,11 +20,6 @@
import { RuleTester } from 'eslint';
import { rule } from './';
import path from 'path';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should do the same for all rules calling loadPackageJsons in the unit tests

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 agree, but it would require another broader ticket. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, check my comment below, we can create tickets for all rules having same issue

},
): Array<PackageJson> => {
// if the fileName is not a child of the working directory, we bail
const relativePath = Path.relative(workingDirectory, fileName);
Copy link
Contributor

Choose a reason for hiding this comment

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

seems qa in failing in windows, it may be due to backward slashes. Check other helpers where we always transform paths with toUnixPath helper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. The path module is OS-aware, though. If this fails, it means that at some point we are using explicit path separator.

Copy link
Contributor

Choose a reason for hiding this comment

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

but some paths are sent from java. to be sure we are working with the proper paths, always use path.unix methods. Windows supports in any case forward slashes also

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 moved to path/posix.

@@ -35,8 +37,19 @@ const messages = {
export const rule: Rule.RuleModule = {
meta: generateMeta(meta as Rule.RuleMetaData, { messages, schema }),
create(context: Rule.RuleContext) {
// we need to find all the npm manifests from the directory of the analyzed file to the context working directory
const manifests = getManifests(context.filename, context.cwd, fs);
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 like this logic to sit in the package-json helpers, I think other rules are affected by this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the rest of the code, the one that gather the dependencies? If so, I didn't want to add another getDependencies method there as there already is one and I don't feel comfortable changing things that are outside of the scope of the ticket.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok fair enough. can you please also check what other rules depend on having the package-json cache? just create tickets for those as well pls and we'll see how we prepare the helper

@vdiez
Copy link
Contributor

vdiez commented Sep 19, 2024

would be nice to add an integration test so that we are sure the rule works now in eslint context

Copy link
Contributor

@vdiez vdiez left a comment

Choose a reason for hiding this comment

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

LGTM!

@ericmorand-sonarsource ericmorand-sonarsource merged commit 7dc3241 into master Sep 19, 2024
15 of 16 checks passed
@ericmorand-sonarsource ericmorand-sonarsource deleted the ESLINTJS-49 branch September 19, 2024 13:02
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.

2 participants