-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Rule idea: forbid elements by name #19
Comments
The extremely nice thing about In general, some form of annotation to suppress instead of excluding an entire file would be much more maintainable and granular. Obviously, it would also be more complicated to implement in [That was probably not exactly the sort of feedback you were looking for?] |
This reminds me a lot of NeoVier/elm-review-no-function-outside-of-modules, but with the added bonus details about why it's forbidden. I did a very minor experiment with a similar rule internally, though much more limited and the extra details was something I added as well.
|
As far as names go, maybe |
I think I'd avoid references to "restricting syntax" like the eslint rule since this isn't restricting syntax itself but instead restricting named values (potentially types). Maybe |
Thanks for the input so far 🙏
In practice we like to rename functions/modules, because that makes it clear something shouldn't be used, even without the use
It's actually do-able in practice. elm-review-performance does that for its (only) rule. But instead of having it be part of the framework, its up to the rule (and I'm so far happy it's not spreading too much to other rules). So this would definitely be an option for this rule. I'm not sure where it's better to write the exceptions though. When in doubt, I'd still do it in the configuration if both are possible.
As long as we don't stray too much off the topic, I'm fine with it. Also, your second point did bring an interesting possibility for the rule that could be exception.
Ah yes, I forgot to check whether this already existed. I know it was created at some companies but forgot to check the registry. (something something discovery or rules could be improved) The package doesn't work anymore, but it was republished under @henriquecbuss's name (hello relevant person 👋) after a username change. I'd also be fine with using that rule, maybe pushing for some improvements like message/details customization And maybe a rename. I'm not sure it's the best one, especially as you can configure the rule to not allow a reference anywhere (which is great but I would not have expected that from the name). An exception through this method (and especially the module name which is nicer than the path) sounds like a good idea though. @henriquecbuss how has been your experience with using the rule so far?
@wolfadex I'd be happy to help you out with that. Maybe let's discuss that in a separate issue or on Slack. Maybe there are a few "tricks" that is not widely known (like deleting a line in the suppressed file, that's okay) to make working with this easer. But yeah, separate topic.
As I said, this confused me. I think it's better to call it like what I suggested or like
It's definitely not necessary, but it might be the little push people need to get started with custom rules. As long as it doesn't take a too prominent part of the documenation, this should be fine. This could also just be a link with explanations on how to extend this code. |
My instinct (FWIW) would be to have a rule that takes a single record and relies on repeating the rule multiple times to get the configuration you want. Then the name of the rule can be dynamic (spitball I don't think there is much overlap with NoDeprecated from a user point of view (I imagine the implementation would be very similar). But the use case for NoDeprecated is to do rolling upgrades and the automatic detection of +1 on putting the implementation (perhaps slightly simplified even) into the docs if it's simple enough. It's a really basic rule (it's definitely the first rule we've built at work). |
I really like the idea behind this kind of rule. I also really agree that my rule could be improved. I've never really loved the name - it's too long, hard to remember, and, as you said, doesn't really convey everything that the rule can do. But it's hard to name it! I think there are some ways we could improve the rule configuration:
I like the idea of providing custom error messages. My rule also shows what modules are allowed in the error messages - I think this is good for discoverability. While developing the rule I went back and forth between relying on having multiple Just to have some data points, our most common use cases for this rule are:
|
What the rule should do:
Report usages of specific values/functions/types/modules by name.
What problems does it solve:
Making it much easier to forbid the usage of certain elements, lowering the entry to use
elm-review
.Example of things the rule would report:
Given configuration like
then this rule would report references to
Html.img
with the message and details defined above.When (not) to enable this rule:
When you don't have specific things you want to forbid or move away from.
I am looking for:
I have plenty of questions around this rule, and could use a lot of feedback!
NoDeprecated
The
NoDeprecated
rule in this same package has quite a bit of overlap with this proposal. For instance, you can forbid a function defined in your codebase by either tagging it as deprecated, or by using this rule by explicitly targeting the function by name.Which one to use becomes a bit of an unclear decision. We can probably merge the two ideas, but then it shouldn't be called
NoDeprecated
. There is definitely some overlap, but it's also not a perfect overlap.A common use-case for this rule is to forbid something in favor of a custom solution. For instance, you could define a new
Button
module and then forbid theHtml.button
function. But you would still want to support the usage ofHtml.button
in this one module. So each restriction likely needs to be configured with exceptions. Except that you can't use the existingReview.Rule.ignoreErrorsFor*
functions as that would make the exceptions apply to unrelated forbidden elements.Unless you use the rule multiple times, which is possible (but potentially confusing for people who come from ESLint where that's not possible because redefining a rule overrides it).
One thing that I've noticed with
NoDeprecated
is that when you're usingelm-review
's suppression system (which the rule is pretty much meant to), you can get a large amount of suppressions (we have over a 1000 at work), and it can be a bit hard to figure out which deprecated functions are responsible for most suppressed usages. I have a proof of concept to use--extract
to help give that insight, which could help a bit.I'm thinking that if we have one rule with plenty of these restrictions and we suppress that, then once again it would be hard to tell which functions are still used a lot and which ones don't have any issues.
There probably needs quite a few configuration options to forbid functions vs types (and especially record type constructors) vs modules vs dependencies vs other things. The proposed API above only works for functions and/or types, but depending on the scope, we might want more.
These could also be split into multiple new rules.
Maybe I'm overthinking or over-engineering this rule, and it would be nice to have a simpler rule (or way of writing this rule), for instance that would only forbid a single element. But that then becomes annoying if you have plenty of related functions you want to forbid.
I also need a good rule name.
I'm thinking
NoForbiddenReferences
or something. I do find the double negation a bit confusing though, so maybe onlyForbiddenReferences
.ESLint has multiple "no-restricted-*" rules, like "no-restrict-syntax" and "no-restricted-globals" which are close. But I have found the name very confusing for years.
That said, if we decide to limit this rule to forbidding a single element, then the rule name should likely be configurable by the user of the rule, as that is a somewhat important part of an
elm-review
error. But the module containing this rule would still need to be named 😄Thoughts and ideas welcome 🙏
The text was updated successfully, but these errors were encountered: