Enumerate all variants in list #71
Replies: 9 comments 1 reply
-
What if you have |
Beta Was this translation helpful? Give feedback.
-
Something like this could work I suppose bubbleGumFlavorsInternal = [ ... ] -- This is the one the rule checks
bubbleGumFlavors = bubbleGumFlavorsInternal |> List.filter ((/=) LegacyBubblegum) |
Beta Was this translation helpful? Give feedback.
-
Ah, I see. I was thinking that |
Beta Was this translation helpful? Give feedback.
-
Yes! We actually have this rule set up at my workplace. I wrote it when v1 was the latest version, so it is limited to the knowledge of the current module. This should be turned into a project rule before it is published somewhere. Also, I didn't account for example 2, and at the moment it would just error as if the variant with an argument was missing from the list (which is not ideal)
That is actually what I went with, but I agree that it is brittle and that bugged me. I hadn't thought of having the list in the configuration, that sounds like a more stable solution. I wonder whether there is worth in having both the I imagine that the configuration would look somewhat like this? RuleName.rule [ "Some.Module.Name.iceCreamFlavors" ] If so, what you should probably do then is to report when that function could not be found in the project (or if does not look like a list of enum), like I described in here (under "Making sure the target function exists"). |
Beta Was this translation helpful? Give feedback.
-
Yeah, something like Also I had a look at how project/configuration errors are reported in the link you provided. Rule.errorForElmJson
elmJsonKey
(\_ ->
{ message = "Could not find Helpers.Regex.fromLiteral."
, details =
[ "I want to provide guarantees on the use of this function, but I can't find it. It is likely that it was renamed, which prevents me from giving you these guarantees."
, "You should rename it back or update this rule to the new name. If you do not use the function anymore, remove the rule."
]
-- Dummy location. Not recommended though :(
, range =
{ start = { row = 1, column = 1 }
, end = { row = 1, column = 2 }
}
} In this code there's this comment, |
Beta Was this translation helpful? Give feedback.
-
I've got a couple of rules that take module names as config and have discussed |
Beta Was this translation helpful? Give feedback.
-
I feel like that can make it harder for a user to understand, especially when they don't know that
The recommended way would be to throw some kind of global/configuration error, which That said, there are other concerns around creating global/configuration errors. I'll try and create an issue about that (soon-ish) in the |
Beta Was this translation helpful? Give feedback.
-
Update:
@MartinSStewart I think you had more comments about this rule on Slack but I forgot what they were :s |
Beta Was this translation helpful? Give feedback.
-
@Arkham published this under https://package.elm-lang.org/packages/Arkham/elm-review-no-missing-type-constructor/latest/ |
Beta Was this translation helpful? Give feedback.
-
What the rule should do:
This rule checks that list literals the user has chosen, contain every possible variant of a chosen type.
What problems does it solve:
Those times where you add a new variant to a type and forget to update a list that should contain every variant
Example of things the rule would report:
Example 1:
gets fixed to this (assuming the user has configured the rule to check
iceCreamFlavors
)Example 2:
This would cause a configuration error because Custom can't be enumerated in a list (assuming the rule was configured to check
iceCreamFlavors
).Example 3:
This would cause a configuration error because
iceCreamFlavor
is missing (again, assuming that the rule is configured to check for it).When (not) to enable this rule:
You don't have lists that need to enumerate a type
I am looking for:
all
and have a type annotation ofList <type name>
. I personally don't think this is the way to go since things might silently break if the function gets renamed.Beta Was this translation helpful? Give feedback.
All reactions