Denilson
Denilson

Reputation: 43

Flutter/Dart: Ignore lines_longer_than_80_chars only for strings in vscode

with the rule when a format the code it becomes like this:

 final regex = 
     r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{8,}$';

I want to keep like this when I format:

 final regex = r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{8,}$';

Upvotes: 0

Views: 1262

Answers (2)

Jonathan
Jonathan

Reputation: 4928

in fact you can prevent that lint by making the String a block type by using '''.

ie

final regex = r'''^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{8,}$''';

however the formatting will still occur

Upvotes: 1

jamesdlin
jamesdlin

Reputation: 90155

Code is reformatted by the formatter (dart format), not by the linter. The Dart VS Code extension has settings for the Dart formatter.

There is separately the lines_longer_than_80_chars lint for cases where dart format cannot break up a line (such as with long string literals). If you increase the line length for dart format, you likely will want to disable this lint.

There is no way to make dart format or dart analyzer apply these rules conditionally.

Upvotes: 1

Related Questions