-
Notifications
You must be signed in to change notification settings - Fork 120
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
dartfmt moved an // ignore: lint
comment
#838
Comments
// ignore: lint
comment// ignore: lint
comment
cc @munificent |
Interesting. So, in general, the behavior is deliberate. The formatter considers it unidiomatic to have a line comment on the same line as the beginning of a block and puts it on the next line instead. This behavior is useful for things like formatting generated code which may not have any useful newlines. But when the comment is an ignore comment, that might not be the right behavior. If this comes up frequently enough, it might be worth giving special handling for comments that start with |
I think it'd be reasonable to reformat Another idea is to make comments in general match the indentation of the next non-comment line (if there isn't an intervening blank line). |
Dup of #798
In some cases it could make comments harder to read. For instance: if (true) {
things;
} else { // ignore: some_lint_on_else
things;
}
// here the ignore looks related to the _then_ block
if (true) {
things;
// ignore: some_lint_on_else
} else {
things;
} |
Fair, but I think those cases are pretty rare in practice and easily explained with a second human-oriented comment. |
This would happen for any code of the form: try {
doSomething();
} catch (e) { // ignore: avoid_catches_without_on_clauses
log(e);
rethrow;
} which seems like a reasonable and not atypical pattern. |
Good point. It's probably worth special casing |
Running
dartfmt
on:generates:
And now the
// ignore:
comment is no longer referring to the intended line.I don't think that this is quite the same as #546 since:
// ignore:
to "the new lines if dartfmt splits something up".I could move
// ignore:
to be above the targeted line, but I'd prefer not to since it then looks like the comment belongs in thetry
block. (Thatdartfmt
indents the comment in that case doesn't help.)(I am using dartfmt 1.2.8 on linux x64.)
The text was updated successfully, but these errors were encountered: