| 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.one_member_abstracts; | 5 library linter.src.rules.one_member_abstracts; |
| 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:linter/src/linter.dart'; | 9 import 'package:linter/src/linter.dart'; |
| 10 | 10 |
| 11 const desc = | 11 const desc = |
| 12 'Avoid defining a one-member abstract class when a simple function will do.'
; | 12 'Avoid defining a one-member abstract class when a simple function will do.'
; |
| 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 **AVOID** defining a one-member abstract class when a simple function will do. | 17 **AVOID** defining a one-member abstract class when a simple function will do. |
| 18 | 18 |
| 19 Unlike Java, Dart has first-class functions, closures, and a nice light syntax | 19 Unlike Java, Dart has first-class functions, closures, and a nice light syntax |
| 20 for using them. If all you need is something like a callback, just use a | 20 for using them. If all you need is something like a callback, just use a |
| 21 function. If you're defining an class and it only has a single abstract member | 21 function. If you're defining an class and it only has a single abstract member |
| 22 with a meaningless name like `call` or `invoke`, there is a good chance | 22 with a meaningless name like `call` or `invoke`, there is a good chance |
| 23 you just want a function. | 23 you just want a function. |
| 24 | 24 |
| 25 **GOOD:** | 25 **GOOD:** |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 var member = node.members[0]; | 59 var member = node.members[0]; |
| 60 if (member is MethodDeclaration && | 60 if (member is MethodDeclaration && |
| 61 member.isAbstract && | 61 member.isAbstract && |
| 62 !member.isGetter && | 62 !member.isGetter && |
| 63 !member.isSetter) { | 63 !member.isSetter) { |
| 64 rule.reportLint(node.name); | 64 rule.reportLint(node.name); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 } | 68 } |
| OLD | NEW |