| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 linter.src.rules.empty_constructor_bodies; | 5 library linter.src.rules.empty_constructor_bodies; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/src/dart/ast/token.dart'; | 9 import 'package:analyzer/src/dart/ast/token.dart'; |
| 10 import 'package:linter/src/linter.dart'; | 10 import 'package:linter/src/linter.dart'; |
| 11 | 11 |
| 12 const desc = 'Use `;` instead of `{}` for empty constructor bodies.'; | 12 const desc = 'Use `;` instead of `{}` for empty constructor bodies.'; |
| 13 | 13 |
| 14 const details = ''' | 14 const details = ''' |
| 15 From the [style guide] (https://www.dartlang.org/articles/style-guide/): | 15 From the [style guide](https://www.dartlang.org/articles/style-guide/): |
| 16 | 16 |
| 17 **DO** use ; instead of {} for empty constructor bodies. | 17 **DO** use ; instead of {} for empty constructor bodies. |
| 18 | 18 |
| 19 In Dart, a constructor with an empty body can be terminated with just a | 19 In Dart, a constructor with an empty body can be terminated with just a |
| 20 semicolon. This is required for const constructors. For consistency and | 20 semicolon. This is required for const constructors. For consistency and |
| 21 brevity, other constructors should also do this. | 21 brevity, other constructors should also do this. |
| 22 | 22 |
| 23 **GOOD:** | 23 **GOOD:** |
| 24 | 24 |
| 25 ``` | 25 ``` |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 if (node.body is BlockFunctionBody) { | 60 if (node.body is BlockFunctionBody) { |
| 61 Block block = (node.body as BlockFunctionBody).block; | 61 Block block = (node.body as BlockFunctionBody).block; |
| 62 if (block.statements.length == 0) { | 62 if (block.statements.length == 0) { |
| 63 if (block.endToken is! TokenWithComment) { | 63 if (block.endToken is! TokenWithComment) { |
| 64 rule.reportLint(block); | 64 rule.reportLint(block); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 } | 69 } |
| OLD | NEW |