Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid cumbersome formatter workaround #6573

Merged
merged 3 commits into from
Jun 4, 2024
Merged

Conversation

lrhn
Copy link
Contributor

@lrhn lrhn commented Apr 19, 2024

If a list shouldn't be formatted with one element on each line, a single EOL-comment inside is enough to disable the formatter. Much simpler.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

RegExp(r' *0x([A-F0-9]{2}),? *\n? *'), (Match m) => '${m[1]}\n'))
.map<int>((String b) => int.parse(b, radix: 16))
.toList();
];
Copy link
Contributor Author

@lrhn lrhn Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another, still simpler than the original, workaround would be:

final String _imageBytesString =
  '\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49'
  '\x48\x44\x52\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06'
  '\x00\x00\x00\x1F\x15\xC4\x89\x00\x00\x00\x0A\x49\x44'
  '\x41\x54\x78\x9C\x63\x00\x01\x00\x00\x05\x00\x01\x0D'
  '\x0A\x2D\xB4\x00\x00\x00\x00\x49\x45\x4E\x44\xAE';
final List<int> _transparentImage = [..._imageBytesString.codeUnits];

Having a full, formatted string, and parsing it using RegExp, just to get to some bytes, feels a little like overkill.


// Convert the string representing the hexidecimal bytes in the image into
// a list of integers that can be consumed as image data in a stream.
final List<int> _transparentImage = const LineSplitter()
Copy link
Contributor Author

@lrhn lrhn Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some possible improvements, for any similar code:

  • For const LineSplitter().convert(...), one can just use LineSplitter.split(...).
  • It's easier to just match the numbers, and then work on allMatches, than to try to remove what's not numbers:
    final List<int> _transparentImage = RegExp(r'0x([A-F0-9]{2})').allMatches(_imageBytesAsString)
        .map((b) => int.parse(b[1], radix: 16))
        .toList();

@stuartmorgan
Copy link
Contributor

@lrhn Are you planning on updating this to pass the analyzer CI check?

If a list shouldn't be formatted with one element on each line, a single EOL-comment inside is enough to disable the formatter.
Much simpler.
@lrhn
Copy link
Contributor Author

lrhn commented May 22, 2024

Merged to head, removed unused import.

@stuartmorgan
Copy link
Contributor

You're still missing a type specifier on the list, so it fails analysis with Flutter settings.

@lrhn
Copy link
Contributor Author

lrhn commented May 22, 2024

Added type to list literal. Now I'm half-expecting to get a warning about having types on both sides of the =. Let's see what Mr. Analyzer says.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label May 22, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 22, 2024
Copy link
Contributor

auto-submit bot commented May 22, 2024

auto label is removed for flutter/packages/6573, due to This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a flutter-hacker before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@stuartmorgan
Copy link
Contributor

@lrhn You might want to request being added to flutter-hackers. Meanwhile, @domesticmouse could you approve this?

@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 4, 2024
Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 6, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jun 6, 2024
flutter/packages@11e192a...586faa6

2024-06-05 [email protected] [google_sign_in_web] Update button_tester to use web_only library. (flutter/packages#6868)
2024-06-05 [email protected] Roll Flutter from c246ecd to 27e0656 (17 revisions) (flutter/packages#6875)
2024-06-05 [email protected] [path_provider] Skip verifying sample file on macOS (flutter/packages#6874)
2024-06-05 [email protected] [google_maps_flutter] Custom marker size improvements (flutter/packages#4055)
2024-06-05 [email protected] [rfw] Material slider widget (flutter/packages#6610)
2024-06-04 [email protected] [ci] Manual roll Flutter to c246ecd (84 revisions) + fixes (flutter/packages#6863)
2024-06-04 [email protected] Correcting the typo of Flutter in projects (flutter/packages#6850)
2024-06-04 [email protected] [google_maps_flutter] Custom marker size improvements - platform impls (flutter/packages#6826)
2024-06-04 [email protected] Avoid cumbersome formatter workaround (flutter/packages#6573)
2024-06-04 [email protected] Clean Xcode project before analyzing and testing (flutter/packages#6842)
2024-06-03 [email protected] [pigeon] Kotlin/Java method overloading for the `setUp` method (flutter/packages#6843)
2024-06-03 [email protected] [url_launcher] Add support for setting show title on Chrome Custom Tabs (flutter/packages#6097)
2024-06-03 [email protected] Revert "Roll Flutter from c85fa6a to 7eebe29 (#6836)" (flutter/packages#6860)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https:/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
If a list shouldn't be formatted with one element on each line, a single EOL-comment inside is enough to disable the formatter. Much simpler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: flutter_markdown
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants