Skip to content

Commit

Permalink
Add use_super_parameters and fix lints in examples (#4044)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough committed May 17, 2022
1 parent b96d953 commit cd66498
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 35 deletions.
1 change: 1 addition & 0 deletions examples/analysis_options.yaml
Expand Up @@ -24,3 +24,4 @@ linter:
- throw_in_finally
- type_annotate_public_apis
- unawaited_futures
- use_super_parameters
19 changes: 1 addition & 18 deletions examples/misc/lib/effective_dart/usage_good.dart
@@ -1,6 +1,7 @@
// ignore_for_file: type_annotate_public_apis, unused_element, unused_local_variable
// ignore_for_file: prefer_function_declarations_over_variables, strict_raw_type,
// ignore_for_file: prefer_initializing_formals, prefer_typing_uninitialized_variables
// ignore_for_file: use_super_parameters
import 'dart:async';
import 'dart:io';
import 'dart:math';
Expand Down Expand Up @@ -557,21 +558,3 @@ Widget build(BuildContext context) {
);
}
// #enddocregion no-new

//----------------------------------------------------------------------------

class Style {}

class ViewBase {
ViewBase(_);
}

class View extends ViewBase {
final List _children;
// #docregion super-first
View(Style style, List children)
: _children = children,
super(style);
// #enddocregion super-first
List get children => _children;
}
4 changes: 2 additions & 2 deletions examples/misc/lib/language_tour/classes/employee.dart
Expand Up @@ -18,8 +18,8 @@ class Employee extends Person {
// #enddocregion method-then-constructor
// #docregion super
// Person does not have a default constructor;
// you must call super.fromJson(data).
Employee.fromJson(Map data) : super.fromJson(data) {
// you must call super.fromJson().
Employee.fromJson(super.data) : super.fromJson() {
print('in Employee');
}
// #docregion method-then-constructor
Expand Down
6 changes: 3 additions & 3 deletions examples/misc/lib/language_tour/classes/orchestra.dart
Expand Up @@ -38,7 +38,7 @@ abstract class Performer {
// #docregion Musician-and-Maestro
class Musician extends Performer with Musical {
// #enddocregion Musician-and-Maestro
Musician(String name) : super(name);
Musician(super.name);
// #docregion Musician-and-Maestro
}

Expand All @@ -55,7 +55,7 @@ class Maestro extends Person with Musical, Aggressive, Demented {

class Musician2 extends Performer with Musical {
Musician2() : super('Anonymous');
Musician2.withName(String name) : super(name);
Musician2.withName(super.name);
}

// Simple version of Musician for the mixin example.
Expand Down Expand Up @@ -85,7 +85,7 @@ mixin MusicalPerformer on Musician2 {
class SingerDancer extends Musician2 with MusicalPerformer {
// ...
// #enddocregion mixin-on
SingerDancer(String name) : super.withName(name);
SingerDancer(super.name) : super.withName();
// #docregion mixin-on
}
// #enddocregion mixin-on
Expand Down
5 changes: 2 additions & 3 deletions examples/misc/lib/language_tour/functions.dart
Expand Up @@ -92,7 +92,6 @@ abstract class Widget {

class Scrollbar extends Widget {
// #docregion required-named-parameters
const Scrollbar({Key? key, required Widget child})
// #enddocregion required-named-parameters
: super(key: key);
const Scrollbar({super.key, required Widget child});
// #enddocregion required-named-parameters
}
5 changes: 2 additions & 3 deletions examples/misc/lib/samples/spacecraft.dart
Expand Up @@ -33,8 +33,7 @@ class Spacecraft {
class Orbiter extends Spacecraft {
double altitude;

Orbiter(String name, DateTime launchDate, this.altitude)
: super(name, launchDate);
Orbiter(super.name, DateTime super.launchDate, this.altitude);
}
// #enddocregion extends

Expand All @@ -51,7 +50,7 @@ mixin Piloted {
// #docregion mixin-use
class PilotedCraft extends Spacecraft with Piloted {
// #enddocregion mixin-use
PilotedCraft(String name, DateTime launchDate) : super(name, launchDate);
PilotedCraft(super.name, DateTime super.launchDate);
// #docregion mixin-use
}
// #enddocregion mixin-use
Expand Down
2 changes: 1 addition & 1 deletion src/_guides/language/effective-dart/usage.md
Expand Up @@ -1288,7 +1288,7 @@ class Box extends BaseBox {
{% endprettify %}

This looks surprising, but works like you want. Fortunately, code like this is
relatively rare thanks to initializing formals.
relatively rare thanks to initializing formals and super initializers.


### DO initialize fields at their declaration when possible.
Expand Down
6 changes: 3 additions & 3 deletions src/_guides/language/language-tour.md
Expand Up @@ -1359,7 +1359,7 @@ For example:

<?code-excerpt "misc/lib/language_tour/functions.dart (required-named-parameters)" replace="/required/[!$&!]/g"?>
{% prettify dart tag=pre+code %}
const Scrollbar({Key? key, [!required!] Widget child})
const Scrollbar({super.key, [!required!] Widget child});
{% endprettify %}

If someone tries to create a `Scrollbar`
Expand Down Expand Up @@ -2986,8 +2986,8 @@ class Person {
class Employee extends Person {
// Person does not have a default constructor;
// you must call super.fromJson(data).
Employee.fromJson(Map data) : super.fromJson(data) {
// you must call super.fromJson().
Employee.fromJson(super.data) : super.fromJson() {
print('in Employee');
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/samples/index.md
Expand Up @@ -287,8 +287,7 @@ Dart has single inheritance.
class Orbiter extends Spacecraft {
double altitude;
Orbiter(String name, DateTime launchDate, this.altitude)
: super(name, launchDate);
Orbiter(super.name, DateTime super.launchDate, this.altitude);
}
```

Expand Down

0 comments on commit cd66498

Please sign in to comment.