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

[new rule] No global imports #390

Merged
merged 2 commits into from
Feb 8, 2023

Conversation

juanpcapurro
Copy link
Contributor

depends on #389

this is my first time near a syntax tree, so I'm looking forward to your feedback!

I also took the liberty of making it a recommended rule, but if there isn't consensus we could just drop the last commit

as always, see technical details in git history

@@ -9,7 +9,7 @@ title: "comprehensive-interface | Solhint"
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)

## Description
Check that all public or external functions are override. This is useful to make sure that the whole API is extracted in an interface.
Check that all public or external functions are override. This is iseful to make sure that the whole API is extracted in an interface.
Copy link
Collaborator

Choose a reason for hiding this comment

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

iseful ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's from the documentation update, from #389 , which this PR depends on.

I wanted to get feedback as early as possible, but for that you and other reviewers should look at the changes introduced in the last two commits.

It seems that it wasn't obvious and I want to be respectful of your time so I'll mark this PR as a draft until #389 is merged, sorry for the mixup

Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry... I was just going quickly through the changes, I saw this and just asked.... I'm not assigned full time to this project. And I'm also new to it. I did not approve the former pr because of that. Waiting a few days if fvitorio (the former maintainer) can check it as well... if not, I will do it.
Your contributions are very valuable, sorry if we can't keep up

@juanpcapurro juanpcapurro marked this pull request as draft January 26, 2023 19:43
@juanpcapurro juanpcapurro marked this pull request as ready for review January 27, 2023 14:35

SourceUnit(node) {
node.children.forEach((it) => {
if (it.type === 'ImportDirective' && !it.symbolAliases) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to use the ImportDirective visitor callback instead of iterating here. Not a big difference, but it's more idiomatic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially I had an issue by which the ImportDirective callback wasn't being called for the nodes not defining symbolAliases, which are the interesting ones. But I can't replicate it now 🙃 so it was probably something else.

pushed again using the ImportDirective callback as suggested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

seems to me this can be resolved and pr approved
do you agree @fvictorio ?

Copy link
Contributor

@fvictorio fvictorio left a comment

Choose a reason for hiding this comment

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

Minor comment, feel free to merge after it's fixed.

}

ImportDirective(node) {
if (node.type === 'ImportDirective' && !node.symbolAliases) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to check the node's type, the ImportDirective callback is only called when an import node is visited.

Suggested change
if (node.type === 'ImportDirective' && !node.symbolAliases) {
if (!node.symbolAliases) {

disallow imports that potentially pollute the namespace by importing
every defined name of the imported file.

~when registering an ImportDirective method on the NoGlobalImportsChecker
class, it's only called by imports that explicitly define a new
Identifier, the only way I found to find global imports is to search for
them in the SourceUnit nodes~

^ was recommended against in review and when trying to replicate it to
show the issue to fvictorio, I wasn't able to. So the cleaner way, using
the ImportDirective visitor, will remain.
I haven't seen global imports on recent codebases, and they're
[recommended against](https://docs.soliditylang.org/en/v0.8.17/layout-of-source-files.html#importing-other-source-files)
in the solidity documentation, so I think it's reasonable to have the
rule as recommended
@dbale-altoros dbale-altoros merged commit 57ce266 into protofire:master Feb 8, 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.

3 participants