Chromium Code Reviews| Index: pkg/analyzer/test/services/data/style_guide_tests.data |
| =================================================================== |
| --- pkg/analyzer/test/services/data/style_guide_tests.data (revision 0) |
| +++ pkg/analyzer/test/services/data/style_guide_tests.data (revision 0) |
| @@ -0,0 +1,225 @@ |
| +>>> DO use ; instead of {} for empty constructor bodies |
| +class Point { |
| + int x, y; |
| + Point(this.x, this.y) {} |
| +} |
| +<<< |
| +class Point { |
| + int x, y; |
| + Point(this.x, this.y); |
|
Brian Wilkerson
2014/01/03 01:06:47
Is there a way to disable code transformations so
pquitslund
2014/01/03 19:02:16
Yep. A command-line a flag.
|
| +} |
| +>>> DO indent block bodies two spaces. |
| +hi() { |
| +if (condition) { print('hi'); } |
| +} |
| +<<< |
| +hi() { |
| + if (condition) { |
| + print('hi'); |
| + } |
| +} |
| +>>> DON'T indent lines that are continued with a function expression. |
| +var callback = new Future.delayed(const Duration(seconds: 1), () { |
| + print('I am a callback'); |
| + }); |
| +<<< |
| +var callback = new Future.delayed(const Duration(seconds: 1), () { |
| + print('I am a callback'); |
| +}); |
| +>>> DO place the opening curly brace ({) on the same line as what it follows. |
| +class Foo { |
| + method() |
| + { |
| + if (true) |
| + { |
| + print('true'); |
| + } else { |
| + print('false'); |
| + } |
| + } |
| +} |
| +<<< |
| +class Foo { |
| + method() { |
| + if (true) { |
| + print('true'); |
| + } else { |
| + print('false'); |
| + } |
| + } |
| +} |
| +>>> DO use curly braces for all flow control structures. |
| +flow() { |
| + if (true) print('sanity'); |
| + else |
| + print('opposite day!'); |
| +} |
| +<<< |
| +flow() { |
| + if (true) { |
| + print('sanity'); |
| + } else { |
| + print('opposite day!'); |
| + } |
| +} |
| +>>> ... short if statements with no else may omit the braces ... |
| +except() { |
| + if (arg == null) return defaultValue; |
| +} |
| +<<< |
| +except() { |
| + if (arg == null) return defaultValue; |
| +} |
| +>>> DO indent switch cases two spaces and case bodies four spaces |
| +switches() { |
|
Brian Wilkerson
2014/01/03 01:06:47
The before and after code are the same, so this te
pquitslund
2014/01/03 19:02:16
Tweaked.
|
| + switch (fruit) { |
| + case 'apple': |
| + print('delish'); |
| + break; |
| + |
| + case 'durian': |
| + print('stinky'); |
| + break; |
| + } |
| +} |
| +<<< |
| +switches() { |
| + switch (fruit) { |
| + case 'apple': |
| + print('delish'); |
| + break; |
| + |
| + case 'durian': |
| + print('stinky'); |
| + break; |
| + } |
| +} |
| +>>> DO use spaces around binary and ternary operators, etc... |
| +spaces() { |
| + a=1+2/(3* - b); |
| + c= ! condition==a>b; |
| + d= condition?b:object.method(a,b,c); |
| + if (obj is !SomeType) print('not SomeType'); |
| +} |
| +<<< |
| +spaces() { |
| + a = 1 + 2 / (3 * -b); |
| + c = !condition == a > b; |
| + d = condition ? b : object.method(a, b, c); |
| + if (obj is! SomeType) print('not SomeType'); |
| +} |
| +>>> DO place spaces around in, and after each ; in a loop. |
| +loop() { |
|
Brian Wilkerson
2014/01/03 01:06:47
The before and after code are the same.
pquitslund
2014/01/03 19:02:16
Done.
|
| + for (var i = 0; i < 100; i++) { |
| + print(i); |
| + } |
| + for (final item in collection) { |
| + print(item); |
| + } |
| +} |
| +<<< |
| +loop() { |
| + for (var i = 0; i < 100; i++) { |
| + print(i); |
| + } |
| + for (final item in collection) { |
| + print(item); |
| + } |
| +} |
| +>>> DO use a space after flow-control keywords. |
| +flow() { |
|
Brian Wilkerson
2014/01/03 01:06:47
You might want to test more cases (such as if and
pquitslund
2014/01/03 19:02:16
Absolutely. There are more in the "unit tests".
|
| + while(foo) { |
| + print(foo); |
| + } |
| + |
| + try{ |
| + flow(); |
| + }catch(e) { |
| + print(e); |
| + } |
| +} |
| +<<< |
| +flow() { |
| + while (foo) { |
| + print(foo); |
| + } |
| + |
| + try { |
| + flow(); |
| + } catch (e) { |
| + print(e); |
| + } |
| +} |
| +>>> DON'T use a space after (, [, and {, or before ), ], and }. |
| +spaces() { |
|
Brian Wilkerson
2014/01/03 01:06:47
The before code should include spaces in the wrong
pquitslund
2014/01/03 19:02:16
Done.
|
| + var numbers = <int> [1, 2,(3+4)]; |
| +} |
| +<<< |
| +spaces() { |
| + var numbers = <int>[1, 2, (3 + 4)]; |
| +} |
| +>>> DO use a space before { in function and method bodies. |
| +getEmptyFn(a){ |
| + return (){}; |
| +} |
| +<<< |
| +getEmptyFn(a) { |
| + return () { |
| + }; |
| +} |
| +>>> DO format constructor initialization lists with each field on its own line. |
| +class MyClass { |
| + var firstField, secondField, thirdField; |
| + MyClass() : firstField = "some value", secondField = "another", |
| + thirdField = "last"; |
| +} |
| +<<< |
| +class MyClass { |
| + var firstField, secondField, thirdField; |
| + MyClass() |
| + : firstField = "some value", |
| + secondField = "another", |
| + thirdField = "last"; |
| +} |
| +>>> DO use a space after : in named parameters and named arguments. |
| +class ListBox { |
| + bool showScrollbars; |
| + |
| + ListBox({this.showScrollbars: false}); |
|
Brian Wilkerson
2014/01/03 01:06:47
You might want to add another named parameter that
pquitslund
2014/01/03 19:02:16
There's one like this in the unit tests.
|
| +} |
| + |
| +main() { |
| + new ListBox(showScrollbars:true); |
| + new ListBox(showScrollbars : true); |
| +} |
| +<<< |
| +class ListBox { |
| + bool showScrollbars; |
| + |
| + ListBox({this.showScrollbars: false}); |
| +} |
| + |
| +main() { |
| + new ListBox(showScrollbars: true); |
| + new ListBox(showScrollbars: true); |
| +} |
| +>>> DO use a spaces around = in optional positional parameters. |
| +class HttpServer { |
| + static Future<HttpServer> listen([int port=80]) { |
| + print('hi!'); |
| + } |
| +} |
| +<<< |
| +class HttpServer { |
| + static Future<HttpServer> listen([int port = 80]) { |
| + print('hi!'); |
| + } |
| +} |
| +>>> DO use four spaces for method cascades |
| +var list = new List() |
| + ..addAll([1, 2, 3]) |
| + ..addAll([4, 5, 6]); |
| +<<< |
| +var list = new List() |
| + ..addAll([1, 2, 3]) |
| + ..addAll([4, 5, 6]); |