Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Unified Diff: pkg/analyzer/test/services/data/style_guide_tests.data

Issue 119323005: Style guide acceptance tests. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
+>>> 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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});
+}
+
+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]);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698