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

Rules for list literals #1588

Open
tfausak opened this issue May 3, 2024 · 0 comments
Open

Rules for list literals #1588

tfausak opened this issue May 3, 2024 · 0 comments

Comments

@tfausak
Copy link
Contributor

tfausak commented May 3, 2024

It would be nice to be able to write rules for list literals with any number of elements. For example, consider the following rule:

- warn:
    lhs: '[x] ++ [y]'
    rhs: '[x, y]'

As written, they only work with singleton lists. I could write additional rules for lists of various sizes. That quickly gets out of hand and isn't exhaustive anyway. What I would like to be able to do is write a rule like this:

- warn:
    lhs: '[xs] ++ [ys]'
    rhs: '[xs, ys]'

And have that match for all the following cases:

[] ++ [] -- []
[x] ++ [] -- [x]
[] ++ [y] -- [y]
[x] ++ [y] -- [x, y]
[x, z] ++ [y] -- [x, z, y]
[x] ++ [y, w] -- [x, y, w]
[x, z] ++ [y, w] -- [x, z, y, w]

And so on. Perhaps the cases with empty lists would need to be handled separately.

I tried doing something like { lhs: [x] ++ y, side: isList y } which didn't work. I also tried { side: 'is[] y' }, but that errored out. Even if that condition worked, there would be no way for me to "unpack" the list literal anyway; it would end up suggesting [x, [y]].

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

1 participant