diff --git a/pkgs/dart_pad/pubspec.lock b/pkgs/dart_pad/pubspec.lock index 0c3335d78..017cf1abf 100644 --- a/pkgs/dart_pad/pubspec.lock +++ b/pkgs/dart_pad/pubspec.lock @@ -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: @@ -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: diff --git a/pkgs/dart_pad/pubspec.yaml b/pkgs/dart_pad/pubspec.yaml index ff4d546c0..82bc2f15e 100644 --- a/pkgs/dart_pad/pubspec.yaml +++ b/pkgs/dart_pad/pubspec.yaml @@ -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 diff --git a/pkgs/dart_services/pubspec.lock b/pkgs/dart_services/pubspec.lock index 8a546b3d2..54d39bcfc 100644 --- a/pkgs/dart_services/pubspec.lock +++ b/pkgs/dart_services/pubspec.lock @@ -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: @@ -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: diff --git a/pkgs/dart_services/pubspec.yaml b/pkgs/dart_services/pubspec.yaml index 1070efe11..851b6ae12 100644 --- a/pkgs/dart_services/pubspec.yaml +++ b/pkgs/dart_services/pubspec.yaml @@ -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 diff --git a/pkgs/dartpad_shared/analysis_options.yaml b/pkgs/dartpad_shared/analysis_options.yaml index d978f811c..c5bc1a8fc 100644 --- a/pkgs/dartpad_shared/analysis_options.yaml +++ b/pkgs/dartpad_shared/analysis_options.yaml @@ -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 diff --git a/pkgs/dartpad_shared/pubspec.yaml b/pkgs/dartpad_shared/pubspec.yaml index b7c9fbb53..f863ba7d0 100644 --- a/pkgs/dartpad_shared/pubspec.yaml +++ b/pkgs/dartpad_shared/pubspec.yaml @@ -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 diff --git a/pkgs/samples/analysis_options.yaml b/pkgs/samples/analysis_options.yaml index 5d22437f9..9aa633569 100644 --- a/pkgs/samples/analysis_options.yaml +++ b/pkgs/samples/analysis_options.yaml @@ -6,4 +6,6 @@ analyzer: linter: rules: + - directives_ordering + - prefer_relative_imports - prefer_single_quotes diff --git a/pkgs/samples/lib/fibonacci.dart b/pkgs/samples/lib/fibonacci.dart index 185ed1b41..14ca78972 100644 --- a/pkgs/samples/lib/fibonacci.dart +++ b/pkgs/samples/lib/fibonacci.dart @@ -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)}'); } diff --git a/pkgs/samples/lib/hello_world.dart b/pkgs/samples/lib/hello_world.dart index 790d1f948..f8c5b7101 100644 --- a/pkgs/samples/lib/hello_world.dart +++ b/pkgs/samples/lib/hello_world.dart @@ -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}'); } } diff --git a/pkgs/samples/lib/main.dart b/pkgs/samples/lib/main.dart index fe703a36a..12bbdd4bd 100644 --- a/pkgs/samples/lib/main.dart +++ b/pkgs/samples/lib/main.dart @@ -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 createState() => _MyHomePageState(); diff --git a/pkgs/samples/pubspec.yaml b/pkgs/samples/pubspec.yaml index 2d6fd718e..58decd791 100644 --- a/pkgs/samples/pubspec.yaml +++ b/pkgs/samples/pubspec.yaml @@ -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: diff --git a/pkgs/samples/tool/samples.dart b/pkgs/samples/tool/samples.dart index a374c3da7..a291b1b87 100644 --- a/pkgs/samples/tool/samples.dart +++ b/pkgs/samples/tool/samples.dart @@ -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(); @@ -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(' ')) { @@ -90,7 +90,7 @@ class Samples { void generate() { // readme.md - var readme = File('README.md'); + final readme = File('README.md'); readme.writeAsStringSync(_generateReadmeContent()); // print generation message @@ -98,8 +98,8 @@ class Samples { 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}'); } @@ -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:'); @@ -126,8 +126,8 @@ class Samples { String _generateReadmeContent() { const marker = ''; - 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 + @@ -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. @@ -189,8 +189,8 @@ class Samples { buf.writeln('Map _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''',"); } @@ -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 ')}, ]'''; @@ -234,7 +234,7 @@ class Sample implements Comparable { 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); diff --git a/pkgs/sketch_pad/analysis_options.yaml b/pkgs/sketch_pad/analysis_options.yaml index 06c3cdd8d..ac5006b34 100644 --- a/pkgs/sketch_pad/analysis_options.yaml +++ b/pkgs/sketch_pad/analysis_options.yaml @@ -9,5 +9,7 @@ analyzer: linter: rules: - directives_ordering + - prefer_final_in_for_each + - prefer_final_locals - prefer_relative_imports - prefer_single_quotes diff --git a/pkgs/sketch_pad/lib/editor/completion.dart b/pkgs/sketch_pad/lib/editor/completion.dart index 8a2242a07..d96fdbe8d 100644 --- a/pkgs/sketch_pad/lib/editor/completion.dart +++ b/pkgs/sketch_pad/lib/editor/completion.dart @@ -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) { diff --git a/pkgs/sketch_pad/lib/editor/editor.dart b/pkgs/sketch_pad/lib/editor/editor.dart index 10ba868fa..fe6602fb2 100644 --- a/pkgs/sketch_pad/lib/editor/editor.dart +++ b/pkgs/sketch_pad/lib/editor/editor.dart @@ -184,7 +184,7 @@ class _EditorWidgetState extends State implements EditorService { } void _updateCodemirrorFromModel() { - var value = widget.appModel.sourceCodeController.text; + final value = widget.appModel.sourceCodeController.text; codeMirror!.doc.setValue(value); } @@ -244,7 +244,7 @@ class _EditorWidgetState extends State implements EditorService { // same. final memos = {}; hints.retainWhere((hint) { - var memo = '${hint.text}:${hint.displayText}'; + final memo = '${hint.text}:${hint.displayText}'; if (memos.contains(memo)) return false; memos.add(memo); diff --git a/pkgs/sketch_pad/lib/execution/execution.dart b/pkgs/sketch_pad/lib/execution/execution.dart index f950cc600..4a72606e4 100644 --- a/pkgs/sketch_pad/lib/execution/execution.dart +++ b/pkgs/sketch_pad/lib/execution/execution.dart @@ -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' diff --git a/pkgs/sketch_pad/lib/gists.dart b/pkgs/sketch_pad/lib/gists.dart index f29d553f4..05b62743d 100644 --- a/pkgs/sketch_pad/lib/gists.dart +++ b/pkgs/sketch_pad/lib/gists.dart @@ -11,7 +11,7 @@ class GistLoader { final http.Client client = http.Client(); Future load(String gistId) async { - var response = + final response = await client.get(Uri.parse('https://api.github.com/gists/$gistId')); if (response.statusCode != 200) { diff --git a/pkgs/sketch_pad/lib/main.dart b/pkgs/sketch_pad/lib/main.dart index 5287458a3..7af7f63f1 100644 --- a/pkgs/sketch_pad/lib/main.dart +++ b/pkgs/sketch_pad/lib/main.dart @@ -422,7 +422,7 @@ class _DartPadMainPageState extends State { } 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(); @@ -633,10 +633,10 @@ class ListSamplesWidget extends StatelessWidget { } Future _showMenu(BuildContext context, RelativeRect position) { - var categories = Samples.categories.keys; + final categories = Samples.categories.keys; final menuItems = >[ - for (var category in categories) ...[ + for (final category in categories) ...[ const PopupMenuDivider(), PopupMenuItem( value: null, @@ -706,7 +706,7 @@ class SelectChannelWidget extends StatelessWidget { const itemHeight = 46.0; final menuItems = >[ - for (var channel in Channel.valuesWithoutLocalhost) + for (final channel in Channel.valuesWithoutLocalhost) PopupMenuItem( value: channel, child: PointerInterceptor( @@ -849,8 +849,8 @@ class VersionInfoWidget extends StatefulWidget { const VersionInfoWidget( this.versions, { - Key? key, - }) : super(key: key); + super.key, + }); @override State createState() => _VersionInfoWidgetState(); diff --git a/pkgs/sketch_pad/lib/model.dart b/pkgs/sketch_pad/lib/model.dart index 39b9a7dc0..63388ef31 100644 --- a/pkgs/sketch_pad/lib/model.dart +++ b/pkgs/sketch_pad/lib/model.dart @@ -175,7 +175,7 @@ class AppServices { // Delay a bit for codemirror to initialize. await Future.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; @@ -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; @@ -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), ]; @@ -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; diff --git a/pkgs/sketch_pad/lib/widgets.dart b/pkgs/sketch_pad/lib/widgets.dart index 9db0e9b3f..c95907749 100644 --- a/pkgs/sketch_pad/lib/widgets.dart +++ b/pkgs/sketch_pad/lib/widgets.dart @@ -19,8 +19,8 @@ class Hyperlink extends StatefulWidget { required this.url, this.displayText, this.style, - Key? key, - }) : super(key: key); + super.key, + }); @override State createState() => _HyperlinkState(); @@ -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( diff --git a/pkgs/sketch_pad/pubspec.yaml b/pkgs/sketch_pad/pubspec.yaml index 90d10ba7c..21a2734a6 100644 --- a/pkgs/sketch_pad/pubspec.yaml +++ b/pkgs/sketch_pad/pubspec.yaml @@ -26,7 +26,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.0 + flutter_lints: ^3.0.0 test: any flutter: diff --git a/pkgs/sketch_pad/test/gists_test.dart b/pkgs/sketch_pad/test/gists_test.dart index 5792a3c88..17c55359a 100644 --- a/pkgs/sketch_pad/test/gists_test.dart +++ b/pkgs/sketch_pad/test/gists_test.dart @@ -10,7 +10,8 @@ import 'package:test/test.dart'; void main() { group('gists', () { test('parses json', () { - var gist = Gist.fromJson(jsonDecode(jsonSample) as Map); + final gist = + Gist.fromJson(jsonDecode(jsonSample) as Map); expect(gist.id, 'd3bd83918d21b6d5f778bdc69c3d36d6'); expect(gist.description, 'Fibonacci'); @@ -19,13 +20,14 @@ void main() { }); test('finds main.dart', () { - var gist = Gist.fromJson(jsonDecode(jsonSample) as Map); + final gist = + Gist.fromJson(jsonDecode(jsonSample) as Map); expect(gist.mainDartSource, isNotNull); }); test('recognizes main.dart missing', () { - var gist = + final gist = Gist.fromJson(jsonDecode(jsonSampleNoMain) as Map); expect(gist.mainDartSource, isNull);