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

Side by Side Diff: lib/src/source_visitor.dart

Issue 1173663004: Insert a blank line before and after classes. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | test/regression/168.unit » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart_style.src.source_visitor; 5 library dart_style.src.source_visitor;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/src/generated/scanner.dart'; 8 import 'package:analyzer/src/generated/scanner.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 10
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 // Put a blank line between the library tag and the other directives. 428 // Put a blank line between the library tag and the other directives.
429 var directives = node.directives; 429 var directives = node.directives;
430 if (directives.isNotEmpty && directives.first is LibraryDirective) { 430 if (directives.isNotEmpty && directives.first is LibraryDirective) {
431 visit(directives.first); 431 visit(directives.first);
432 twoNewlines(); 432 twoNewlines();
433 433
434 directives = directives.skip(1); 434 directives = directives.skip(1);
435 } 435 }
436 436
437 visitNodes(directives, between: oneOrTwoNewlines); 437 visitNodes(directives, between: oneOrTwoNewlines);
438 visitNodes(node.declarations, 438
439 before: twoNewlines, between: oneOrTwoNewlines); 439 if (node.declarations.isNotEmpty) {
440 twoNewlines();
441
442 for (var i = 0; i < node.declarations.length; i++) {
443 visit(node.declarations[i]);
444
445 if (i < node.declarations.length - 1) {
446 // Require blank lines around classes.
447 if (node.declarations[i] is ClassDeclaration ||
448 node.declarations[i + 1] is ClassDeclaration) {
449 twoNewlines();
450 } else {
451 // Functions and variables can be more tightly packed.
452 oneOrTwoNewlines();
453 }
454 }
455 }
456 }
440 } 457 }
441 458
442 visitConditionalExpression(ConditionalExpression node) { 459 visitConditionalExpression(ConditionalExpression node) {
443 builder.nestExpression(); 460 builder.nestExpression();
444 visit(node.condition); 461 visit(node.condition);
445 462
446 builder.startSpan(); 463 builder.startSpan();
447 464
448 // If we split after one clause in a conditional, always split after both. 465 // If we split after one clause in a conditional, always split after both.
449 builder.startRule(); 466 builder.startRule();
(...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after
2048 /// Gets the 1-based line number that the beginning of [token] lies on. 2065 /// Gets the 1-based line number that the beginning of [token] lies on.
2049 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber; 2066 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber;
2050 2067
2051 /// Gets the 1-based line number that the end of [token] lies on. 2068 /// Gets the 1-based line number that the end of [token] lies on.
2052 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber; 2069 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber;
2053 2070
2054 /// Gets the 1-based column number that the beginning of [token] lies on. 2071 /// Gets the 1-based column number that the beginning of [token] lies on.
2055 int _startColumn(Token token) => 2072 int _startColumn(Token token) =>
2056 _lineInfo.getLocation(token.offset).columnNumber; 2073 _lineInfo.getLocation(token.offset).columnNumber;
2057 } 2074 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | test/regression/168.unit » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698