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

Fix: double import issue #58

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Fix: double import issue #58

wants to merge 4 commits into from

Conversation

0xteddybear
Copy link

No description provided.

});
it('should replace path as instructed by remapping with all import syntaxes', function () {
const fileContent = `
import '../../../interfaces/ITest.sol';
Copy link
Member

Choose a reason for hiding this comment

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

I might be wrong here, but I don't think remappings work this way. If your remapping key is interfaces, ../../../interfaces should not be affected, only when it starts with interfaces/

Copy link
Author

Choose a reason for hiding this comment

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

👀 will check

import '../../../interfaces/ITest.sol';
import './someFile.sol';
`;
import './Contract.sol';
Copy link
Member

Choose a reason for hiding this comment

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

what do you think about adding something that should be automatically modified in between these lines? Just to make sure our code is not skipping all the imports after seeing that the first one does not need any modification

No need to add a new test, we could do it in this one

Copy link
Author

@0xteddybear 0xteddybear Oct 31, 2024

Choose a reason for hiding this comment

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

sure!

now that I think about it (related to your other comment) having multiple imports in a single line will probably break as well (but we could actually make that work without properly parsing the code). Will add a test for that too!

expect(transformedContent).to.include(`contract C {}`);
});

it.skip('should not have false positives choosing imports', () => {
Copy link
Member

Choose a reason for hiding this comment

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

why is this test being skipped? we are not able to know if we are talking about code or comment?

Copy link
Author

@0xteddybear 0xteddybear Oct 31, 2024

Choose a reason for hiding this comment

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

we are not, since we don't reuse an existing lexer+parser, and only do regular-style modifications to the code. For most cases it is sufficient though, and single-line comments are skipped since we match \s*import to detect imports

Also, its worth noting that the impact of modifying comments when we shouldn't is very low considering multi-line natspec is required to have a leading * which would not match the regex above

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