Skip to content

refactor generateString to emit simpler dart code - #49334

Merged
a14n merged 1 commit into
flutter:masterfrom
a14n:generateString-refactoring
Jan 31, 2020
Merged

a14n merged 1 commit into
flutter:masterfrom
a14n:generateString-refactoring

Conversation

@a14n

@a14n a14n commented Jan 23, 2020 •

Copy link
Copy Markdown
Contributor

Description

In #49159 we try to handle whitepaces in adjacent strings. Some of the lints were in generated files.
This PR changes how we output dart String in generated code to have more terse and idiomatic Strings.

Related Issues

None

Tests

I added several tests for generateString function.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@fluttergithubbot fluttergithubbot added a: internationalization Supporting other languages or locales. (aka i18n) p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages c: contributor-productivity Team-specific productivity, code health, technical debt. labels Jan 23, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The previous version didn't emit trailing commas.

@a14n
a14n force-pushed the generateString-refactoring branch from c932146 to 05c7ffe Compare January 23, 2020 07:53
@a14n
a14n requested a review from HansMuller January 23, 2020 20:29
@a14n
a14n force-pushed the generateString-refactoring branch 4 times, most recently from c198e2a to 40db9e5 Compare January 29, 2020 08:03
@a14n

a14n commented Jan 29, 2020

Copy link
Copy Markdown
Contributor Author

/cc @HansMuller

@HansMuller HansMuller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@a14n
a14n force-pushed the generateString-refactoring branch from 40db9e5 to 429d217 Compare January 30, 2020 07:13
@a14n
a14n force-pushed the generateString-refactoring branch from 429d217 to 5b851f8 Compare January 30, 2020 17:38
@Piinks

Piinks commented Jan 30, 2020

Copy link
Copy Markdown
Contributor

@kjlubick this PR has been experiencing some gold failures that look a bit odd. Waiting to see if it happens again. Here is one of the runs that had issues: https://cirrus-ci.com/task/5200111831613440
I don't think this has happened on other PRs though.

@kjlubick

Copy link
Copy Markdown
Contributor

That does look strange - the service account that goldctl was authed with ([email protected]) does not look familiar to me.

@Piinks

Piinks commented Jan 30, 2020

Copy link
Copy Markdown
Contributor

It looks like it is not recurring with this latest commit. I don't know where that service account would have come from. 🤔

@a14n

a14n commented Jan 30, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for your help. The job that failed happened before I rebase this PR (previously the PR was based on 92f7e16)

The rebase seems to have fixed the issue.

@a14n
a14n merged commit 5a8de59 into flutter:master Jan 31, 2020
@a14n
a14n deleted the generateString-refactoring branch January 31, 2020 10:58
///
/// Strings with newlines are not supported.
String generateString(String value) {
assert(!value.contains('\n'));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @a14n, could you explain why this newline check was added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I added this assert because the old method didn't work for s with a \n inside.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new method appears to handle any backslash character by generating a raw string. Maybe this assert isn't really needed.

@a14n a14n Mar 10, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The assert is currently needed because the method does not handle \n. We could change it to use triple quote if s contains \n but it's a different handling than \\

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're right; it's newline characters that are disallowed, not a backslash followed by an 'n'.

Values in JSON files - and ARB files are JSON files - cannot contain newline characters, so it makes sense that this method doesn't allow values to contain newline characters.

return "r'''$json'''";
}
if (json is String)
return generateEncodedString(currentLocale, json);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@a14n A separate question, but this function was originally created for use to handle the Kannada locale. What's the rationale for changing its purpose here? It also seems like the documentation for the function have not been appropriately updated so I'm not quite sure what the intent is

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

generateEncodedString now manages both Kannada and not-Kannada. The test on locale is done at a single place.

It also seems like the documentation for the function have not been appropriately updated

Indeed it should now mention that the method handles both Kannada and not-Kannada. Perhaps a better function name could be found.

@lock

lock Bot commented Apr 2, 2020

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock Bot locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: internationalization Supporting other languages or locales. (aka i18n) c: contributor-productivity Team-specific productivity, code health, technical debt. p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants