antfu / eslint-config

Anthony's ESLint config preset
https://eslint-config.antfu.me/
MIT License
3.81k stars 426 forks source link

Setting stylistic/object-property-newline breaks indentation. #462

Closed m-shum closed 5 months ago

m-shum commented 5 months ago

Describe the bug

Object properties should break onto new lines and should be indented correctly. When setting'style/object-property-newline': ['error', { allowAllPropertiesOnSameLine: false }], indentation breaks and code is re-formatted differently every time you hit save.

Stackblitz enforces their own linting so the reproduction isn't much use but it does contain the config I'm using. I have tried removing all the rules I've set up, but the default config seems to have set object properties to multiline.

What is the correct way to enforce object properties with this config?

Having huge run-on object declarations like this: tween.value = gsap.timeline({ paused: true, onComplete: () => { isComplete.value = true } }).from(split.value.lines, { duration: 1, y: '100%', x: 10, autoAlpha: 0, scale: 0.99, stagger: 0.07, ease: 'power2.inOut' }) is not readable. I would like to be able break down lines like that automatically using something like the object-property-newline rule.

Reproduction

https://stackblitz.com/edit/github-lzpjei?file=.vscode%2Fsettings.json,app.vue,eslint.config.js

System Info

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 78.75 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.12.0 - ~/.nvm/versions/node/v18.12.0/bin/node
    npm: 9.8.1 - ~/.nvm/versions/node/v18.12.0/bin/npm
  Browsers:
    Chrome: 124.0.6367.92
    Safari: 17.4.1

Used Package Manager

npm

Validations

ziveen commented 5 months ago

it seems the rule style/object-property-newline conflict with the default rule consistent-list-newline.the object should format to newline depend on the first indentifier of object.eg:

// this  obj will keep at 1 line
const obj = {age: 100, name: "lee"}

/** this obj1 will format like this :
* const obj1 = {
*     age: 100,
*     name: "lee",
* }
*/
const obj1 = {
age: 100, name: "lee"}

u can remove style/object-property-newline and try again. @m-shum

ziveen commented 5 months ago

here is the doc

m-shum commented 5 months ago

Thanks @ziveen , I was wondering if there's a way to always break object properties onto new lines rather than having to do it manually to enforce a particular convention.

antfu commented 5 months ago

Thank you for submitting the issue!

However, please also note that this is only a shared config where we can only make sure the default and recommended configs are working fine. We don't have the bandwidth to deal with custom configuration or rules conflicts. If you believe it's a bug in the rules, please create an issue to upstream plugins instead.

Thus, I am converting this to a discussion for now.