Skip to content

Commit

Permalink
Update lints for v3 releases (#2688)
Browse files Browse the repository at this point in the history
Co-authored-by: Devon Carew <[email protected]>
  • Loading branch information
parlough and devoncarew authored Oct 22, 2023
1 parent 4c5b0a7 commit 55029b7
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 55 deletions.
8 changes: 4 additions & 4 deletions pkgs/dart_pad/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ packages:
dependency: "direct dev"
description:
name: dart_flutter_team_lints
sha256: "0917c8b64a29532a7e6835e164131c89a5925fbf1e3a4319558b95f4ef623d64"
sha256: "091ced68bc78ae8002003065486fd052d556903ba6c68a4d47ca574c80e6013f"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.1"
dart_style:
dependency: transitive
description:
Expand Down Expand Up @@ -436,10 +436,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: "5e5a8fdb6c327a998e3e14b611829e080b3bee14bdd9ae41bbc2efac77bc0dca"
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
url: "https://pub.dev"
source: hosted
version: "3.0.0-beta.2"
version: "3.0.0"
logging:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dart_pad/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dev_dependencies:
build_runner: ^2.4.4
build_test: ^2.1.7
build_web_compilers: ^4.0.3
dart_flutter_team_lints: ^2.0.0
dart_flutter_team_lints: ^2.1.1
git: ^2.0.0
grinder: ^0.9.4
json_serializable: ^6.7.0
Expand Down
8 changes: 4 additions & 4 deletions pkgs/dart_services/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ packages:
dependency: "direct dev"
description:
name: dart_flutter_team_lints
sha256: "0917c8b64a29532a7e6835e164131c89a5925fbf1e3a4319558b95f4ef623d64"
sha256: "091ced68bc78ae8002003065486fd052d556903ba6c68a4d47ca574c80e6013f"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.1"
dart_style:
dependency: transitive
description:
Expand Down Expand Up @@ -349,10 +349,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: "5e5a8fdb6c327a998e3e14b611829e080b3bee14bdd9ae41bbc2efac77bc0dca"
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
url: "https://pub.dev"
source: hosted
version: "3.0.0-beta.2"
version: "3.0.0"
logging:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dart_services/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dev_dependencies:
angel3_mock_request: ^8.0.0
async: ^2.11.0
build_runner: ^2.4.5
dart_flutter_team_lints: ^2.0.0
dart_flutter_team_lints: ^2.1.1
grinder: ^0.9.4
json_serializable: any
package_config: ^2.1.0
Expand Down
11 changes: 11 additions & 0 deletions pkgs/dartpad_shared/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
- prefer_final_in_for_each
- prefer_final_locals
2 changes: 1 addition & 1 deletion pkgs/dartpad_shared/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ dependencies:

dev_dependencies:
build_runner: ^2.4.5
dart_flutter_team_lints: ^2.0.0
dart_flutter_team_lints: ^2.1.1
json_serializable: ^6.7.0
2 changes: 2 additions & 0 deletions pkgs/samples/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ analyzer:

linter:
rules:
- directives_ordering
- prefer_relative_imports
- prefer_single_quotes
2 changes: 1 addition & 1 deletion pkgs/samples/lib/fibonacci.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// that can be found in the LICENSE file.

void main() {
var i = 20;
const i = 20;

print('fibonacci($i) = ${fibonacci(i)}');
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/samples/lib/hello_world.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// that can be found in the LICENSE file.

void main() {
for (int i = 0; i < 10; i++) {
for (var i = 0; i < 10; i++) {
print('hello ${i + 1}');
}
}
4 changes: 2 additions & 2 deletions pkgs/samples/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class MyHomePage extends StatefulWidget {
final String title;

const MyHomePage({
Key? key,
super.key,
required this.title,
}) : super(key: key);
});

@override
State<MyHomePage> createState() => _MyHomePageState();
Expand Down
2 changes: 1 addition & 1 deletion pkgs/samples/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dev_dependencies:
args: ^2.4.0
# flutter_test:
# sdk: flutter
flutter_lints: ^2.0.0
flutter_lints: ^3.0.0
path: ^1.8.0

flutter:
Expand Down
28 changes: 14 additions & 14 deletions pkgs/samples/tool/samples.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Samples {

void parse() {
// read the samples
var json =
final json =
jsonDecode(File(p.join('lib', 'samples.json')).readAsStringSync());

defaults = (json['defaults'] as Map).cast<String, String>();
Expand All @@ -55,13 +55,13 @@ class Samples {
hadFailure = true;
}

for (var entry in defaults.entries) {
for (final entry in defaults.entries) {
if (!File(entry.value).existsSync()) {
fail('File ${entry.value} not found.');
}
}

for (var sample in samples) {
for (final sample in samples) {
print(sample);

if (sample.id.contains(' ')) {
Expand Down Expand Up @@ -90,16 +90,16 @@ class Samples {

void generate() {
// readme.md
var readme = File('README.md');
final readme = File('README.md');
readme.writeAsStringSync(_generateReadmeContent());

// print generation message
print('');
print('Wrote ${readme.path}');

// samples.g.dart
var codeFile = File('../sketch_pad/lib/samples.g.dart');
var contents = _generateSourceContent();
final codeFile = File('../sketch_pad/lib/samples.g.dart');
final contents = _generateSourceContent();
codeFile.writeAsStringSync(contents);
print('Wrote ${codeFile.path}');
}
Expand All @@ -109,7 +109,7 @@ class Samples {

print('Verifying sample file generation...');

var readme = File('README.md');
final readme = File('README.md');
if (readme.readAsStringSync() != _generateReadmeContent()) {
stderr.writeln('Generated sample files not up-to-date.');
stderr.writeln('Re-generate by running:');
Expand All @@ -126,8 +126,8 @@ class Samples {
String _generateReadmeContent() {
const marker = '<!-- samples -->';

var contents = File('README.md').readAsStringSync();
var table = _generateTable();
final contents = File('README.md').readAsStringSync();
final table = _generateTable();

return contents.substring(0, contents.indexOf(marker) + marker.length + 1) +
table +
Expand All @@ -143,7 +143,7 @@ ${samples.map((s) => s.toTableRow()).join('\n')}
}

String _generateSourceContent() {
var buf = StringBuffer('''
final buf = StringBuffer('''
// Copyright 2023 the Dart project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
Expand Down Expand Up @@ -189,8 +189,8 @@ class Samples {

buf.writeln('Map<String, String> _defaults = {');

for (var entry in defaults.entries) {
var source = File(entry.value).readAsStringSync().trimRight();
for (final entry in defaults.entries) {
final source = File(entry.value).readAsStringSync().trimRight();
buf.writeln(" '${entry.key}': r'''\n$source\n''',");
}

Expand All @@ -202,7 +202,7 @@ class Samples {
}

String _mapForCategory(String category) {
var items = samples.where((s) => s.category == category);
final items = samples.where((s) => s.category == category);
return ''''$category': [
${items.map((i) => i.sourceId).join(',\n ')},
]''';
Expand Down Expand Up @@ -234,7 +234,7 @@ class Sample implements Comparable<Sample> {
String get sourceId {
var gen = id;
while (gen.contains('-')) {
var index = id.indexOf('-');
final index = id.indexOf('-');
gen = gen.substring(0, index) +
gen.substring(index + 1, index + 2).toUpperCase() +
gen.substring(index + 2);
Expand Down
2 changes: 2 additions & 0 deletions pkgs/sketch_pad/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ analyzer:
linter:
rules:
- directives_ordering
- prefer_final_in_for_each
- prefer_final_locals
- prefer_relative_imports
- prefer_single_quotes
2 changes: 1 addition & 1 deletion pkgs/sketch_pad/lib/editor/completion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AnalysisCompletion {
bool get isDeprecated => suggestion.deprecated;

HintResult toCodemirrorHint() {
var replaceText = suggestion.completion;
final replaceText = suggestion.completion;

var displayText = suggestion.displayText;
if (displayText == null) {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/sketch_pad/lib/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class _EditorWidgetState extends State<EditorWidget> implements EditorService {
}

void _updateCodemirrorFromModel() {
var value = widget.appModel.sourceCodeController.text;
final value = widget.appModel.sourceCodeController.text;
codeMirror!.doc.setValue(value);
}

Expand Down Expand Up @@ -244,7 +244,7 @@ class _EditorWidgetState extends State<EditorWidget> implements EditorService {
// same.
final memos = <String>{};
hints.retainWhere((hint) {
var memo = '${hint.text}:${hint.displayText}';
final memo = '${hint.text}:${hint.displayText}';
if (memos.contains(memo)) return false;

memos.add(memo);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/sketch_pad/lib/execution/execution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void _initViewFactory() {

html.Element _iFrameFactory(int viewId) {
// 'allow-popups' allows plugins like url_launcher to open popups.
var frame = html.IFrameElement()
final frame = html.IFrameElement()
..sandbox!.add('allow-scripts')
..sandbox!.add('allow-popups')
..src = 'frame.html'
Expand Down
2 changes: 1 addition & 1 deletion pkgs/sketch_pad/lib/gists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GistLoader {
final http.Client client = http.Client();

Future<Gist> load(String gistId) async {
var response =
final response =
await client.get(Uri.parse('https://api.github.com/gists/$gistId'));

if (response.statusCode != 200) {
Expand Down
12 changes: 6 additions & 6 deletions pkgs/sketch_pad/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class _DartPadMainPageState extends State<DartPadMainPage> {
} catch (error) {
appModel.editorStatus.showToast('Compilation failed');

var message = error is ApiRequestError ? error.message : '$error';
final message = error is ApiRequestError ? error.message : '$error';
appModel.appendLineToConsole(message);
} finally {
progress.close();
Expand Down Expand Up @@ -633,10 +633,10 @@ class ListSamplesWidget extends StatelessWidget {
}

Future<String?> _showMenu(BuildContext context, RelativeRect position) {
var categories = Samples.categories.keys;
final categories = Samples.categories.keys;

final menuItems = <PopupMenuEntry<String?>>[
for (var category in categories) ...[
for (final category in categories) ...[
const PopupMenuDivider(),
PopupMenuItem(
value: null,
Expand Down Expand Up @@ -706,7 +706,7 @@ class SelectChannelWidget extends StatelessWidget {
const itemHeight = 46.0;

final menuItems = <PopupMenuEntry<Channel>>[
for (var channel in Channel.valuesWithoutLocalhost)
for (final channel in Channel.valuesWithoutLocalhost)
PopupMenuItem<Channel>(
value: channel,
child: PointerInterceptor(
Expand Down Expand Up @@ -849,8 +849,8 @@ class VersionInfoWidget extends StatefulWidget {

const VersionInfoWidget(
this.versions, {
Key? key,
}) : super(key: key);
super.key,
});

@override
State<VersionInfoWidget> createState() => _VersionInfoWidgetState();
Expand Down
8 changes: 4 additions & 4 deletions pkgs/sketch_pad/lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class AppServices {
// Delay a bit for codemirror to initialize.
await Future<void>.delayed(const Duration(milliseconds: 1));

var sample = Samples.getById(sampleId);
final sample = Samples.getById(sampleId);
if (sample != null) {
appModel.title.value = sample.name;
appModel.sourceCodeController.text = sample.source;
Expand All @@ -195,7 +195,7 @@ class AppServices {
final gist = await gistLoader.load(gistId);
progress.close();

var title = gist.description ?? '';
final title = gist.description ?? '';
appModel.title.value =
title.length > 40 ? '${title.substring(0, 40)}…' : title;

Expand Down Expand Up @@ -284,7 +284,7 @@ class AppServices {
final issues = results.issues.toList()..sort(_compareIssues);
appModel.analysisIssues.value = issues;
} catch (error) {
var message = error is ApiRequestError ? error.message : '$error';
final message = error is ApiRequestError ? error.message : '$error';
appModel.analysisIssues.value = [
AnalysisIssue(kind: 'error', message: message),
];
Expand All @@ -310,7 +310,7 @@ class AppServices {
}

int _compareIssues(AnalysisIssue a, AnalysisIssue b) {
var diff = a.severity - b.severity;
final diff = a.severity - b.severity;
if (diff != 0) return -diff;

return a.charStart - b.charStart;
Expand Down
12 changes: 6 additions & 6 deletions pkgs/sketch_pad/lib/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Hyperlink extends StatefulWidget {
required this.url,
this.displayText,
this.style,
Key? key,
}) : super(key: key);
super.key,
});

@override
State<Hyperlink> createState() => _HyperlinkState();
Expand Down Expand Up @@ -151,14 +151,14 @@ class MediumDialog extends StatelessWidget {
required this.title,
this.smaller = false,
required this.child,
Key? key,
}) : super(key: key);
super.key,
});

@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
var width = smaller ? 400.0 : 500.0;
var height = smaller ? 325.0 : 400.0;
final width = smaller ? 400.0 : 500.0;
final height = smaller ? 325.0 : 400.0;

return PointerInterceptor(
child: AlertDialog(
Expand Down
Loading

0 comments on commit 55029b7

Please sign in to comment.