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

Formatting is unstable (not idempotent) #686

Open
adrian-gierakowski opened this issue Nov 25, 2024 · 2 comments
Open

Formatting is unstable (not idempotent) #686

adrian-gierakowski opened this issue Nov 25, 2024 · 2 comments

Comments

@adrian-gierakowski
Copy link

Describe the bug

Running dprint fmt on the on some code twice, leads to different output each time.

Input Code

const createTestData = () =>
  function*() {
    const startingFrom = yield* Effect.map(DateTime.now, now =>
      DateTime.startOf(now, 'day'))

    return HashSet.make(DateTime.toEpochMillis(startingFrom))
  }

Expected Output

const createTestData = () =>
  function*() {
    const startingFrom = yield* Effect.map(DateTime.now, now =>
      DateTime.startOf(now, 'day'))

    return HashSet.make(DateTime.toEpochMillis(startingFrom))
  }

Actual Output

first time:

const createTestData = () =>
  function*() {
    const startingFrom = yield* Effect.map(DateTime.now, now =>
      DateTime.startOf(now, 'day'))

    return HashSet
      .make(DateTime.toEpochMillis(startingFrom))
  }

second time:

const createTestData = () =>
  function*() {
    const startingFrom = yield* Effect.map(DateTime.now, now =>
      DateTime.startOf(now, 'day'))

    return HashSet
      .make(DateTime
        .toEpochMillis(startingFrom))
  }
@adrian-gierakowski
Copy link
Author

adrian-gierakowski commented Nov 25, 2024

note that following remains unchanged (with the same config)

const createTestData = () =>
  function*() {
    return HashSet.make(DateTime.toEpochMillis(startingFrom))
  }

and the following:

const createTestData = function*() {
  const startingFrom = yield* Effect.map(DateTime.now, now =>
    DateTime.startOf(now, 'day'))

  return HashSet.make(DateTime.toEpochMillis(startingFrom))
}

gets formatted to:

const createTestData = function*() {
  const startingFrom = yield* Effect.map(
    DateTime.now,
    now => DateTime.startOf(now, 'day'),
  )

  return HashSet.make(DateTime.toEpochMillis(startingFrom))
}

@adrian-gierakowski
Copy link
Author

adrian-gierakowski commented Nov 25, 2024

Tested with:

  • dprint 0.47.5
  • dprin-plugin-typescript 0.93.2
  • following config
{
  "typescript": {
    "arrowFunction.useParentheses": "preferNone",
    "binaryExpression.linePerExpression": true,
    "enumDeclaration.memberSpacing": "newLine",
    "jsx.quoteStyle": "preferSingle",
    "lineWidth": 80,
    "memberExpression.linePerExpression": true,
    "nextControlFlowPosition": "sameLine",
    "quoteProps": "asNeeded",
    "quoteStyle": "preferSingle",
    "semiColons": "asi"
  }
}

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