-
-
Notifications
You must be signed in to change notification settings - Fork 167
More robustly pick valid unique names for each asset. #433
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
Conversation
@bramp Hi, could you rebase so we can review this? |
Trying to rebase, but it seems a bunch of changes, such as #471 are causing me merge conflicts, and I may need to refactor a bunch :( |
…e of the asset. Instead of having this code scattered in a few places.
… unique names for each asset. The strategy is as follows: 1) Convert the asset file name, to a valid dart identifier, that is - Replace non ASCII chars with ASCII. - Ensure the name starts with a letter (not number or _). - Style the name per the camelCase or snakeCase rules. 2) Use the asset name without extension. If unique and not a dart reserved word use that. 3) Use the asset name with extension. If unique and not a dart reserved word use that. 4) If there are any collisions, append a underscore suffix to each item until they are unique. This fixes FlutterGen#420 and FlutterGen#250. It also conflicts with PR FlutterGen#346, but this does everything that does plus more.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #433 +/- ##
==========================================
- Coverage 98.35% 97.22% -1.14%
==========================================
Files 21 22 +1
Lines 730 756 +26
==========================================
+ Hits 718 735 +17
- Misses 12 21 +9 ☔ View full report in Codecov by Sentry. |
Ok, rebased, and all tests now pass. Please take a look. I'm a little unsure if this will now resolve conflicts with "root assets" with conflicting names. But I think to resolve that a larger refactor is needed (such as getting the list of all root assets, and then deconflicting the names). I also noticed that code coverage dropped, it seems because I added a toString for debugging, and that's not convered by a test. I can add that, but it was purely for debugging, not part of the output of the problem. |
@@ -14,6 +14,9 @@ extension StringExt on String { | |||
} | |||
} | |||
|
|||
String camelCase(String s) => s.camelCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem to be an improvement compare to the original usages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because now you can pass camelCase as a function, eg.
UniqueAssetType(assetType: assetType, style: camelCase)
…riable = ''` to `String variable = ''`.
Ok, made the required changes. Please take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
What does this change?
Changed
AssetTypeIsUniqueWithoutExtension
to more robustly pick valid unique names for each asset.The strategy is as follows:
This will now handle a wide-range of names that weren't previously supported. Dart identifiers, assets starting with numbers, asserts with non-ascii characters, assets with conflicting names (e.g 'a.png' and 'A.png'). See the tests in
packages/core/test/assets_gen_test.dart
.Fixes #250, #346, and #420 🎯. Happy to discuss on #420.
Type of change
Please delete options that are not relevant.
Checklist:
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
melos run test
)melos run format
to automatically apply formatting)