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

newline-per-chained-call: bad indentation, and bare fn call treated as chain #265

Open
3 of 5 tasks
OJFord opened this issue Jan 14, 2024 · 0 comments
Open
3 of 5 tasks

Comments

@OJFord
Copy link

OJFord commented Jan 14, 2024

Validations

Describe the bug

With "@stylistic/newline-per-chained-call": ["error", {ignoreChainWithDepth: 1}]:

export const post = sqliteTable(
  'post',
  {
    id: integer('id').primaryKey(),
    name: text('name'),
  },
)

is reformatted to:

export const post = sqliteTable(
  'post',
  {
    id: integer('id')
.primaryKey(),
    name: text('name'),
  },
)

Which:

  1. I would not expect anyway, since integer('id').primaryKey() is to me a chain of 1 - it would be fine if it were integer.primaryKey(), I expected that a 'chain' refers to occurrences of the . operator;
  2. is weird indentation, not that there's really a great solution anyway

A workaround is to introduce parens:

export const post = sqliteTable(
  'post',
  {
    id: (
        integer('id')
        .primaryKey()
    ),
    name: text('name'),
  },
)

which is a bit verbose but less odd looking than the zero indentation above.


To address (1), I think this should not be treated as a >1 chain.


Assuming it were integer('id').something.primaryKey() then, to address (2), I would suggest a configurable option for what happens in object values.

/* ["error", {ignoreChainWithDepth: 1, ignoreChainInObjectValue: true}]] */

// GOOD
{
  id: foo().bar().baz(),
}

(
  foo()
  .bar()
  .baz()
)

// BAD
(
  foo().bar().baz()
)

then if it really does get too long and we want to force it, we can always:

// GOOD
{
  id: (
    foo()
    .bar()
    .baz()
  ),
}

or this could even just be new, unconfigurable, behaviour - since I'm really not sure what a sensible indentation would look like, all possibilities seem a bit weird:

{
  a: foo()
.bar()
.baz(),

  b: foo()
     .bar()
     .baz(),

  c: foo()
  .bar()
  .baz(),
}

or whatever else.

Reproduction

See description, I can't work out how to use Stackblitz for it

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests
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