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

Provide a way to disable warnings for particular macros, or inside all macro invocations #114

Closed
jafingerhut opened this issue Nov 26, 2014 · 4 comments

Comments

@jafingerhut
Copy link
Collaborator

Given that:

  • many libraries provide macros
  • some of those macros will expand into expressions that Eastwood normally warns about, but having such suspicious-looking expressions in a macro expansion is perhaps perfectly normal
  • users of such libraries would find it inconvenient to modify the source code of those libraries in order to disable such warnings (even if there were a way to do so in Eastwood at a per-macro or per-expression granularity, which there is not yet)

It seems that having a way to disable such warnings for particular macros, without modifying the source code of the library, is a desirable thing. Issue #21 would be able to handle selectively disabling warnings, perhaps even in individual expressions within a macro definition (perhaps tricky inside syntax-quoted forms), but it does not address the issue of disabling warnings in projects you do not wish to edit.

A fairly straightforward 'granularity' for this would be to specify a collection of pairs containing (set of macros, set of linters to disable), where macros are specified by their names, perhaps fully qualified, e.g. korma.core/select, and linters by their keyword names in the Eastwood documentation.

Places these could be put:

  • already supported, if they are in the Eastwood options map: project.clj file, ~/.lein/profiles.clj file, command line option map
  • new place that might be useful: Some other Clojure-syntax file whose name is specified in one of the places above, in the Eastwood options map. Allowing one such file to include/load one or more others could be useful to share such disabling across multiple developer projects.
  • new place that might be useful: In a normal Clojure source file where the macro is invoked, before it is first invoked. This has the down-side of needing to be in multiple Clojure source files, if the macro is used in more than one of them. Probably best not to even implement it, then.

It might be useful to extend this to functions or var definitions inside any namespace. Not clear if that is useful, but think about it.

@gfredericks
Copy link

If you did extend it to functions, would that be a halfway-decent approach to #21?

And if you can do it in your own code, can you also do it with some sort of metadata? or at least at the function definition somehow or another?

@jafingerhut
Copy link
Collaborator Author

It isn't in a released Eastwood version yet, but I have implemented new ways to configure the disabling of warnings for :suspicious-expression and :constant-test warnings based upon what macro expansions the warned-about expression was created from. I will probably extend this to other linters as I find uses for them, or perhaps simply implement it for every linter if it starts to become the majority of them where it seems useful.

@cichli
Copy link
Contributor

cichli commented Feb 22, 2015

@jafingerhut Would you consider providing any defaults around this? For example:

(clojure.test/is (= (:status val) #{:done}))

will cause a constant-test warning, whereas the following will not:

(clojure.test/is (= #{:done} (:status val)))

I'm not sure if suppressing constant-test inside the expansion of is will cause any useful cases of the warning to be suppressed, but if not I think it would make sense for Eastwood to do this by default.

@vemv
Copy link
Collaborator

vemv commented Apr 27, 2021

This has been possible for a while via

(disable-warning
 {:linter :suspicious-test
  :if-inside-macroexpansion-of ...

so the issue is safe to close now :)

@vemv vemv closed this as completed May 22, 2021
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

No branches or pull requests

4 participants