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

`eslint-disable` or `tslint:disable` comments should be ignored from `printWidth` #6505

Closed
JounQin opened this issue Sep 21, 2019 · 8 comments
Closed

Comments

@JounQin
Copy link
Contributor

@JounQin JounQin commented Sep 21, 2019

Prettier 1.18.2
Playground link

Input:

if (minorVersion >= 6.4) { // eslint-disable-line @typescript-eslint/no-magic-numbers
}

Output:

if (minorVersion >= 6.4) {
  // eslint-disable-line @typescript-eslint/no-magic-numbers
}

Expected behavior:

if (minorVersion >= 6.4) { // eslint-disable-line @typescript-eslint/no-magic-numbers
}
@lydell

This comment has been minimized.

Copy link
Collaborator

@lydell lydell commented Sep 21, 2019

Hi!

This has nothing to do with printWidth. Comments are moved down into the body of block regardless of length:

Prettier 1.18.2
Playground link

--parser babylon

Input:

if (x) { // c
}

Output:

if (x) {
  // c
}

Why? Because comments are one of the trickiest parts of Prettier. Maybe we can support printing them at the same line, maybe not. Either way I think it’s fine that they are moved down in this case. Except that it breaks // some-tool-do-something-to-this-line comments of course.

But that’s a known issue. We recommend using // eslint-disable-next-line instead for this reason. See #1267 and the issues that link to it. A bit sad, but workable.

@JounQin

This comment has been minimized.

Copy link
Contributor Author

@JounQin JounQin commented Sep 21, 2019

@lydell What if I'm using eslint with tslint together and they complain about same line together?

// tslint:disable-next-line no-magic-numbers
if (minorVersion >= 6.4) { // eslint-disable-line @typescript-eslint/no-magic-numbers
}

What means I cann't use next-line comments for eslint and tslint either at the same time.

@lydell

This comment has been minimized.

Copy link
Collaborator

@lydell lydell commented Sep 21, 2019

Why do you use both? TSLint is deprecated in favor of the @typescript-eslint plugin, isn’t it?

@JounQin

This comment has been minimized.

Copy link
Contributor Author

@JounQin JounQin commented Sep 21, 2019

@lydell @typescript-eslint doesn't provide all rules like tslint for now, that's why eslint-plugin-tslint exists.

@lydell

This comment has been minimized.

Copy link
Collaborator

@lydell lydell commented Sep 21, 2019

But surely there’s no need running both TSLint’s no-magic-numbers and @typescript-eslint/no-magic-numbers? I’d turn remove TSLint’s rule from the configuration and enjoy faster linting.

@JounQin

This comment has been minimized.

Copy link
Contributor Author

@JounQin JounQin commented Sep 21, 2019

It's just a simple example, they could be different rules targetting different purposes.

platformBrowserDynamic()
  .bootstrapModule(AppModule)
  // eslint-disable-next-line @typescript-eslint/unbound-method
  .catch(console.error) // tslint:disable-line no-console
@lydell

This comment has been minimized.

Copy link
Collaborator

@lydell lydell commented Sep 22, 2019

ESlint also has a no-console rule.

 // eslint-disable-next-line @typescript-eslint/unbound-method, no-console

But, sure, I totally understand that this is a flaw in Prettier. On the other hand, why worry about a problem you don’t have?

@JounQin

This comment has been minimized.

Copy link
Contributor Author

@JounQin JounQin commented Sep 22, 2019

Fine, then I'm going to create something like tslint-config-eslint which disables all rules which has been handlered by eslint or @typescript-eslint.

But I still think it is a bug instead of a small flaw of Prettier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.