Skip to content

Comments

fix(codeStyle): allow devs write small objects in one line#996

Merged
susnux merged 1 commit intomainfrom
fix/@stylistic-object-property-newline--off
Apr 24, 2025
Merged

fix(codeStyle): allow devs write small objects in one line#996
susnux merged 1 commit intomainfrom
fix/@stylistic-object-property-newline--off

Conversation

@ShGKme
Copy link
Contributor

@ShGKme ShGKme commented Apr 24, 2025

While it makes sense for large objects, requiring even small objects like { width, height } be defined in 3+ lines.

I'd prefer to let developers decide when it is better.

function getPos(): { x: number, y: number } {
  //
}

// vs

function getPos(): { 
  x: number,
  y: number,
} {
  //
}
const { width, height } = getSize()

// vs

const { 
  width,
  height
} = getSize()
emit('app:config:change', { key, value })

// vs

emit('app:config:change', {
  key,
  value,
})

@ShGKme ShGKme force-pushed the fix/@stylistic-object-property-newline--off branch from 0830288 to 61a923f Compare April 24, 2025 17:19
@susnux
Copy link
Contributor

susnux commented Apr 24, 2025

The first example should not be affected as that are types not an object.

susnux
susnux previously requested changes Apr 24, 2025
Copy link
Contributor

@susnux susnux left a comment

Choose a reason for hiding this comment

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

I'd prefer to let developers decide when it is better.

The idea of code styles is to let no room for opinions 😉

But same as #997 this requies adjustments to our code style first.
We strictly recommend 1 element per line arrays and object.
(except from as parameters which was already disabled).

Reference:

@susnux
Copy link
Contributor

susnux commented Apr 24, 2025

If you consider I misinterpret it ("must be" vs "should be") please dismiss the review.
Then I will just override this in my personal projects 😅

@skjnldsv
Copy link
Contributor

skjnldsv commented Apr 24, 2025

Now I'm confused, is this to enforce this?

const { width, height } = getSize()

or this ?

const { 
  width,
  height
} = getSize()

AFAIK, the first one is the traditional Nextcloud code style, right?

@susnux
Copy link
Contributor

susnux commented Apr 24, 2025

traditional Nextcloud code style

define this please ^^

In PHP currently the style is going to the second one. In fronend I see both.
The documentation recommends the second style.
I personally also prefer one element per line due to readability.

But to be honest if this needs already this discussion here, then we have not agreed on one style and thus need to first agree upon one and until then allow both.

@susnux susnux dismissed their stale review April 24, 2025 20:56

To much discussion, maybe I am wrong here.

@susnux susnux merged commit 9a4ce26 into main Apr 24, 2025
10 checks passed
@susnux susnux deleted the fix/@stylistic-object-property-newline--off branch April 24, 2025 21:03
@skjnldsv
Copy link
Contributor

traditional Nextcloud code style

define this please ^^

No hardcoded rules, I guess this is just old habit from most of the old devs.
It seems like I've seen more one-liners than split lines 🤷
Cannot confirm this is true or not, just a feeling 🙈

@ShGKme
Copy link
Contributor Author

ShGKme commented Apr 24, 2025

The first example should not be affected as that are types not an object.

I got it auto-fixed after updating @nextcloud/eslint-config 👀

@ShGKme
Copy link
Contributor Author

ShGKme commented Apr 24, 2025

But same as #997 this requies adjustments to our code style first.

IMO, there should be no such details in the text documentation.

There is a linter/formatter for this. It defines all the rules, and they are actually rules — they are checked automatically.

@ShGKme
Copy link
Contributor Author

ShGKme commented Apr 24, 2025

I'd prefer to let developers decide when it is better.

The idea of code styles is to let no room for opinions 😉

When it is about places where both options are equal (e.g. using ;) or one in better in most of the cases (e.g. trailing commas).

But with this rule there are many cases where the opposite works well or better.

IMO, readability is more important than consistency.

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

Successfully merging this pull request may close these issues.

Proposal: disable or configure @stylistic/object-property-newline

3 participants