From 9a82e003ba5c7840763923e35354be8daa43ce86 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Thu, 15 Dec 2022 21:36:04 -0600 Subject: [PATCH] Minor sample index cleanup (#1532) --- web/_tool/build_ci.dart | 4 ++-- web/_tool/peanut_post_build.dart | 2 +- web/_tool/pubspec.yaml | 2 +- web/samples_index/.gitignore | 1 - web/samples_index/README.md | 14 ++++++------- web/samples_index/analysis_options.yaml | 6 ++++++ web/samples_index/lib/cookbook.dart | 6 +++--- web/samples_index/lib/src/carousel.dart | 18 ++++++++-------- web/samples_index/lib/src/data.dart | 17 ++++++++-------- web/samples_index/lib/src/search.dart | 8 ++++---- web/samples_index/lib/src/templates.dart | 23 ++++++++++----------- web/samples_index/pubspec.yaml | 26 ++++++++++++++---------- web/samples_index/tool/grind.dart | 14 ++++++------- web/samples_index/web/main.dart | 2 +- web/samples_index/web/styles.scss | 2 +- 15 files changed, 77 insertions(+), 68 deletions(-) diff --git a/web/_tool/build_ci.dart b/web/_tool/build_ci.dart index 5882c274a..1713607be 100644 --- a/web/_tool/build_ci.dart +++ b/web/_tool/build_ci.dart @@ -7,9 +7,9 @@ import 'package:path/path.dart' as p; import 'common.dart'; import 'fix_base_tags.dart'; -final ignoredDirectories = ['_tool', 'samples_index']; +const ignoredDirectories = ['_tool', 'samples_index']; -main() async { +void main() async { final packageDirs = [ ...listPackageDirs(Directory.current) .map((path) => p.relative(path, from: Directory.current.path)) diff --git a/web/_tool/peanut_post_build.dart b/web/_tool/peanut_post_build.dart index 683132d3f..c7482751f 100644 --- a/web/_tool/peanut_post_build.dart +++ b/web/_tool/peanut_post_build.dart @@ -14,7 +14,7 @@ import 'package:path/path.dart' as p; import 'common.dart'; -main(List args) async { +void main(List args) async { final buildDir = args[0]; final fileMap = (jsonDecode(args[1]) as Map).cast(); diff --git a/web/_tool/pubspec.yaml b/web/_tool/pubspec.yaml index 157e4f497..ba5630c78 100644 --- a/web/_tool/pubspec.yaml +++ b/web/_tool/pubspec.yaml @@ -2,7 +2,7 @@ name: tool publish_to: none environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' dependencies: markdown: ^6.0.0 diff --git a/web/samples_index/.gitignore b/web/samples_index/.gitignore index bc8e6f07c..99161f407 100644 --- a/web/samples_index/.gitignore +++ b/web/samples_index/.gitignore @@ -3,7 +3,6 @@ public/ # Files and directories created by pub .dart_tool/ -.packages # Remove the following pattern if you wish to check in your lock file pubspec.lock diff --git a/web/samples_index/README.md b/web/samples_index/README.md index ff23f21fb..06d60ab74 100644 --- a/web/samples_index/README.md +++ b/web/samples_index/README.md @@ -7,9 +7,8 @@ This tool is used to generate the visual samples index for Flutter samples. We use [grinder](https://pub.dev/packages/grinder) to run the build tasks: ```bash -$ pub get -$ pub global activate grinder -$ grind generate +$ dart pub get +$ dart run grinder generate ``` This will generate the index into `./web` @@ -20,6 +19,7 @@ If you want to serve the index locally, you can use [webdev](https://pub.dev/packages/webdev): ```bash +$ dart pub global activate grinder $ webdev serve ``` @@ -28,16 +28,16 @@ $ webdev serve You can build the complete index into a publishable directory using Grinder: ```bash -$ grind build-release +$ dart run grinder build-release ``` This outputs the completely built index to `./public`. ## Generating cookbook content -The cookbook articles are generated using a WebDriver script that scrapes the -flutter.dev website. To run: +The cookbook articles are generated using a WebDriver script +that scrapes the docs.flutter.dev website. To run: 1. Install [ChromeDriver](https://chromedriver.chromium.org/downloads) 2. run `chromedriver --port=4444 --url-base=wd/hub --verbose` -3. run `grind scrape-cookbook` +3. run `dart run grinder scrape-cookbook` diff --git a/web/samples_index/analysis_options.yaml b/web/samples_index/analysis_options.yaml index d7eb49106..973c98aad 100644 --- a/web/samples_index/analysis_options.yaml +++ b/web/samples_index/analysis_options.yaml @@ -6,6 +6,7 @@ analyzer: language: strict-casts: true strict-inference: true + strict-raw-types: true linter: rules: @@ -16,6 +17,11 @@ linter: directives_ordering: true package_api_docs: true package_prefixed_library_names: true + prefer_final_in_for_each: true + prefer_single_quotes: true test_types_in_equals: true throw_in_finally: true + unawaited_futures: true unnecessary_statements: true + use_enums: true + use_super_parameters: true diff --git a/web/samples_index/lib/cookbook.dart b/web/samples_index/lib/cookbook.dart index 2db0bbd67..8f0fb978f 100644 --- a/web/samples_index/lib/cookbook.dart +++ b/web/samples_index/lib/cookbook.dart @@ -14,11 +14,11 @@ import 'package:webdriver/io.dart'; class CookbookScraper { late WebDriver _driver; - Future init() async { + Future init() async { _driver = await createDriver(desired: {}); } - Future dispose() async { + Future dispose() async { await _driver.quit(); } @@ -59,7 +59,7 @@ class CookbookScraper { ); } - Future takeScreenshot(String url) async { + Future takeScreenshot(String url) async { var screenshot = await _driver.captureScreenshotAsList(); var file = File('web/${screenshotPath(url)}'); await file.create(recursive: true); diff --git a/web/samples_index/lib/src/carousel.dart b/web/samples_index/lib/src/carousel.dart index b617e983f..9d1841c80 100644 --- a/web/samples_index/lib/src/carousel.dart +++ b/web/samples_index/lib/src/carousel.dart @@ -11,7 +11,7 @@ class Carousel { final List slides = querySelectorAll('.slider-single'); late int currentSlideIndex; - late int lastSlideIndex; + late final int lastSlideIndex; late Element prevSlide, currentSlide, nextSlide; @@ -127,24 +127,24 @@ class Carousel { } void _checkRepeat() { - var prevArrow = querySelector('.slider-left'); - var nextArrow = querySelector('.slider-right'); + var prevArrow = querySelector('.slider-left') as AnchorElement; + var nextArrow = querySelector('.slider-right') as AnchorElement; if (currentSlideIndex == slides.length - 1) { slides[0].classes.add('hidden'); slides[slides.length - 1].classes.remove('hidden'); - prevArrow!.classes.remove('hidden'); - nextArrow!.classes.add('hidden'); + prevArrow.classes.remove('hidden'); + nextArrow.classes.add('hidden'); } else if (currentSlideIndex == 0) { slides[slides.length - 1].classes.add('hidden'); slides[0].classes.remove('hidden'); - prevArrow!.classes.add('hidden'); - nextArrow!.classes.remove('hidden'); + prevArrow.classes.add('hidden'); + nextArrow.classes.remove('hidden'); } else { slides[slides.length - 1].classes.remove('hidden'); slides[0].classes.remove('hidden'); - prevArrow!.classes.remove('hidden'); - nextArrow!.classes.remove('hidden'); + prevArrow.classes.remove('hidden'); + nextArrow.classes.remove('hidden'); } } diff --git a/web/samples_index/lib/src/data.dart b/web/samples_index/lib/src/data.dart index 3332b5e05..a33d66ca7 100644 --- a/web/samples_index/lib/src/data.dart +++ b/web/samples_index/lib/src/data.dart @@ -22,7 +22,7 @@ class Index { Index(this.samples); - factory Index.fromJson(Map json) => _$IndexFromJson(json); + factory Index.fromJson(Map json) => _$IndexFromJson(json); Map toJson() => _$IndexToJson(this); } @@ -100,7 +100,7 @@ class Sample { this.channel, }); - factory Sample.fromJson(Map json) => _$SampleFromJson(json); + factory Sample.fromJson(Map json) => _$SampleFromJson(json); Map toJson() => _$SampleToJson(this); @@ -116,25 +116,25 @@ class Sample { buf.write(name.toLowerCase()); buf.write(' '); - for (var tag in tags) { + for (final tag in tags) { buf.write('tag:${tag.toLowerCase()} '); // Allow tags to be searched without the tag: prefix buf.write('${tag.toLowerCase()} '); } - for (var platform in platforms) { + for (final platform in platforms) { buf.write('platform:$platform '); // Allow platforms to be searched without the tag: prefix buf.write('$platform '); } - for (var widget in widgets) { + for (final widget in widgets) { buf.write('widget:$widget '); } - for (var package in packages) { + for (final package in packages) { buf.write('package:$package '); } @@ -167,7 +167,8 @@ class Screenshot { Screenshot(this.url, this.alt); - factory Screenshot.fromJson(Map json) => _$ScreenshotFromJson(json); + factory Screenshot.fromJson(Map json) => + _$ScreenshotFromJson(json); Map toJson() => _$ScreenshotToJson(this); } @@ -180,7 +181,7 @@ class Link { Link(this.text, this.href); - factory Link.fromJson(Map json) => _$LinkFromJson(json); + factory Link.fromJson(Map json) => _$LinkFromJson(json); Map toJson() => _$LinkToJson(this); } diff --git a/web/samples_index/lib/src/search.dart b/web/samples_index/lib/src/search.dart index c8d00c510..7f57e7794 100644 --- a/web/samples_index/lib/src/search.dart +++ b/web/samples_index/lib/src/search.dart @@ -16,7 +16,7 @@ bool matchesQuery(String query, String sampleAttributes) { // This will check whether a type parameter is present in the // search query, and return false if the self type mismatches // the query type - for (var word in queryWords) { + for (final word in queryWords) { if ((word.contains('type:') && !attributes.contains(word)) || (word.contains('platform:') && !attributes.contains('type:demo'))) { return false; @@ -30,7 +30,7 @@ bool matchesQuery(String query, String sampleAttributes) { // Test for exact matches for keywords var matches = 0; - for (var word in queryWords) { + for (final word in queryWords) { if (attributes.contains(word)) { matches++; } @@ -43,8 +43,8 @@ bool matchesQuery(String query, String sampleAttributes) { // e.g. searching "kitten tag:cats" is a match for a sample with the // attributes "kittens tag:cats" matches = 0; - for (var attribute in attributes) { - for (var queryWord in queryWords) { + for (final attribute in attributes) { + for (final queryWord in queryWords) { if (attribute.startsWith(queryWord)) { matches++; } diff --git a/web/samples_index/lib/src/templates.dart b/web/samples_index/lib/src/templates.dart index aeabdf027..5d8c98ece 100644 --- a/web/samples_index/lib/src/templates.dart +++ b/web/samples_index/lib/src/templates.dart @@ -29,7 +29,7 @@ $_footer '''; -String _indexHeader = ''' +const String _indexHeader = ''' Flutter samples @@ -39,11 +39,11 @@ String _indexHeader = ''' - ${_googleAnalytics()} + $_googleAnalytics '''; -String _descriptionHeader = ''' +const String _descriptionHeader = ''' Flutter samples @@ -54,11 +54,11 @@ String _descriptionHeader = ''' - ${_googleAnalytics()} + $_googleAnalytics '''; -String _navbar = ''' +const String _navbar = '''