Open Hixie opened 8 years ago
Shouldn't this be handled by dartfmt?
Shouldn't this be handled by dartfmt?
In general, yes. However, some folks don't use it. (Specifically, flutter.)
FWIW this bit
x =+ 1; // sets x to one
produces a warning ("expected an identifier"). Maybe it didn't before?
@Hixie : is the intent here to make it more obvious when someone intends a binary op but is getting a unary one? Typing, for example, 5 /~ 10
when they meant 5 ~/ 10
?
The code x =+ 1;
produces an error because +
is not a valid prefix operator.
is the intent here to make it more obvious when someone intends a binary op but is getting a unary one? Typing, for example,
5 /~ 10
when they meant5 ~/ 10
?
That was in fact the exact case that led to my filing this bug.
Regarding =+
, change all my examples from using +
to using -
.
Update: the lint as described in 1fdc9f9 caused enough confusion (namely around the overlapping roles of the formatter and analyzer) that we've decided to back it out pending more consideration. Along those lines, @bwilkerson had some interesting thoughts around focusing on the particular mistakes (e.g., ~/
vs. /~
) rather than more generally linting something ensured by the formatter.
Sidenote: this further emphasizes the value in finding a happy place where the formatter plays nice with (in this case Flutter) idiomatic Dart. Luckily, folks are working on just that. 👍
Just my 2c: I think we'd be much more productive to let dartfmt make rules about whitespace, and linter make rules about anything but whitespace. It would be a real waste to get into the whitespace game int the linter...
some of us can't use the formatter because it is too opinionated, but still want to avoid bugs like this one.
A simplified formatter that doesn't change line-breaks, similar to how it works in IntelliJ with TypeScript would probably provide more value than linter rules.
If we had a formatter that didn't mess up expressions like:
if (offset.x == velocity.x * xFactor + x0 &&
offset.y == velocity.y + xy)
return true;
...then sign me up. Until then, a linter can solve the problem described in the OP in a way a formatter can't.
(see https://github.com/dart-lang/dart_style/issues/530, https://github.com/dart-lang/dart_style/issues/531, https://github.com/dart-lang/dart_style/issues/528, https://github.com/dart-lang/dart_style/issues/525, or my personal favourite, https://github.com/dart-lang/dart_style/issues/452)
@Hixie I guess in this case I'm in favor of linter rules as well :D
This code shows why you might care:
With the suggested lint, the following code would be ok: