| 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.super_goes_last; | 5 library linter.src.rules.super_goes_last; |
| 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 'Place the super() call last in a constructor initialization list.'; | 12 'Place the super() call last in a constructor initialization list.'; |
| 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** place the `super()` call last in a constructor initialization list. | 17 **DO** place the `super()` call last in a constructor initialization list. |
| 18 | 18 |
| 19 Field initializers are evaluated in the order that they appear in the | 19 Field initializers are evaluated in the order that they appear in the |
| 20 constructor initialization list. If you place a `super()` call in the | 20 constructor initialization list. If you place a `super()` call in the |
| 21 middle of an initializer list, the superclass's initializers will be evaluated | 21 middle of an initializer list, the superclass's initializers will be evaluated |
| 22 right then before evaluating the rest of the subclass's initializers. | 22 right then before evaluating the rest of the subclass's initializers. |
| 23 | 23 |
| 24 What it doesn't mean is that the superclass's constructor body will be executed | 24 What it doesn't mean is that the superclass's constructor body will be executed |
| 25 then. That always happens after all initializers are run regardless of where | 25 then. That always happens after all initializers are run regardless of where |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 var last = node.initializers.length - 1; | 68 var last = node.initializers.length - 1; |
| 69 | 69 |
| 70 for (int i = 0; i <= last; ++i) { | 70 for (int i = 0; i <= last; ++i) { |
| 71 var init = node.initializers[i]; | 71 var init = node.initializers[i]; |
| 72 if (init is SuperConstructorInvocation && i != last) { | 72 if (init is SuperConstructorInvocation && i != last) { |
| 73 rule.reportLint(init); | 73 rule.reportLint(init); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 } | 77 } |
| OLD | NEW |