Skip to content

Conversation

@susnux
Copy link
Contributor

@susnux susnux commented Nov 6, 2025

@susnux susnux requested a review from ShGKme November 6, 2025 00:57
@susnux susnux added bug Something isn't working 3. to review labels Nov 6, 2025
@Antreesy
Copy link
Contributor

Antreesy commented Nov 6, 2025

IDK, are there options to keep/enforce multiline there, e.g. by line length?
image

@susnux
Copy link
Contributor Author

susnux commented Nov 6, 2025

options to keep/enforce multiline there

The old value was not multi line (considered by the fixer) because brackets and first / last item are on the same line.
What is available is "maxItems" for single line.

@Antreesy
Copy link
Contributor

Antreesy commented Nov 6, 2025

This? https://eslint.style/rules/list-style#maxitems

Looks nice, I'd consider great if limited to 3 items, maybe?

@susnux
Copy link
Contributor Author

susnux commented Nov 6, 2025

Looks nice, I'd consider great if limited to 3 items, maybe?

Pushed a commit

Copy link
Contributor

@Antreesy Antreesy left a comment

Choose a reason for hiding this comment

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

image

Now it also affects functions with 4+ arguments... But at least consistent =)
LGTM, I would wait for the second opinion to merge

@susnux
Copy link
Contributor Author

susnux commented Nov 6, 2025

Now it also affects functions with 4+ arguments... But at least consistent =)

Maybe exclude functions

@ShGKme
Copy link
Contributor

ShGKme commented Nov 6, 2025

The old value was not multi line (considered by the fixer) because brackets and first / last item are on the same line.
What is available is "maxItems" for single line.

I'm voting for the previous behavior.

If a developer makes it multiline — keep multiline. If single-line - keep single line.

The decision here doesn't depend on the number of items but on the nature of the array.

@ShGKme
Copy link
Contributor

ShGKme commented Nov 6, 2025

In the referenced PR the tests were adjusted to be more real life like, with som explanations

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux
Copy link
Contributor Author

susnux commented Nov 6, 2025

@ShGKme I added the tests you created to this PR see the two commits to see how it is changed

Comment on lines 10 to 16
const LATIN_VOWELS = [
'a',
'e',
'i',
'o',
'u',
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need diff-safe here? I don't think new vowels are expected to be added 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO its better readable than one-liner.
But at this point I do not care, either we merge this or keep current behavior or someone propose a different consistent solution. As long as we finally can publish this - IMHO we can also change this later...

Copy link
Contributor

Choose a reason for hiding this comment

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

someone propose a different consistent solution

What's wrong with what was already proposed?

  1. Only check for consistency: either single-line array, or multi-line, forbid mixed
  2. Check for bracket [] position if possible
  3. Semantic-related decisions are on the developers. No forced multiline based on syntax without semantics.

The tests copied to this PR were carefully (spending quite much time) developed to follow the proposal: allow developers to decide which format to use to have the readability and simplicity as the priority, keeping the consistency. With the explanation in the comment to make a test not only a snapshot but also a specification.

This is also why vowels in the test where a single line. If we say "multi-line is better for diff-safe", then there is no reason for vowels to be multi-line. Unless we are worried about a case of inventing a new vowel in the English language.

It is not something that can be decided via maxItems. Number 3 has no semantics.
In this test sampleUsers are 3 items, but it is a dynamic array that may have items changed anytime. Same for MUTE_NOTIFICATIONS_USER_STATUSES with a single item.

Let's allow developers to do what is better in a specific case instead of sacrificing anything for the sake of auto-fixed consistency. Is having a diff-safe array every time worth the profit of the diff-safe arrays?

My motivation is to make ESLint a friendly assistant to a developer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My motivation is to make ESLint a friendly assistant to a developer.

Same but at the same time enforce consitent style as written in the docs so that if you open any Nextcloud app you do not see 10 different styles but one code style across all apps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As said I do not care that much at this moment anymore as we need a release and that best case couple of month ago 😉

So if you have a better solution ready I happily review - or we postpone this rule to v9.0.1 - should not be breaking any already migrated app so weaken the rule after release.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same but at the same time enforce consitent style as written in the docs so that if you open any Nextcloud app you do not see 10 different styles but one code style across all apps.

If ESLint breaks my code readability skipping semantics, it doesn't sound as a friendly assistant

Writing a short stable array in a single line doesn't sound like adding 9 more different styles. It is still a consistent array.

We have many other cases where developers can decide if they want the code to be single or multiline, for example, imports.

They can also decide between using .forEach method and for-of statement.

Do you want to specify a single way in every such cases for consistensy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They can also decide between using .forEach method and for-of statement.
Do you want to specify a single way in every such cases for consistensy?

No.
While .forEach and for ... of could also be enforces this is different as this can have different use cases.
Also this gets quite opinionated at some point.
I think that's the reason why we only have some general code structuring and let the rest be decided by the developers.

Writing a short stable array in a single line doesn't sound like adding 9 more different styles. It is still a consistent array.

Its consistency within one array vs consistency of all arrays.
I can also reverse the question: What is the problem of having one style everywhere?
I personally also was more in favor of one-line arrays for simple arrays.
But now I am quite used to the multi line arrays because they allow "seeing" the code vs having to "read" the code.

The decision here doesn't depend on the number of items but on the nature of the array.

I do not agree - if the array is quite long its much harder to quickly read all elements.

If ESLint breaks my code readability skipping semantics, it doesn't sound as a friendly assistant

Well but this is not caused by ESLint but by not following code style in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But as said - I am fine with leaving this for know.
The biggest problem is having it not released as everything can be changed later if we discover issues with it and someone proposes a working fix.

We already have apps released with it for Vue 3 in Nextcloud 32 but depend on a "rc" version - which should be fixed soon. We can always add new rules in a new minor version or remove rules if we see that it breaks things.
But for now it seems like we had not real problems migrating even big apps like photos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants