I am working on a Flutter project where the Formatting is set to the default Dart recommends VSCode formatter setting. Is there any way to exclude multi-lines from formatting when VS is set to format modified code/file on save?
I refer to this answer to exclude each line. The code below worked:
msg.pose.covariance = [
0.25, 0.0, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.25, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.0, 0.0, 0.0, 0.0, 2.25 // noqa
];
Now I want to exclude multi-lines with similar this answer. The expected code like Python (black formatter):
// dart: fmt_off
msg.pose.covariance = [
0.25, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.25, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 2.25
];
// dart: fmt_on
As explained in the Dart formatter's FAQ, you just need to have a single comment within the collection literal to prevent the formatter from reformatting it:
So, if you have a collection that you have carefully split into lines, add at least one line comment somewhere inside it to get it to preserve all of the newlines in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With