Skip to content

[tool] Add support for .java, .gradle, .sh, and .m files… #5567

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

Merged
merged 9 commits into from
Dec 13, 2023

Conversation

mike-v2
Copy link
Contributor

@mike-v2 mike-v2 commented Dec 4, 2023

… to update-excerpts tool

Need this tool to recognize .java, .gradle, and .sh files in order to complete flutter/flutter#102679. The README.md for the espresso package contains code from .java, .gradle, and .sh files.

Support for .m files was requested by @tarrinneal.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@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 Hixie or stuartmorgan on 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.

@mike-v2
Copy link
Contributor Author

mike-v2 commented Dec 4, 2023

The existing test file update_excerpts_command_test.dart only uses dart language in its tests. It seems like it would have to be completely reworked in order to allow testing other languages.

@stuartmorgan-g
Copy link
Contributor

The existing test file update_excerpts_command_test.dart only uses dart language in its tests. It seems like it would have to be completely reworked in order to allow testing other languages.

What do you mean by "totally reworked"? It looks like the existing test structure would just need one more parameter (for the file path to write source to) in its helper.

Update test helper function to accept fileName parameter so that tests may use arbitrary file types

Remove extra line in tool file that prevents language from being properly set in cc files
@mike-v2
Copy link
Contributor Author

mike-v2 commented Dec 5, 2023

Ah sorry, I should've figured that out. Thanks for pointing me in the right direction!

Group file type tests
});
}

// ignore: prefer_foreach
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two conflicting lint rules here: avoid_function_literals_in_foreach_calls and prefer_foreach. The latter aims to make the code more terse but the formatter uses the same number of lines with forEach as it does with for...in.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's not a conflict, the linter just gives a misleading suggestion for what you probably wrote as your other version. The version of this that's compliant with all of our lints is testCases.forEach(runTest);.

@tarrinneal tarrinneal requested review from stuartmorgan-g and tarrinneal and removed request for stuartmorgan-g December 6, 2023 09:18
@@ -142,10 +142,15 @@ class UpdateExcerptsCommand extends PackageLoopingCommand {
case '.kt':
language = 'kotlin';
break;
case '.cc':
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shoot, there was a problem with my test case for .cc files. My mistake.

@@ -33,12 +33,13 @@ void runAllTests(MockPlatform platform) {
));
});

Future<void> testInjection(String before, String source, String after,
Future<void> testInjection(
String before, String source, String after, String fileName,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a lot of positional arguments with the same type; ideally they should all be named, but lets at least name the new one.

@@ -33,12 +33,13 @@ void runAllTests(MockPlatform platform) {
));
});

Future<void> testInjection(String before, String source, String after,
Future<void> testInjection(
String before, String source, String after, String fileName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit throughout the PR: "filename" is generally a single word in programming, so the variable would just be filename.

});
}

// ignore: prefer_foreach
Copy link
Contributor

Choose a reason for hiding this comment

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

There's not a conflict, the linter just gives a misleading suggestion for what you probably wrote as your other version. The version of this that's compliant with all of our lints is testCases.forEach(runTest);.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

Do you think there's a good way to handle .h files for c++ and objc?

Comment on lines 146 to +151
case '.cpp':
language = 'c++';
break;
case '.m':
language = 'objectivec';
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

@stuartmorgan Seems like we don't have support for header files for either language. I'm not sure there's a simple solution though.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g Dec 13, 2023

Choose a reason for hiding this comment

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

Good point. That would need either more special casing here, or a more generalized solution (like a mapping from extensions to the set of allowed languages).

required String source,
required String after,
required String filename,
bool failOnChange = false}) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add a trailing comma false,})

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

Changed my mind, merging now

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 13, 2023
@auto-submit auto-submit bot merged commit ee593fd into flutter:main Dec 13, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 14, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Dec 14, 2023
flutter/packages@b5958e2...1151191

2023-12-14 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 2.22.8 to 3.22.11 (flutter/packages#5674)
2023-12-13 [email protected] [ci][web] Ignore always_specify_types for JSArray. (flutter/packages#5669)
2023-12-13 [email protected] [tool] Add support for `.java`, `.gradle`, `.sh`, and `.m` filesâ�¦ (flutter/packages#5567)
2023-12-13 [email protected] [google_sign_in] Update (web) example app. (flutter/packages#5634)
2023-12-13 [email protected] [path_provider] De-flake getExternalStorageDirectories test (flutter/packages#5628)
2023-12-13 [email protected] [google_sign_in_web] Stop relying on framework internals. (flutter/packages#5660)
2023-12-13 [email protected] [Android] Bump Gradle version to 7.6.3 (flutter/packages#5522)
2023-12-13 [email protected] [google_sign_in] Adopt code excerpts in README (flutter/packages#5521)
2023-12-13 [email protected] [css_colors] Adopt code excerpts in README (flutter/packages#5478)
2023-12-13 [email protected] [webview_flutter] Support for handling basic authentication requests (Android) (flutter/packages#5454)

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://github.com/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
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants