-
Notifications
You must be signed in to change notification settings - Fork 127
Description
Since no formatter is perfect (e.g., some const/final nested collection constructs try to represent actual readable structure meaning in the code via their indentation that the formatter cannot be expected to understand and preserve), formatter off/on comment pairs should be recognized that turn off reformatting for the specified lines in between these delimiters.
// dartfmt off
Foo barBaz() => new Quux({
'alpha.beta.gamma': [new Zuul({
'yarrr': Abracadabra.OPEN_SESAME,
}, {
'toil': {
'trouble': {
'fireBurn': {
'cauldronBubble': EYE_OF_NEWT,
}
}
}
})]
});
// dartfmt on
Yes, use of this construct should be discouraged and limited. Perhaps emit a warning as dartfmt is run indicating that it encountered such blocks of unformatted code?
Also, it is only reasonable to require complete constructs be present between the delimiters, and not expect the formatter to do anything reasonable when the delimiters arbitrarily break up the middle of some block level construct. For example, the formatter could produce an error, or just not be expected to do anything sane, for misuses like:
if (someTest) {
someThenCode();
// dartfmt off
unformattedThenCode();
} else {
unformattedElseCode();
// dartfmt on
moreElseCode();
}
At worst, such unformatted segments that span block boundaries should produced undefined results for the rest of the source file. At best, an error should be printed and formatting should stop.