-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Linter should suggest having a space on either side of any binary operators, and before any unary operators #57336
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
Comments
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, |
The code |
That was in fact the exact case that led to my filing this bug. Regarding |
* Grinder support (`rule:rule_name` and `docs:location`) for rule stub and doc generation (respectively). * Fix to allow leading underscores in `non_constant_identifier_names`. * New `valid_regexps` lint (#277). * New `whitespace_around_ops` lint (#249). * Fix to `overridden_fields` to flag overridden static fields (#274). * New `list_remove_unrelated_type` to detect passing a non-`T` value to `List.remove()`` (#271). * New `empty_catches` lint to catch empty catch blocks (#43). * Fixed `close_sinks` false positive (#268). * Added `linter` support for `--strong` to allow for running linter in strong mode. BUG= [email protected] Review URL: https://codereview.chromium.org//2182183004 .
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., 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 dart-lang/dart_style#530, dart-lang/dart_style#531, dart-lang/dart_style#528, dart-lang/dart_style#525, or my personal favourite, dart-lang/dart_style#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:
The text was updated successfully, but these errors were encountered: