Skip to content

Do not warn on unused bindings whose names begin with _ #757

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

Merged

Conversation

ikappaki
Copy link
Contributor

Hi,

could you please review patch to not work on unused bindings whose name begins with _. It addresses #756.

I've addressed some of such warnings coming up when running the nrepl-server, and added a test.

Thanks

Copy link
Member

@chrisrink10 chrisrink10 left a comment

Choose a reason for hiding this comment

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

The compiler already ignores symbols entitled _ for just this purpose.

I am ok with the patch for rare cases where _ may be insufficient, but in my opinion every one of the _ prefixed names you've included here should just be _ rather than _{name} as they are unused and their names are irrelevant.

@ikappaki
Copy link
Contributor Author

The compiler already ignores symbols entitled _ for just this purpose.

I am ok with the patch for rare cases where _ may be insufficient, but in my opinion every one of the _ prefixed names you've included here should just be _ rather than _{name} as they are unused and their names are irrelevant.

Thank you, knowing the name of the thing that you want to ignore is very useful, I use it all the time. It provides more information about the current context.

@ikappaki ikappaki force-pushed the feature/unused-warning-underscore branch from fd0674b to 310b155 Compare December 29, 2023 20:07
@chrisrink10
Copy link
Member

Upon further reflection, I don't think I agree with this patch. The compiler explicitly supports ^:no-warn-when-unused metadata for suppressing the warning in cases where a name is desired even if unused.

Thank you, knowing the name of the thing that you want to ignore is very useful, I use it all the time. It provides more information about the current context.

As to this point, there are cases where that may be true and others where I strongly disagree. For cases such as this example below, there is no value in having a name bound and it is often ignored in Python (by not binding a name) and in Clojure:

(catch python/Exception _e
   )

@ikappaki
Copy link
Contributor Author

Upon further reflection, I don't think I agree with this patch. The compiler explicitly supports ^:no-warn-when-unused metadata for suppressing the warning in cases where a name is desired even if unused.

allowing a _ prefix gives the finest granularity down to the binding level, while a the above metadata value applies to everything in the scope of the metadata, so it's not the same.

Thank you, knowing the name of the thing that you want to ignore is very useful, I use it all the time. It provides more information about the current context.

As to this point, there are cases where that may be true and others where I strongly disagree. For cases such as this example below, there is no value in having a name bound and it is often ignored in Python (by not binding a name) and in Clojure:

(catch python/Exception _e
   )

I still find it useful that what we ignore even in this case has a name, name e which is what we usually use for the exception. Perhaps that is a personal preference.

btw, this is the standard behavior of the clj-kondo linter, here is an example from Calva in visual studio which uses clj-kondo for linting (the wiggly line inidcates an error, in this case unused binding):

image

@chrisrink10
Copy link
Member

allowing a _ prefix gives the finest granularity down to the binding level, while a the above metadata value applies to everything in the scope of the metadata, so it's not the same.

The metadata ^:no-warn-when-unused is per-binding as you can see here:

([^:no-warn-when-unused type aseq]

That being said, since you have indicated that this is something you find useful and is part of other community projects I am willing to accept the patch to suppress the Basilisp compiler's warnings with _ prefixed names.

However, I do not prefer that style and do not want to use it for code in this repository. In general I do not prefer to give bindings names where it is not required or where it is not serving an explicit documentation purpose. Therefore, I would ask that you please revert the suppressions included in this PR using this style to use _.

@ikappaki ikappaki force-pushed the feature/unused-warning-underscore branch from 310b155 to 62fa65f Compare January 4, 2024 22:34
@ikappaki
Copy link
Contributor Author

ikappaki commented Jan 4, 2024

allowing a _ prefix gives the finest granularity down to the binding level, while a the above metadata value applies to everything in the scope of the metadata, so it's not the same.

The metadata ^:no-warn-when-unused is per-binding as you can see here:

([^:no-warn-when-unused type aseq]

That being said, since you have indicated that this is something you find useful and is part of other community projects I am willing to accept the patch to suppress the Basilisp compiler's warnings with _ prefixed names.

However, I do not prefer that style and do not want to use it for code in this repository. In general I do not prefer to give bindings names where it is not required or where it is not serving an explicit documentation purpose. Therefore, I would ask that you please revert the suppressions included in this PR using this style to use _.

Great thanks, Updated unused bindings to '_', I didn't realise you can have metadata at the binding level, thanks for the tip.

@chrisrink10 chrisrink10 merged commit ae360e5 into basilisp-lang:main Jan 4, 2024
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