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(detect-non-literal-fs-filename): change to track non-top-level require() as well #105

Merged
merged 6 commits into from Jan 11, 2023

Conversation

ota-meshi
Copy link
Member

This PR modifies the detect-non-literal-fs-filename rule so that it also checks for non-toplevel require().

I tried to do something similar to the changes made to detect-non-literal-fs-filename (#92) to detect-child-process (#104), but I noticed that detect-non-literal-fs-filename does not check for inline require().

With this change, instead of checking the top level node, it checks the scope variable to keep track of where it was defined. It's working fine as the test case shows, but the change was big 😓.

Copy link
Contributor

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this. It looks like there's a conflict that needs addressing, plus on question.


const { getImportAccessPath } = require('../../rules/utils/import-utils');

const RuleTester = require('eslint').RuleTester;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you using RuleTester to test a function in import-utils? Can't you just use Mocha tests here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is possible to use Mocha without RuleTester. But that test would require parsing with espree, adding a parent field to each node, parsing the scope using eslint-scope, and emulating context.getScope(). I thought using RuleTester would be easier and more reliable testing than doing that, what do you think?
Or are you suggesting that I change the eslint rule for testing to run in eslint, and stop hacking the message validation?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's really confusing to be using RuleTester for something other than testing a rule. :) If you really need all of the ESLint infrastructure in place, then using the Linter object is a much clearer way to test this functionality.

@@ -1,41 +1,196 @@
module.exports.getImportAccessPath = getImportAccessPath;
Copy link
Contributor

Choose a reason for hiding this comment

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

Utility files should be outside of the rules directory.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hope to use it later in the detect-child-process rule as well. #104
So the utils directory is good for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine, but it shouldn't be in the rules directory. Please move it to the top level.

@ota-meshi
Copy link
Member Author

Thank you for the review.
I made changes to this PR. Could you please check again?

Copy link
Contributor

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@nzakas
Copy link
Contributor

nzakas commented Jan 11, 2023

Oops, looks like they’re a conflict. Can you take a look?

@ota-meshi
Copy link
Member Author

I resolved the conflict by merging from main.

@nzakas nzakas merged commit d3b1543 into main Jan 11, 2023
@nzakas nzakas deleted the improve-detect-non-literal-fs-filename branch January 11, 2023 21:29
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

2 participants