Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

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

Closed
5 tasks done
m-shum opened this issue Apr 26, 2024 · 4 comments
Closed
5 tasks done

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

m-shum opened this issue Apr 26, 2024 · 4 comments

Comments

@m-shum
Copy link

m-shum commented Apr 26, 2024

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

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@ziveen
Copy link

ziveen commented Apr 29, 2024

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
Copy link

ziveen commented Apr 29, 2024

here is the doc

@m-shum
Copy link
Author

m-shum commented May 2, 2024

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
Copy link
Owner

antfu commented May 2, 2024

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.

Repository owner locked and limited conversation to collaborators May 2, 2024
@antfu antfu converted this issue into discussion #469 May 2, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants