prettier / prettier

Prettier is an opinionated code formatter.
https://prettier.io
MIT License
49.42k stars 4.36k forks source link

Comments on type assertions in heads of call and member expressions should stay inside the parens #10865

Open JounQin opened 3 years ago

JounQin commented 3 years ago

Prettier 2.3.0 Playground link

Input:

const startConsole = () =>
  (
    // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
    require('../src/start-console') as typeof import('../src/start-console')
  ).startConsole()

Output:

const startConsole = () =>
  // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
  (
    require("../src/start-console") as typeof import("../src/start-console")
  ).startConsole();

Expected behavior:

Do not change comment line.

JounQin commented 3 years ago

Workaround temporarily:

const startConsole = () =>
  (require('../src/start-console') as typeof import('../src/start-console')) // eslint-disable-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
    .startConsole()
thorn0 commented 3 years ago

closely related: #10851

glen-84 commented 3 years ago

Is this the same issue? The = moves after the DoubleEliminationGroupTournament comment.

thorn0 commented 3 years ago

This issue is related to type assertions (as) and specifically to this PR: https://github.com/prettier/prettier/pull/10341

thorn0 commented 3 years ago

@glen-84 Yours might be one of these, but I'm not sure which one. Feel free to open a new issue. Note that there is the 'show second format' checkbox on the playground, so you don't need to do the 'first pass/second pass' thing.

JounQin commented 3 years ago

Another incorrect comment format:

// original
module.exports = declare(
  (
    api,
    {
      modules = false,
    },
  // eslint-disable-next-line sonarjs/cognitive-complexity
  ) => {

  },
)

// formatted
module.exports = declare((api, { modules = false }) =>
  // eslint-disable-next-line sonarjs/cognitive-complexity
  {}
);

The only workaround is using top level eslint disable statement: /* eslint-disable sonarjs/cognitive-complexity */.